这是我的代码:
<?php
require dirname(__DIR__).'/config/Redirect.php';
class Parsing {
private $controller = null;
private $model = null;
private $parameters = array();
private $redirect;
public function __construct() {
$this->redirect = new Redirect($controller, $model, $parameters); //error is on this line
}
}
?>
我得到的错误是这个(我删除了行号,但我评论了错误在上面代码中的位置):
Notice: Undefined variable: controller in /var/www/html/application/config/Parsing.php on line #
Notice: Undefined variable: model in /var/www/html/application/config/Parsing.php on line #
Notice: Undefined variable: params in /var/www/html/application/config/Parsing.php on line #
似乎控制器已经定义在它之上,例如private $controller = null;
和所有其他控制器。可能是什么问题?
答案 0 :(得分:1)
将行更改为:
$this->redirect = new Redirect($this->controller, $this->model, $this->parameters);
答案 1 :(得分:1)
使用$this
关键字调用类级别变量
public function __construct() {
$this->redirect = new Redirect($this->controller, $this->model, $this->parameters);
}
答案 2 :(得分:0)
您需要$this
关键字,例如$this->controller
,$this->model
,$this->parameters
public function __construct() {
$this->redirect = new Redirect($this->controller, $this->model, $this->parameter); //error is on this line
}