2013-04-15 20:33
浏览 42

codeigniter - 在视图中检索控制器变量(使用$ this)

in my controller i have an public variable i want to use in my view.

public $header = array("show_menu"=>true);

Traditional i would pass variables as an array to the load->view("incl_header",$header) function, however i have noticed that in my view i can retrieve variables of my controller like so:

echo  $this->header['show_menu'];

Are there any problems retrieving variables like this in my view file?

I am using codeigniter 2.1.3

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongshang1934 2013-04-16 12:31

    It's possible to do it like that.

    If you use var_dump($this) you can see all the variables that are availible in your view.

    It's not the normal codeigniter way of retrieving variables in your view.

    How ever this might change in futeure releases of codeigniter so you must keep that in mind when using this method.

    解决 无用
    打赏 举报

相关推荐 更多相似问题