0
votes

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.

1
Erreur HTTP 500 (Internal Server Error)Flash-Square
Thanks. Is there a stack trace or related message you can print out here as well?fideloper
Don't get any error neither any log error.Flash-Square
I'm not sure what OS you're on, but my next strategy at getting a meaningful error message would be to check the web-server error logsfideloper
good Idea for the logs @fideloper. It's working now. ( i'll post the result ) Thank youFlash-Square

1 Answers

1
votes

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