0
votes

I'm using Laravel web framework for a PHP project. I have a question about this framework, the documentation (which is poor), and the community from IRC doesn't helped me.

I want to create a controller which will be executed before any other controller. I want in this controller to pass some variables to view. How is this possible?

Thank you.

1
Usually only one controller is executed per request. It sounds like you could make use of view composers or using View::share in conjunction with route filters. And there was no need to start your question off with those remarks. Be grateful for help, it's not always a given. I'm on IRC now and there are plenty of others around too. Jump back on.Jason Lewis

1 Answers

2
votes

You can do such thing in the before filter, in routes.php (, for Laravel 4 its filters.php).

Or if you need to do it in controller then create a BaseController which should extend Controller, in Laravel 3 you should have this already, base.php. And all your controllers should extend this BaseController, in its __construct or in before filter do this for ease:

View::share('key', 'value');

And use it as $key in your views.

Note, View::share can be problematic sometimes.