开发者

symfony - Call an action from view?

开发者 https://www.devze.com 2023-02-19 18:27 出处:网络
I know it\'s not good to try to do this, but i would like to call an ac开发者_如何学Gotion in my view/template on symfony framework.

I know it's not good to try to do this, but i would like to call an ac开发者_如何学Gotion in my view/template on symfony framework. Is it possible ? I don't find anything about this on the web.

Thanks you, and sorry for my bad english!!


As you know you should not call an action from the view layer. Actions are used to process form data and fetch page data, there should only be one action process per page imho. Perhaps a helper function or using a partial or component would be better for your needs.

Helper functions may be called at anytime and can most likely do what your second action needs to do. Short of forwarding or page routing, I believe a helper function can do anything an action function can. You need to use the Symfony getContext singleton for access to variables that are standardly loaded in an action.

Partials and components let you break up the view layer into separate chunks. Components actually get their own action code, but I wouldn't go crazy hitting the database or anything in a component, keep it simple. Partials pretty much let you call another template file from within a template.

Read more at http://www.symfony-project.org/gentle-introduction/1_4/en/07-Inside-the-View-Layer

0

精彩评论

暂无评论...
验证码 换一张
取 消