我有以下问题。在我的一门课程中,我在结构中使用 $this->view->title = $titlearray; 这适用于 add.php
现在我想用另一种方法在同一个类中做同样的事情
public function addAction() {
$this->view->errors = $errorarray;
}
在 add.php 我想显示数组
$errors = $this->errors;
foreach ($errors as $value) {echo $value;}
但这不起作用。有人出主意吗?
class Controller_PagesController {
private $view;
public function __construct( ){
$this->view = new View();
$this->view->title = 'title example';
}
public function addAction(){
$this->view->errors = array(1=>'required',2=>'minlenght');
}
^^^^^^^Construct 作品和 addAction 不在 add.php
add.php 示例
$title = $this->title; //string
$errors = $this->erors; //array
echo $title; //works
foreach ($errors as $value) {print_r($value);} //doesnt work