2011-09-27 86 views
1

我想在我的layout.php中獲取我的模板名稱。請幫我如何在symfony中獲取模板名稱

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

我使用上面的代碼來獲取模塊名稱,但如何獲得我當前的模板名稱。

回答

1

如果您在setTemplate()函數中將模板設置爲您的操作,則只需使用getTemplate()即可獲取模板名稱。如果您沒有在操作中分配模板,get Template函數將返回null。

如果沒有修改相關聯的動作模板(默認情況下,執行[動作]有[動作] 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來告訴exacte代碼,但這是算法。

希望它能幫助你,祝你好運;