Fraser
Fraser

Reputation: 14246

Laravel 3: View doesn't exist

I've just inherited a Laravel 3 site which works on a custom CMS. The CMS output is rendered through a theme folder at the / level so my folder structure looks like:

-application
-bundles
-laravel
-public
-storage
-theme
  -errors
  -layouts
    -partials

I've made a search controller within '/application/controllers' and I want to create my view for the output in the '/theme/layouts' folder with the other template files. When I've worked with Laravel before, my views are all within '/application/views' and I can specify my view with:

public $layout = 'layouts.default';

..which would use '/application/views/layouts/default.blade.php'

How can I get my controller to render the view using my '/theme/layouts/searchTemplate.php' file and pass in the search data from the controller?

Upvotes: 0

Views: 401

Answers (2)

Matteus Hemström
Matteus Hemström

Reputation: 3845

If you really need to put these files in a separate folder you should probably use bundles (see docs).

However, a quick and dirty solution is to add a hook in the view loader event (application/start.php):

Event::listen(View::loader, function($bundle, $view)
{
    if($bundle == 'theme') {
        return View::file('application', $view, Bundle::path('application').'theme');
    }

    return View::file($bundle, $view, Bundle::path($bundle).'views');
});

You can then make views like:

View::make('theme::layouts.default');

which will load the file "application/theme/layouts/default.blade.php".

Upvotes: 1

Polichism
Polichism

Reputation: 224

In your application folder, there is a folder called 'views' You have to create the default.php in applications/views/layouts/

With 'layouts.defaults' it search in the views folder to a folder that will be called layouts.

So the complete folder for 'layouts.default' would be: ./application/views/layouts/default.php

Edit: answer is not relative anymore

Upvotes: 0

Related Questions