Php 要查看的类数组
我有以下问题。 在我的一个类中,我在construct$this->view->title=$titlearray; 这在add.php中起作用 现在我想用另一种方法在同一个类中做同样的事情Php 要查看的类数组,php,arrays,class,Php,Arrays,Class,我有以下问题。 在我的一个类中,我在construct$this->view->title=$titlearray; 这在add.php中起作用 现在我想用另一种方法在同一个类中做同样的事情 public function addAction() { $this->view->errors = $errorarray; } 在add.php中,我想显示数组 $errors = $this->errors; foreach ($errors as $value) {echo $
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');
}
^^^^^^^不在add.php中的Construct works和addAction
add.php示例
$title = $this->title; //string
$errors = $this->erors; //array
echo $title; //works
foreach ($errors as $value) {print_r($value);} //doesnt work
试着
public function addAction() {
$this->view->errors = $errorarray;
}
在add.php中直接使用
foreach ($errors as $value) {print_r($value);}
如果要检查,请打印数据$errors
你试过用它吗
public function addAction(){
$this->view->errors['errors'] = array(1=>'required',2=>'minlenght');
}
在视图中,print$errors$这仅在您处于类上下文中时才有意义。。。您是否试图在类之外使用$this?从何处获取$errorArray变量。。。它似乎不在addAction方法的范围内,请参见上面的示例类,谢谢
$this->erors
@CORRUPT changed,它不起作用,只有u构造提供了它们,而不是addAction中的变量。