Symfony1 如何在symfony中获取模板名称

Symfony1 如何在symfony中获取模板名称,symfony1,Symfony1,我想在我的layout.php中获取模板名称。请帮帮我 <?php $module_name = $sf_context->getModuleName(); ?> 我使用上述代码获取模块名,但如何获取当前模板名。如果您在操作中使用setTemplate()函数设置模板,则只需使用getTemplate()函数获取模板名即可。如果在操作中未分配模板,则get template函数将返回null 如果您没有修改与某个操作关联的模板(默认情况下,execute[action]有

我想在我的layout.php中获取模板名称。请帮帮我

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


我使用上述代码获取模块名,但如何获取当前模板名。

如果您在操作中使用
setTemplate()
函数设置模板,则只需使用
getTemplate()
函数获取模板名即可。如果在操作中未分配模板,则get template函数将返回null

如果您没有修改与某个操作关联的模板(默认情况下,execute[action]有一个[action]Success.php模板),您可以在操作中创建如下函数:

$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";
我在php方面还不够高级,无法说出准确的代码,但这就是算法


希望它能帮助你,祝你好运

如果使用
setTemplate()
函数在操作中设置模板,则只需使用
getTemplate()
获取模板名称即可。如果在操作中未分配模板,则get template函数将返回null

如果您没有修改与某个操作关联的模板(默认情况下,execute[action]有一个[action]Success.php模板),您可以在操作中创建如下函数:

$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";
我在php方面还不够高级,无法说出准确的代码,但这就是算法


希望它能帮助你,祝你好运

所以symfony是一个MVC框架,您的问题属于sfView

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


    • 那么symfony是一个MVC框架,您的问题属于sfView

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