0

I try to get the nested controller in Laravel 4 based on the following structure:

  • app
    • controllers
      • base
        • BaseController.php
      • website
        • WebsiteController.php

I want to get the website route to be associated with WebsiteController that extend BaseController.

I've try the following thing

for route.php (app/route.php)

Route::resource('website', 'Controllers\Website\WebsiteController');

for BaseController.php (app/controllers/base/BaseController.php)

use Illuminate\Routing\Controllers\Controller;
class BaseController extends Controller {

    protected function setupLayout(){
        if ( ! is_null($this->layout)){
            $this->layout = View::make($this->layout);
        }
    }
}

for WebsiteController.php (app/controllers/website/WebsiteController.php)

use Controllers\Base\BaseController;
class WebsiteController extends BaseController {
    public function index(){
        return 'index';
    }
}

Unfortunately when i go to http://mywebsite.com/website it's not working at all.

Thank you.

BenjaminRH
  • 11,974
  • 7
  • 49
  • 76
Flash-Square
  • 391
  • 1
  • 4
  • 10

1 Answers1

1

Without a error dump, we can't know for sure, but you can try these:

1) Run composer's dump-autoload, so the auto-loader knows of the new classes:

$ php composer.phar dump-autoload

2) I don't believe you need to use the use Controllers\Base\BaseController directives as the models directory is auto-loaded by default. Since you're not name-spacing your controllers differently, the use directive shouldn't be needed. The above 'dump-autoload' should do the trick

3) After the dump-autoload, change

Route::resource('website', 'Controllers\Website\WebsiteController');

to this:

Route::resource('website', 'WebsiteController');

You use of specific classes (for instance 'Controllers\Website\WebsiteController') won't be necessary unless you define a different namespace for your new controllers

fideloper
  • 12,213
  • 1
  • 41
  • 38
  • event with a dump-autoload and changing the route it still don't work. I've simplify the code by extending websitecontroller with Controller ( removing the baseController step ) But event like that it's still show error 500 – Flash-Square Feb 03 '13 at 17:56