-1

Let's say in my app_controller.php I include a helper like this:

var $helpers = array('MyHelper' => array('value' => 'This is a value'));    

As you can see above, I'm also setting an array to my Helper. How do I access this array in my view files? Anybody knows how I can do this?

4

3 回答 3

1

在您看来:如果您像访问函数一样尝试访问 options 成员变量会发生什么?

<?php
    ...
    ...
    debug( $this->MyHelper->options['value'] );
    // or
    debug( $this->MyHelper->options );
    // to view the whole array - access them by key like above
    ...
?>

您应该阅读@thecodeparadox 在明确解决您的问题时给您的答案,而不是投反对票。

于 2012-05-04T05:01:36.873 回答
0
class MyHelper extends AppHelper {
    public $options = array();
    public function __construct(View $view, $option = array()) {
        parent::__construct($view, $option);
        $this->options = $option;
        debug($option); // with in $option you will get your array
    }
}

class AppController extends Controller {
    public $helpers = array('MyHelper' => array('option1' => 'value1'));
}

然后在您的视图文件中尝试

$this->MyHelper->options;
于 2012-05-04T03:42:36.223 回答
0

它可以通过以下方式访问:

$helpers["Myhelper"]["value"];
于 2012-05-03T23:19:22.347 回答