我試圖在Yii中實現一個改寫的Ext.Direct功能。除了我不能讓doRpc
函數正常工作,並且這對於應用程序正常工作至關重要,該函數在Sencha Ext.Direct Tutorial中定義,雖然我已對其進行了一些更改,所以這是我的重寫代碼:Yii PHP框架:無法在Yii中require_once
組件/ 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");
}
}
模塊/直接/視圖/班/ 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,因爲我根本沒有得到過電流誤差)
我不是確定你在這裏試圖做什麼。預期的結果是什麼? – Jon 2013-02-13 13:19:19
[PHP的可能的重複 - 包括一個PHP文件,也發送查詢參數](http://stackoverflow.com/questions/1232097/php-include-a-php-file-and-also-send-query-parameters)或[php包含與選項的URL的問題?查看=任務及其他文件未找到](http://stackoverflow.com/questions/3592251/php-include-problem-with-urls-with-options-view-taskothers-file-未找到?rq = 1) – deceze 2013-02-13 13:20:26
我正在嘗試使用'require_once'來包含調用中指定的文件。對於這種情況,它被命名爲'Temporary',因此它將變成'require_once(「index.php?r = direct/classes/index&classaction = Temporary」);' - 但對於其他操作,它將是別的。但'require_once'總是導致:'require_once(index.php?r = direct/classes/index & classaction = Temporary):未能打開流:沒有這樣的文件或目錄。 – rnngau 2013-02-13 13:23:58