0

在 zf2 中,我可以选择使用 Zend/Request 对象发出虚假请求。因此我可以做一个内部请求。我想用一些数据执行我网站的一部分。因此,我必须使用控制器、模块和动作。

我该怎么做?

这是来自上一个问题的 zf2 的代码片段:

/application/controller/IndexController.php

<?php
class IndexController extends Zend_Controller_Action
{
    public function init(){}
    public function indexAction()
    {
        //process some data from $_GET, $_POST, maybe (via framework, ofc).
    }
}

/public/index2.php

<?php
//--cut--
$application->bootstrap();
$options = array(
    'action' => 'index',
    'controller' => 'index',
    'module' => 'default'
);
if( isset($options['action'], $options['module'], $options['controller']) )
{
    //*
    $request = new Zend_Controller_Request_Http ();
    $request->setModuleName($options['module'])->setActionName($options['action'])->setControllerName($options['controller']);
    $frontController = Zend_Controller_Front::getInstance ()->returnResponse ( true );
    //*/

    $response = new Zend_Controller_Response_Http ();
    $frontController->getDispatcher ()->dispatch ( $request, $response );
    var_dump($response);
}

谢谢!

4

0 回答 0