Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Check existence views file

I want to check views/layouts file. For ex:

MainView check: hasMainView

if($this->view->hasMainView('main'))
{
    $this->view->setMainView('main');
}

Layout check: hasLayout

if($this->view->hasLayout('private'))
{
    $this->view->setLayout('private');
}

I dont want to use manual way with file_exist() function.

Is there any helper function like hasMainView() or hasLayout()?

Thanks



62.7k
Accepted
answer
edited Apr '16

Hmmm found a function that may help you:

var_dump($this->view->exists('homepage/index')); // true

var_dump($this->view->exists('homepage/index2')); // false

// More info here: https://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_View.html

Update: sorry for the link in code block, but comment editor fuks up urls containing underscores..

Great! I checked the documentation but i missed it. Thanks

Hmmm found a function that may help you:

```php var_dump($this->view->exists('homepage/index')); // true

var_dump($this->view->exists('homepage/index2')); // false

// More info here: https://docs.phalconphp.com/en/latest/api/Phalcon%5Mvc%5View.html ```

Update: sorry for the link in code block, but comment editor fuks up urls containing underscores..