Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 981
Sergi Juanola Avatar asked Feb 04 '13 11:02

Sergi Juanola


2 Answers

Try use Controller or CWidget method getViewFile

http://www.yiiframework.com/doc/api/1.1/CController#getViewFile-detail

http://www.yiiframework.com/doc/api/1.1/CWidget#getViewFile-detail

like image 182
Sergey Avatar answered Oct 13 '22 00:10

Sergey


Untested, but what's about resolving the alias to a path and then check this...

 echo is_file(Yii::getPathOfAlias('application.views.user.basic_view'))?'yes':'no';
like image 28
schmunk Avatar answered Oct 13 '22 00:10

schmunk