【问题标题】:Can anyone tell me how can i make more then one view through single action谁能告诉我如何通过单一动作制作多个视图
【发布时间】:2012-11-29 11:04:49
【问题描述】:

谁能告诉我如何在基于 zend 模块化的框架中通过单个操作制作多个视图。

例如

$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");
    }  
}

这不起作用?如何解决?

【问题讨论】:

  • 真的无法理解您的查询
  • 我猜你喜欢提出你的问题。我无法解密。
  • 请提供有意义且易于理解的问题!
  • 现在正在渲染哪个视图?

标签: php zend-framework


【解决方案1】:

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

编辑:响应您的代码段:

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

// 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...
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-15
    • 1970-01-01
    • 2011-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多