我在代码点火器中有这个控制器,它以
class MyController extends CI_Controller {
private $data = array(
'importantValueToPassToViews' => $this->Animal->getPrey(),
);
...
我在以 'importantValueToPassToViews'
(第三行)开头的行上收到错误。
Parse error: syntax error, unexpected T_VARIABLE
为什么?
因为不能在类属性定义中调用函数。 您可以将其设置为常量或常量数组。
您需要在构造函数中执行此操作:
<?php
class MyController extends CI_Controller {
private $data = array();
public function __construct()
{
parent::__construct();
$this->data['importantValueToPassToViews'] = $this->Animal->getPrey();
}
// ...
}