任何人都可以告诉我如何通过单一动作制作更多的视图

时间:2012-11-29 11:04:50

标签: php zend-framework

任何人都可以告诉我如何通过基于zend模块的Framework中的单个操作创建多个视图。

例如

$UserId    = $this->getRequest()->getParam('id');
if($UserId !='')
{    
    $userDetails =$loginObj->getUserTypeByID($UserId);
    if($userDetails == 0)
        $this->_helper->redirector('index', 'profile', 'default');
    else
        $usrType    = $userDetails['user_type'];
    if($usrType =='C' || $usrType =='H' )
    {
        //$this->renderScript('other-user-profile.phtml' );
        //$this->render("other-user-profile.phtml");
        $this->_helper->viewRenderer('profile/other-user-profile.phtml');
            //$this->_forward('other-user-profile.phtml','profile','default');
    }
    else
    {
           $this->render("index.phtml");
    }  
}

这不起作用?如何解决?

1 个答案:

答案 0 :(得分:2)

可以通过多种方式完成,例如使用Partial视图助手。

编辑:回复您的代码段:

您最好使用ViewRenderer Action Helpers。检查此页面中的示例#11。代码中的注释非常自我解释。我建议你注意脚本路径。

// Bar controller class, foo module:
class Foo_BarController extends Zend_Controller_Action
{
    public function addAction()
    {
        // Render 'bar/form.phtml' instead of 'bar/add.phtml'
        $this->_helper->viewRenderer('form');
    }

    public function editAction()
    {
        // Render 'bar/form.phtml' instead of 'bar/edit.phtml'
        $this->_helper->viewRenderer->setScriptAction('form');
    }

    public function processAction()
    {
        // do some validation...
        if (!$valid) {
            // Render 'bar/form.phtml' instead of 'bar/process.phtml'
            $this->_helper->viewRenderer->setRender('form');
            return;
        }

        // otherwise continue processing...
    }

}