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

Picking view from controller ALWAYS renders index/index

I have an typical MVC app.

I have an IndexController. I use $this->view->pick('index/index') to render my index.volt -> /view-dir/index/index.vol

I also have a LoginController. I again use $this->view->pick('login/index') to render my index.vot from /view-dir/login/index.volt.

Problem is every time i visit /login, Phalcon renders /login/index but also calls index/index behind the scenes. I see errors complaining that all the {{ }} tags inside index/index are not set.

Why is this happening??? index/index is not part of the view hierarchy on the views doc page.

Also, I have another part of the app where this is working properly.

Please help!



43.9k

Hi,

you do not need to pick view if your app is organized as views/mycontroller/action.volt and you've got an MycontrollerController.php with public actionAction() in it. This is phalcon's default MVC behaviour.

With your problem: "every time i visit /login, Phalcon renders /login/index but also calls index/index", does it also render index/index.volt html ?



8.7k

I tried with the default MVC controller/view routing (not using pick). Same result.

Yes, when I access /login, it renders /views/login/index.volt and (always) hits /views/index/index.volt too.

Can't figure out why

Hi,

you do not need to pick view if your app is organized as views/mycontroller/action.volt and you've got an MycontrollerController.php with public actionAction() in it. This is phalcon's default MVC behaviour.

With your problem: "every time i visit /login, Phalcon renders /login/index but also calls index/index", does it also render index/index.volt html ?



43.9k

show us LoginController and login/index.volt



8.7k

I've stripped everything out of them and it still hits index/index.volt everytime.

Is there a way to trace what the router is doing?



8.7k
Accepted
answer
edited Nov '15

I figured this out. NOT a Phalcon problem.

My html had a reference to an image that did no exist. I also had my EventsManager listening for dispatch:beforeException. When I accessed /login, the page routed properly and rendered /view/login/index.volt.

Phalcon then tried to load the missing image, triggered an exception, which was faithfully caught. Unfornately, I didn't yet setup up my ErrorController! Phalcon couldn't find the controller it needed and fell back to my IndexController controller, displaying the messages I saw.

LoginController was not rendering two views: LoginController was rendering correctly and the missing image was triggering IndexController.

Thanks to XDebug. Everyone should really install it.