dtj4307 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?