7

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?

2 Answers 2

7

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

Sign up to request clarification or add additional context in comments.

Comments

7

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'; 

1 Comment

Thanks for your answer. Though it might work, I already tested @Sergey's answer and it worked. However, +1 for noticing the getPathOfAlias false return in case the file doesn't exist.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.