[英]Check if a file exists in Yii
I am creating a bunch of modules that all extend a base module. 我正在创建一堆扩展基本模块的模块。 However, some actions need to override the base view.
但是,某些操作需要覆盖基本视图。 In that case, I'd like to check if the new module has a view in its structure.
在这种情况下,我想检查新模块的结构是否有视图。 If it does, use that view, and otherwise use the base one.
如果是,请使用该视图,否则使用基本视图。 Now, my question:
现在,我的问题:
Is there a way to check if a file exists in Yii, using the typical alias structure application.views.user.basic_view
without using or importing it? 有没有办法检查Yii中是否存在文件,使用典型的别名结构
application.views.user.basic_view
而不使用或导入它?
Try use Controller or CWidget method getViewFile
尝试使用Controller或CWidget方法
getViewFile
http://www.yiiframework.com/doc/api/1.1/CController#getViewFile-detail http://www.yiiframework.com/doc/api/1.1/CController#getViewFile-detail
http://www.yiiframework.com/doc/api/1.1/CWidget#getViewFile-detail http://www.yiiframework.com/doc/api/1.1/CWidget#getViewFile-detail
未经测试,但是解决路径的别名是什么,然后检查这个......
echo is_file(Yii::getPathOfAlias('application.views.user.basic_view'))?'yes':'no';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.