We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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



93.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.phalcon.io/en/latest/api/Phalcon_Mvc_View.html

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



58.1k

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

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.phalcon.io/en/latest/api/Phalcon_Mvc_View.html

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