开发者

How to get the name of the current layout?

symfony getLayout does not seem to work when layout is set via view.yml. Is there anyway to get this开发者_如何学C within the controller's action class method


I recently needed this. You can do it but you just need to return the entire view.yml contents as an array:

$view_array = sfViewConfigHandler::getConfiguration(array(sfConfig::get('sf_app_config_dir').'/‌​view.yml'));

Just adjust the relative path from sf_app_config_dir (or use another marker) to get what you need.


It's not a trivial task. The view.yml, is not in the "scope" of the action.
Maybe, you can use setLayout in your action rather then in view.yml.
if you can't, for some reasons... you can try this method to reach datas in view.yml:
Is it possible to get a value from view.yml in an action


Execute the following code in the action. It works for both cases, layout set in the action or in the view.yml.

$controller = $this->getContext()->getController();
$view = $controller->getView($this->getModuleName(), $this->getActionName(), 'Success');  // viewName == 'Success' (default)
$layout_name = $view->getDecoratorTemplate();  // e.g expected: layout.php

Let us know if it works for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜