Views and multiple paths and display only one of them

I have a code like that:

$view = new Mvc\View();

$view->setViewsDir([$path1, $path2, $path3]);

$view->partial('test/template');

In that case if template 'test/template' exists in all folders, than all of them will be shown. How to limit it and display only 1st ?

I'm using small "workaround":

$view = new Mvc\View();

foreach([$path1, $path2, $path3] as $viewPath){

$view->setViewsDir($viewPath);

if($view->exists('test/template')){ break; }

}

$view->partial('test/template');

However, maybe exists any better (native) way?

Thank you.



3.1k

Try with this:

https://docs.phalconphp.com/en/latest/reference/views.html#control-rendering-levels

Sorry, but as i understand it'll stop rendering ALL views.

i am not sure if it will work for you

https://docs.phalconphp.com/en/latest/reference/views.html#picking-views

Seems, it doesn't work if view class is used without controllers and other stuff. I found event view:beforeRenderView maybe it can help, maybe not.

Anyway thank you.

edited Aug '16

It won't stop rendering all views?! Read the docs, you'll see available class constants.

 // Shows only the view related to the action
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);

Also, take a look at: https://docs.phalconphp.com/en/latest/reference/views.html#disabling-render-levels



67.7k
edited Aug '16

btw i use my fork of phalcon because a commit is screing my things. Here is the fix: https://github.com/Izopi4a/cphalcon/commit/dabc7c239502b469d303dd83d0c0a14700869732

there is a slight sintax error in it but never the less you get the idea. If you are compileing phalcon yourself you can give my fork a try just to check if it fixes your problem.



3.1k
edited Sep '16

btw i use my fork of phalcon because a commit is screing my things. Here is the fix: https://github.com/Izopi4a/cphalcon/commit/dabc7c239502b469d303dd83d0c0a14700869732

there is a slight sintax error in it but never the less you get the idea. If you are compileing phalcon yourself you can give my fork a try just to check if it fixes your problem.

It'll work. Though i'll prefer to use original Phalcon. Thank you for your variant.

PS.I'll keep my "workaround"