I created a dynamic route due to my complex routes my routes.php was unamaneagle.
Below I create my controller using $controller = new $controller; then $controller->$action(); The controller initialized extends BaseController which has a layout set with $this->layout. The problem is it seems when I manually create this controller, then I cannot access the layout object on BaseController to get data in my view.
this line
$this->layout->dataGroup = $data;
gives me
Attempt to assign property of non-object
routes.php
Route::get('/{dcontroller}/view/{id}', function($dcontroller, $id) {
$controller = ucfirst($dcontroller).'Controller';
$action = 'getView';
$controller = new $controller;
return $controller->$action($id);
});
BaseController.php
class BaseController extends Controller {
protected $layout = 'layouts.master';
protected function layoutFnc($path, $data) {
// ********************* THIS FAILS!! *********************
$this->layout->dataGroup = $data;
// *********************
$this->layout->content = View::make($path, $data);
}
}
MyController.php
class MyController extends BaseController {
public function getView($id) {
$this->layoutFnc('layouts/test', aray('test', 'test2'));
}
}