开发者

In Symfony ( PHP ), what is the path of setTemplate method?

I am using the following code in action class of a module XYZ:

$this->setTemplate("abc.php");

In which directory, it is trying to find ab开发者_Go百科c.php?


The corresponding path is the templates directory that is parallel to the actions directory in which you are editing the actions.class.php file.

Within the file /path/to/my/module/actions/actions.class.php, if you do this:

$this->setTemplate("index");

The corresponding template file will be located at:

/path/to/my/module/templates/indexSuccess.php

This of course assumes successful completion of the action; upon failure, the handling is different and depends on your implementation.

Also worth noting:

If you don't set a template manually using $this->setTemplate($foo), the template name is determined by convention. For the action function executeHomepage(sfWebRequest $request), the template homepageSuccess.php will be shown by convention (again, unless you specify otherwise with setTemplate).


See http://www.symfony-project.org/gentle-introduction/1_4/en/06-Inside-the-Controller-Layer#chapter_06_sub_action_termination. This documentation page contains comprehensive list of possible template names.

To be clear. Call

$this->setTemplate("abc");

will force Symfony to render template module/templates/abcSuccess.php if coressponding action method returns sfView::SUCCESS or nothing.

module/templates/abcError.php will be rendered if your action will return sfView::ERROR.

Also if your action is terminated with return 'SomeString'; then module/templates/abcSomeString.php is to be rendered.


According to API Documentation:

any time i write this:

$this->setTemplate('action_name', 'module_name');

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜