Load controller as services.
This commit is contained in:
parent
601d42ea6e
commit
b6f25e77c3
|
@ -135,8 +135,7 @@ class Application extends b8\Application
|
||||||
|
|
||||||
if ($this->response->hasLayout() && $this->controller->layout) {
|
if ($this->response->hasLayout() && $this->controller->layout) {
|
||||||
$this->setLayoutVariables($this->controller->layout);
|
$this->setLayoutVariables($this->controller->layout);
|
||||||
|
$this->controller->layout->content = $this->response->getContent();
|
||||||
$this->controller->layout->content = $this->response->getContent();
|
|
||||||
$this->response->setContent($this->controller->layout->render());
|
$this->response->setContent($this->controller->layout->render());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,18 +143,26 @@ class Application extends b8\Application
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a particular controller, and injects our layout view into it.
|
* @return \PHPCI\Controller
|
||||||
* @param $class
|
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
protected function loadController($class)
|
public function getController()
|
||||||
{
|
{
|
||||||
$controller = parent::loadController($class);
|
if (empty($this->controller)) {
|
||||||
$controller->layout = new View('layout');
|
try {
|
||||||
$controller->layout->title = 'PHPCI';
|
$this->controller = $this->container->get('application.controller.' . strtolower($this->route['controller']));
|
||||||
$controller->layout->breadcrumb = array();
|
}
|
||||||
|
catch (\Exception $e) {
|
||||||
|
var_dump($this->route);
|
||||||
|
var_dump($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $controller;
|
return $this->controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function controllerExists($route)
|
||||||
|
{
|
||||||
|
return $this->container->has('application.controller.' . strtolower($route['controller']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -52,6 +52,10 @@ class Controller extends \b8\Controller
|
||||||
{
|
{
|
||||||
parent::__construct($config, $request, $response);
|
parent::__construct($config, $request, $response);
|
||||||
|
|
||||||
|
$this->layout = new View('layout');
|
||||||
|
$this->layout->title = 'PHPCI';
|
||||||
|
$this->layout->breadcrumb = array();
|
||||||
|
|
||||||
$class = explode('\\', get_class($this));
|
$class = explode('\\', get_class($this));
|
||||||
$this->className = substr(array_pop($class), 0, -10);
|
$this->className = substr(array_pop($class), 0, -10);
|
||||||
$this->setControllerView();
|
$this->setControllerView();
|
||||||
|
|
Loading…
Reference in a new issue