-3
class Index extends Controller{ 

    public function first_index(){
        parent::__construct();
        public $name = 'tiko';
        $this -> view -> render('index/template','index/index');
    }
}

错误:

Parse error: syntax error, unexpected T_PUBLIC in
Z:\home\localhost\www\3ddproc.ru\controllers\index.php on line 6

Line 6 - public $name = 'tiko';
4

2 回答 2

2

你应该在类中设置 $name,而不是函数。

在函数中,您可以将其设置为您想要的任何值,但声明必须在类根范围内

class Index extends Controller{ 
    public $name;

    public function first_index() {
        parent::__construct();
        $this->name = 'tiko';
        $this -> view -> render('index/template','index/index');
    }
}
于 2013-08-10T21:25:16.670 回答
0

公共、受保护和私有为类函数(方法)和成员变量提供范围解析,public $name = 'tiko';从函数内部删除,而不是放在函数外部或之前

class Index extends Controller{ 
 public $name = 'tiko';
    public function first_index(){
        parent::__construct();

        $this -> view -> render('index/template','index/index');
    }
}
于 2013-08-10T21:28:42.703 回答