Im тестирование это вещь, где я пытаюсь загрузить класс и использовать его как это:почему класс PHP не загружается
$this->model->model_name->model_method();
Это то, что я получил:
<?php
error_reporting(E_ALL);
class Loader {
public function model($model)
{
require_once("models/" . $model . ".php");
return $this->model->$model = new $model;
}
}
class A {
public $load;
public $model;
public $text;
public function __construct()
{
$this->load = new Loader();
$this->load->model('Test');
$this->text = $this->model->Test->test_model();
}
public function get_text()
{
return $this->text;
}
}
$text = new A();
echo $text->get_text();
?>
Im получаю кучу ошибок здесь:
Warning: Creating default object from empty value in C:\xampp\htdocs\fw\A.class.php on line 9
Notice: Trying to get property of non-object in C:\xampp\htdocs\fw\A.class.php on line 24
Fatal error: Call to a member function test_model() on a non-object in C:\xampp\htdocs\fw\A.class.php on line 24
Что я делаю неправильно? Спасибо за любой отзыв!
P.S. не так много в загруженном файле:
<?php
class Test {
public function test_model()
{
return 'testmodel';
}
}
?>
Может вставить класс –
теста, что происходит, если вы делаете var_dump ($ this-> load-> модель ('Test'));Выход; –
объект (тест) # 5 (0) {} – gimcc