Admin_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一样的错误。如何解决这个问题?
发布于 2017-02-21 14:33:05
没有方法可以在中创建函数
class Admin_controller extends CI_Controller{
function __construct()
{
parent::__construct();
$this->load->model("Adminmodel","",true);
$headerview = 'headerview';
$this->render($headerview); # calling render() function in same class
}
function render($content)
{
//$view_data = array( 'content' => $content);
$this->load->view($this->headerview);
}
}发布于 2017-02-21 14:31:55
你不应该假设在带有访问修饰符的构造器中创建/声明一个函数,否则它会像你一样抛出一个错误。您可以创建匿名函数或普通函数声明,请考虑以下内容:
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;https://stackoverflow.com/questions/42360133
复制相似问题