I have a question about how the \Phalcon\Mvc\View works.
This class has a setContent()
method, yet the content set with it won't be part of the output of $this->getContent()
- neither in views/example/overview.phtml
nor views/index.phtml
.
Shouldn't foobar
show up in one of those views?
Use-Case:
I have different HTML codes for some contents, saved in a database. Those codes should be setable as the content for overviewAction
(and some other actions in different controllers) and I don't want to create view files for all those actions, yet the content should be included in/be part of the main layout. That's why simply returning the content won't work.
ExampleController.php
class ExampleController extends \Phalcon\Mvc\Controller {
public function overviewAction () {
//This doesn't work, too:
//$this->view->disableLevel([\Phalcon\Mvc\View::LEVEL_ACTION_VIEW => true]);
$this->view->setContent('foobar');
}
}
index.php:
$di->setShared('view', function() use ($events_manager, $di) {
$view = new \Phalcon\Mvc\View();
//Disable layout-level
$view->disableLevel([\Phalcon\Mvc\View::LEVEL_LAYOUT => true]);
//Bind the EventsManager to the view component
$view->setEventsManager($events_manager);
$view->setVar('f', $di->get('filter'));
return $view;
});