0

I have two classes. UserModel and UserController.

file: localhost/controllers/user.controller.php

<?php class UserController { public function GetArray() { $query = 'SELECT id, username, email, password FROM Users'; $result = mysql_query($query); $model = new UserModel(); while ($row = mysql_fetch_array($result)) { $model->id = $row['id']; $model->username = $row['username']; $model->email = $row['email']; $model->password = $row['password']; $array[] = $model; } return $array; } } ?> 

The UserModel class is in another file: localhost/models/user.model.php. The 6th row is causing the error, because there's no references to the other file. How can I do that?

Sorry for my bad english, and thanks to you all.

2 Answers 2

2

Use require or require_once to include the other file.

Sign up to request clarification or add additional context in comments.

4 Comments

In most cases you should use require_once.
When I add "require_once '../models/user.model.php'" at the top of the file Chrome gives me a error message and don't show the page. 'Error HTTP {500 (Internal Server Error):'
leo, not if you are using __autoload() ;-)
@user1217482: for 500 errors, look at the server's error log. It'll have details as to what caused it.
0

See the following link. Use any of th method to call a class inside another class. Thanks

Calling a class inside another one in PHP

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.