duanjia3187 2013-04-11 16:49
浏览 24

too long

I am using zend framework 2.1. I am trying to load the output of my indexAction from my login controller inside of my index controller. The end result I am trying accomplish is to just have my login form loaded on the index page as if it is part of that view.

I have searched for a few hours with no avail. I have attempted to use $this->view->action, which i've seen in earlier versions of zf2 but that has not worked either.

Any information would be helpful.

  • 写回答

1条回答 默认 最新

  • drws65968272 2013-04-12 09:10
    关注

    Taken from this blog, which explains in depth why $this->view->action() has been removed from ZF2, an example how to use the forward() (ZF2 documentation) controller plugin:

    You can forward all necessary data to another controller inside your index controller action using the forward() controller plugin like this:

    public function indexAction() {
        $view = new ViewModel();
    
        $login_param = $this->params('login_param');
        $login = $this->forward()->dispatch('App\Controller\LoginController', array(
            'action' => 'display',
            'login_param' => $login_param
        ));
    
        $view->addChild($login, 'login');
    
        return $view;
    }
    

    In your view, all you need to do is:

    <?php echo $this->login; ?>
    

    Please note that the forward() plugin might return a Zend\Http\PhpEnvironment\Response instead. This happens if you use a redirect() in your login controller / action.


    Also, if the Servicemanager claims to not find App\Controller\LoginController, have a look in your module.config.php. Look for a section called controllers.
    Example:

    [...]
    'controllers' => array(
        'invokables' => array(
            'LoginCon' => 'App\Controller\LoginController',
            'IndexCon' => 'App\Controller\IndexController',
            'DataCon' => 'App\Controller\DataController',
        )
    ),
    [...]
    

    Here, there is an alias for your login controller called LoginCon, you should use this name as controller name in the dispatch() method instead.

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算