管理 Controller
<?php
class Admin_controller extends CI_Controller{
function __construct()
{
parent::__construct();
$this->load->model("Adminmodel","",true);
protected $headerview = 'headerview';
protected function render($content) {
//$view_data = array( 'content' => $content);
$this->load->view($this->headerview);
}
}
}
?>
我想在应用程序的所有页面中访问我的 headerview.php ,以便我像上面一样创建,但它显示类似 Parse error: syntax error, unexpected 'protected' (T_PROTECTED) in C:\xampp\htdocs\ci3\application\controllers\admin\Admin_controller.php
的错误。
怎么解决这个问题?
最佳答案
您不希望使用访问修饰符在构造函数内创建/声明函数,否则它会像您一样抛出错误。您可以创建匿名函数或普通函数声明,请考虑这一点:
class Student {
public function __construct() {
// below code will run successfull
function doingTask () {
echo "hey";
}
doingTask();
// but this will throw an error because of declaring using access modifier
public function doingTask () {
echo "hey";
}
}
}
$std = new Student;
关于php - 语法错误,codeigniter 中出现意外的 'protected' (T_PROTECTED),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42360133/