我正在尝试在 Yii 中实现重写的 Ext.Direct 功能。一切都很顺利,除了我无法让doRpc
函数正常工作,这对应用程序正常工作至关重要,该函数在Sencha Ext.Direct 教程中定义,虽然我对它做了一些更改,所以这是我的重写代码:
组件/Ext_Router.php
class Ext_Router extends CApplicationComponent
{
public function doRpc($cdata)
{
$API = Yii::app()->ext_api->getApi();
try {
if(!isset($API[$cdata->action])){
throw new Exception('Call to undefined action: ' . $cdata->action);
}
$action = $cdata->action;
$a = $API[$action];
Yii::app()->ext_router->doAroundCalls($a['before'], $cdata);
$method = $cdata->method;
$mdef = $a['methods'][$method];
if(!$mdef){
throw new Exception("Call to undefined method: $method on action $action");
}
Yii::app()->ext_router->doAroundCalls($mdef['before'], $cdata);
$r = array(
'type'=>'rpc',
'tid'=>$cdata->tid,
'action'=>$action,
'method'=>$method
);
// TODO require_once always returns: No such file or directory
require_once("index.php?r=direct/classes/index&classaction=$action");
$o = new $action();
if (isset($mdef['len'])) {
$params = isset($cdata->data) && is_array($cdata->data) ? $cdata->data : array();
} else {
$params = array($cdata->data);
}
$r['result'] = call_user_func_array(array($o, $method), $params);
Yii::app()->ext_router->doAroundCalls($mdef['after'], $cdata, $r);
Yii::app()->ext_router->doAroundCalls($a['after'], $cdata, $r);
}
catch(Exception $e){
$r['type'] = 'exception';
$r['message'] = $e->getMessage();
$r['where'] = $e->getTraceAsString();
}
return $r;
}
public function doAroundCalls(&$fns, &$cdata, &$returnData=null)
{
if(!$fns){
return;
}
if(is_array($fns)){
foreach($fns as $f){
$f($cdata, $returnData);
}
}else{
$fns($cdata, $returnData);
}
}
}
模块/直接/控制器/ClassesController.php
class ClassesController extends Controller
{
public function actionIndex($classaction)
{
$this->render("$classaction");
}
}
modules/direct/views/classes/Temporary.php
class Temporary
{
protected $_result;
public $results;
public function getResults(stdClass $params)
{
$_result = Temporary::model()->findAllByAttributes(array('id'=>Yii::app()->session['id']));
$results = array();
if($_results != null) {
foreach($_result as $row) {
$results[] = $row;
}
}
return $results;
}
...
}
问题:
require_once("index.php?r=direct/classes/index&classaction=$action");
绕过这个问题的最佳方法是什么?我如何“解析”/包含/需要这个 PHP 文件?
(请记住,我还没有开始测试我的 Temporary.php,因为我根本没有克服当前的错误)