【问题标题】:How to call two methods of same controller in router如何在路由器中调用同一控制器的两个方法
【发布时间】:2016-08-04 07:32:18
【问题描述】:

我有两种方法要调用到视图中(同一个控制器)。我怎样才能做到这一点。例如,这是通往视图的路线

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

如何合并这两者。

【问题讨论】:

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


    【解决方案1】:
            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
    

    【讨论】:

      猜你喜欢
      • 2018-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-26
      • 1970-01-01
      • 2018-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多