I try to get the nested controller in Laravel 4 based on the following structure:
- app
- controllers
- base
- BaseController.php
- website
- WebsiteController.php
- base
- controllers
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.
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:
2) I don’t believe you need to use the
use Controllers\Base\BaseControllerdirectives as the models directory is auto-loaded by default. Since you’re not name-spacing your controllers differently, theusedirective shouldn’t be needed. The above ‘dump-autoload’ should do the trick3) After the dump-autoload, change
to this:
You use of specific classes (for instance ‘Controllers\Website\WebsiteController’) won’t be necessary unless you define a different namespace for your new controllers