Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建自己的PHP框架,如何向页面控制器发送参数_Php_Oop_Model View Controller - Fatal编程技术网

创建自己的PHP框架,如何向页面控制器发送参数

创建自己的PHP框架,如何向页面控制器发送参数,php,oop,model-view-controller,Php,Oop,Model View Controller,我正在创建自己的框架。它是这样工作的 localhost/controller/action/firstVariable/second/third(等等…) 我的引导程序如下所示: $request = Util::getInput('request'); $requestList = explode("/",$request); $modelName = @ucwords($requestList[0]); $action = @$requestL

我正在创建自己的框架。它是这样工作的
localhost/controller/action/firstVariable/second/third
(等等…) 我的引导程序如下所示:

$request        = Util::getInput('request');
$requestList    = explode("/",$request);
$modelName      = @ucwords($requestList[0]);
$action         = @$requestList[1];
$parameters = array_slice($requestList,2);
$controllerName = $modelName.'s'.'Controller';
我从url获取参数,并将它们保存在变量
$parameters
中。我想以Laravel 5的方式将它们发送到控制器中的当前操作

例如,在Laravel中,我在url中指定参数,就是这样

要给他们打电话,我需要做一个简单的步骤。只需定义它们:

public function firstAction($first,$second){

}
当我转到如下url时:
localhost/Main/firstAction/first/second/

动作“firstAction”的函数将捕获这两个参数,然后基本上我可以在控制器内部调用它们并将其发送到视图

我的控制器类:

class Controller{
public function __construct($model,$action){
    $modelClass = new main();
    $reflection = new ReflectionClass($model.'sController');
    $reflection->hasMethod($action) ? $this->$action() : die ('Base Controller call error: Method '. $action .' does not exist in Controller '. $model.'sController');

}
public static function renderView($action,$model,$data){
    $model = str_replace('sController','',$model);
    //include '../application/views/'.$model.'/'.$action.'.php';
    $loader = new Twig_Loader_Filesystem('../application/views/'.$model);
    $twig = new Twig_Environment($loader);
    echo $twig->render($action.'.php', $data);
}
}

}

我该怎么做,好办法?当然,我可以将变量$parameter发送到MainController,然后调用 $this->\我的操作中包含数据,但效率不高。 我想我需要使用数组来做这件事,但我不知道怎么做

谢谢。

退房

附言。 您不必使用反射来检查对象实例上的方法是否存在。单个函数调用就足够了。退房


如果你能用更具描述性的名字就好了。现在他们很困惑。

你说的“好的方式”是什么意思?@John你为什么要给别人这样的建议?去使用别人构建的框架,这样你除了用别人的作品编程之外就什么也学不到了?nonsens..@dbf,你为什么不创建自己的操作系统?@dbf,当然你正在使用it@John我问你一个问题,你为什么要给别人这样的建议。。但是你也可以继续添加无用的评论。谢谢你,这就是我需要的!函数调用\用户\函数\数组!祝你有美好的一天!感谢第二个功能:)
class MainsController extends Controller {

private $_data = array();

public function __construct($model,$action){
    parent::__construct($model,$action);
}

public function firstAction($first,$second){
    echo 'Hoi';
}