如何在路由器中调用同一个控制器的两个方法

时间:2016-08-04 07:32:19

标签: php laravel laravel-5 routing laravel-5.1

我想让两个方法调用一个视图(同一个控制器)。我怎样才能做到这一点。例如,这是一个到视图的路径

 Route::get('url', 'ExampleController@foo');
 Route::get('url', 'ExampleController@bar');

如何合并这两者。

1 个答案:

答案 0 :(得分:0)

        You need to code in controller methods i.e



class ExampleController extends CI_Controller {
    public $data;
    public function foo(){
        //inside foo get the view of bar in variable i.e.
        $this->data['bar_view'] = $this->load->view('bar_view',$this->data,true);
        $this->load->view('foo_view',$this->data);
    }
    public function bar(){
        //inside foo get the view of bar in variable i.e.
        $this->data['foo_view'] = $this->load->view('foo_view',$this->data,true);
        $this->load->view('bar_view',$this->data);
    }
}


    // inside view display as the order you want