[英]use the variable returned by cakephp controller
我正在使用 cakephp 2.10.24。 我需要在 php 文件(不是视图)中使用从 controller 返回的变量,所以我使用调度 function 发出 Cakephp 请求。 数据自行显示,我无法在调度调用后执行某些代码。
我尝试添加到 controller 但它没有用
$this->autoRender = false;
$this->layout = false;
$this->autoLayout = false;
controller 动作:
$this->autoRender = false;
$this->layout = false;
$this->autoLayout = false;
$this->response->body(json_encode(array(
'key' => 0,
'message' => 'Invalid request.'
)));
$this->response->send();
$this->_stop();
php 档案:
<?php
echo ('i\'m test file <br />');
include 'app/webroot/index.php';
$request = new CakeRequest('/controller/action/param');
$response = new CakeResponse(array('type' => 'application/json'));
echo $results = $Dispatcher->dispatch(
$request ,
$response,
array('return' => 'vars')
);
//some codes not running
var_dump($response);
print_r(json_decode($response));
?>
得到了结果,但仍然在屏幕上自动打印结果。
测试文件:
$dispatcher = new Dispatcher();
$response = new CakeResponse();
$results = $dispatcher->dispatch(new CakeRequest('/Controlller/Action/params'),$response);
print_r("response: ".$response);
controller 中的操作:
$this->autoRender=false;
$this->autoLayout=false;
$this->response->body($result);
$this->response->send();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.