简体   繁体   中英

Laravel - Converting application to bundle - How to load a view

I'm playing around with Laravel and am struggling to convert an application (simple blog) I made within the standard application layout into a bundle.

Having spent the last half hour reading up on namespacing and working through related error messages, I've got my model loaded and I've got it talking to my separate authorisation bundle. So the next problem is views.

Latest error message is:

View [home] doesn't exist.
Location:
/var/www/lara.dev/laravel/view.php on line 170

I have basically recreated the application structure in my bundle, with a views directory containing the view I am trying to load (bundles/blog/views/home.blade.php) from my bundles controller (bundles/blog/controllers/home.php)

I previously used the following line to load the view :

return View::make('home')->with('posts', $posts);

What do I have to do to make my views load as normal from within the bundles? Also, if it's obvious from my question that I'm missing something here then please enlighten me. I'm pretty new to OO in PHP

You simply namespace the view with your bundle name.

return View::make('bundlename::home')->with('posts', $posts);

This same approach works for almost anything. You should give the Bundle Docs a full read, specially the Using Bundles section. Bundles & Class Autoloading may also be of your interest.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM