We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

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.

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.8k

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.6k

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.8k

show us LoginController and login/index.volt



8.6k

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.6k
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.