I think view composers are what you're looking for: http://laravel.com/docs/responses#view-composers
Thanks for the reply guys, I tried using view composers and I got a blank page. What could I be doing wrong?
here's the code on paste bin, because I wasn't sure if I could post it here.
You don't define view composers in the controller.
Put them into routes.php
or filters.php
or even better in composers.php
There's a good video tutorial on view composers from the great Jeffrey Way :-D http://www.youtube.com/watch?v=X8yqmZtKOoY
Ok I followed the tutorial as best I could all the way to the point where he checks his work and it works, but mine don't and this is the error I'm getting:
Class Acme\Repositories\FlatTagRepository does not exist
I have checked all my spelling, even made sure the folder and file were an exact match and I cannot figure out why It's not finding the class. I suspect a typo, but I've checked and rechecked and I can't find any typos.
I pasted the code here:
Your code is fine.
Maybe you forgot to do a composer dump-autoload
after your edits to composer.json
?
If you're on Windows maybe it's a problem you refer to the application folder app
as App
in your psr-0 autload
"psr-0": {
"Acme": "App/"
}
I'm running LAMP I am starting to wonder if it's because I'm running Laravel version 4.1. Maybe I should roll back to 4.0 what do you think?
Also, something could be botched in my setup, but everything is stock except for changing the name of the folder and adding views->layouts, so it's hard to believe that would be the case.
david@lappy:~/www/test_laravel$ composer dump-autoload No command 'composer' found, did you mean: Command 'compose' from package 'mime-support' (main) composer: command not found
But.....
david@lappy:~/www/test_laravel$ php artisan dump-autoload Generating optimized class loader
It seems artisan might be what you was referring to?
Your code is running fine on Laravel 4.1 so this is not the cause.
I've installed composer globally that why I can call
composer dump-autoload
I think in your case you have to run in the root of your application (where composer.json lies):
php composer.phar dump-autoload
Artisan dump-autload
runs composer
and does some additional stuff so you should also be fine with this.
So after running php artisan dump-autoload
it's still not working ?
Ah Ha! That worked. I didn't realize you were referring to that file. I have my composer.phar file in the www directory. Something I should have known, since I had to call composer a few times last week when I first started. I think I should switch over to loading it globally like you do. I also went ahead and removed the ugly psr-0 line and added the path to the classmap. I hope there aren't any drawbacks to this.
"classmap": [ "app/commands", "app/controllers", "app/models", "app/database/migrations", "app/database/seeds", "app/tests/TestCase.php", "app/Acme"
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community