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