我对 Zend 有一点问题。我正在尝试发出一些虚假的 HTTP 请求,并在module->controller->action
执行后返回在该操作中设置的随机变量。就像在变量设置的情况下一样view->assign(,)
- 我可以稍后从视图文件 (.phtml) 访问它们。
这是我的代码的一部分:
/application/controller/IndexController.php
<?php
class IndexController extends Zend_Controller_Action
{
public function init(){}
public function indexAction()
{
#$this->view seems to be a NULL value from the fake request, so I can't pass variables to it
//$this->view->x = 'y';
echo 'test';
return array(
'x' => 'y'
);
}
}
/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 );
echo '$response:<b>Zend_Controller_Response_Http</b><br>';
//This returns me the body of what I echo in the indexAction but not the variables.
var_dump($response);
}
太感谢了!