dou29106 2015-01-21 14:58
浏览 46

如何在Laravel中的两个控制器之间传递和检索数据

I'm trying to get to grips with Laravel and not finding the documentation any help at all. It seems to assume you know so much instead of actually walking new users through each section step by step.

I've got to the point where I need to make an internal call to another class, and sticking with MVC I can't seem to do what should be a simple thing.

My code:

class UsersController extends BaseController {

    protected $layout   = 'layouts.templates.page';

    protected $messages;

    public function getIndex()
    {
        $input = array('where', array('field' => 'email', 'operator' => '=', 'value' => 'tony@fluidstudiosltd.com'));
        $request = Request::create('user/read', 'GET');
        $users = json_decode(Route::dispatch($request)->getContent());
        var_dump($users); exit;
        $this->pageTitle = 'Fluid Customer Status :: Admin Users';
        $this->content = View::make('layouts.admin.users');
    }

}

Class UserController extends Base Controller
    public function getRead()
    {
        $userId = (int) Request::segment(3);
        if ($userId)
        {
            $user = User::findOrFail($userId);
            return $user;
        }
        else
        {
            $users = new User;
            var_dump(Input::all()); exit;
            if (Input::has('where'))
            {
                var_dump(Input::get('where')); exit;
            }
            return $users->get();
        }
    }

Why isn't the input data from UsersController@getIndex available in UserController@getRead

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?