YII框架这段代码是啥意思?是moudles里面view中default中的index.SegmentFault

php中文网
发布: 2016-06-06 20:45:48
原创
1225人浏览过

<?php
/* @var $this DefaultController 
 
  $this是从哪来的?
 
 
 
 */

$this->breadcrumbs=array(
    $this->module->id,
);
?>


<h1><?php echo $this->uniqueId . '/' . $this->action->id; ?></h1>





<p>
This is the view content for action "<?php echo $this->action->id; ?>".
The action belongs to the controller "<?php echo get_class($this); ?>"
in the "<?php echo $this->module->id; ?>" module.
</p>




<p>
You may customize this page by editing <tt><?php echo __FILE__; ?></tt>
</p>


登录后复制

我想知道这个$this是哪来的?这也没有类啊!

回复内容:

<?php
/* @var $this DefaultController 
 
  $this是从哪来的?
 
 
 
 */

$this->breadcrumbs=array(
    $this->module->id,
);
?>


<h1><?php echo $this->uniqueId . '/' . $this->action->id; ?></h1>





<p>
This is the view content for action "<?php echo $this->action->id; ?>".
The action belongs to the controller "<?php echo get_class($this); ?>"
in the "<?php echo $this->module->id; ?>" module.
</p>




<p>
You may customize this page by editing <tt><?php echo __FILE__; ?></tt>
</p>


登录后复制

我想知道这个$this是哪来的?这也没有类啊!

注释里面不是写了吗?

$this DefaultController 
登录后复制

Yii view 里面的$this 是指当前controller,具体过程去看conroller的render方法.
因为是用Yii自身的renderer,所以调用的是ViewRenderer类的renderFile方法,
这方法接收一个$context参数,其实传的就是当前controller的实例对象,
然后再调这个controller的renderInternal方法,这个方法把view文件require进来了,
所以在view的$this其实是把当前controller传进来,然后调用传进来的controller的自身方法,把view文件require进来.

debug_print_backtrace 一看就知道

Phidata
Phidata

Phidata是一个开源框架,可以快速构建和部署AI智能体应用

Phidata 173
查看详情 Phidata

我心里有答案,但没实际用过YII,所以就只说方法了

相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号