开发者

how to get template name in symfony

开发者 https://www.devze.com 2023-04-08 11:04 出处:网络
I want to get my template name in my layout.php. please help me <?php $module_name = $sf_context->getModuleName(); ?>

I want to get my template name in my layout.php. please help me

<?php $module_name = $sf_context->getModuleName(); ?>

i'm using th开发者_如何学Cis above code to get module name, but how to get my current template name.


if you set the template in your action with the setTemplate() function you can just get the template name with getTemplate(). If you did¡nt assign a template in the action the get Template function will return null.

If you didn't modify the template associated to an action (by default the execute[Action] has a [action]Success.php template) you can make a function like this in your action:

$funcName = $this->getActionName();
--> find the first uppercase letter there starts the function name.
--> $new String() = [first letter of name in lowercase] . [rest of the name]
--> $String = string . "Success.php";

i'm not advanced enough in php to tell the exacte code but that's the algorithm.

Hope it helped you, good luck;


So symfony is a MVC framework your question belongs to sfView

/* layout.php e.g. */
var_dump($this->getTemplate());

See :

  • http://www.symfony-project.org/api/1_4/sfView#method_gettemplate
0

精彩评论

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