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.

5
  • Erreur HTTP 500 (Internal Server Error) Commented Feb 3, 2013 at 17:36
  • Thanks. Is there a stack trace or related message you can print out here as well? Commented Feb 3, 2013 at 17:40
  • Don't get any error neither any log error. Commented Feb 3, 2013 at 17:52
  • 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 logs Commented Feb 3, 2013 at 18:21
  • good Idea for the logs @fideloper. It's working now. ( i'll post the result ) Thank you Commented Feb 3, 2013 at 21:26

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.