I'm trying to implement a rewritten Ext.Direct functionality into Yii. And everything works smoothly except that I cannot get the doRpc
function to work properly, and this is vital to the application working properly, the function is defined in the Sencha Ext.Direct Tutorial, although I have done some changes to it, so here's my rewritten code:
components/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);
}
}
}
modules/direct/controllers/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;
}
...
}
The problem:
require_once("index.php?r=direct/classes/index&classaction=$action");
What is the best way of circumventing this problem? How do I 'parse'/include/require this PHP file?
(Have in mind that I haven't gotten around to testing my Temporary.php, because I simply have not gotten past the current error)