Acces to controller throught layout


I would like to know if is possible get a controller method in a layout. Example:


public function welcome(){

return "Hello";



echo $this->welcome();

I need to show in the layout the value of the welcome method in controller. How can I do this? This welcome method has to be common to all views also

Thank you!

ralphwigum you’re asking the wrong question, the most import is not if you can or can not do something with a certain kind of technologie, any kind of technologie, be a language, a Framework, a DBMS, or any other…

In the proccess of development a soft solution the coding action is just a component of a system. You have to know and to keep some patterns, procedures and styles that define how good or bad your product is going to be. Do not rush the proccess, study first and you will answer your question by your self very fast. Don’t take this in a wrong way, this is the authentic help I can provide you now. I wish you luck, keep you in touch…

Ok thank you. I know the purpose of layout page, Using a controller in any layout is not a MVC pattern.

Use a renderPartial that apply the SiteController to use the common Controller. Thats righ isn`t it?

Hi ralphwigum, the use of renderPartial has no relation with the original problem. Remember always the KISS idea “Keep It So Simple”. Don’t complicate yourself. Your original question is simple, is just to reference a function that returns a single string. The use of the controllers has to do with the concept of “actions”, a functions invokes to render a view usually after getting data from an associated model. This is a general and quick view of their function. Just to understand the basic concept. If you are interested, I can recommend you some materials for a deeper study. However, everything step by step. Don’t give up writing. Good luck bro…