<small id='qCG0C'></small><noframes id='qCG0C'>

  • <legend id='qCG0C'><style id='qCG0C'><dir id='qCG0C'><q id='qCG0C'></q></dir></style></legend>
      <bdo id='qCG0C'></bdo><ul id='qCG0C'></ul>

        <i id='qCG0C'><tr id='qCG0C'><dt id='qCG0C'><q id='qCG0C'><span id='qCG0C'><b id='qCG0C'><form id='qCG0C'><ins id='qCG0C'></ins><ul id='qCG0C'></ul><sub id='qCG0C'></sub></form><legend id='qCG0C'></legend><bdo id='qCG0C'><pre id='qCG0C'><center id='qCG0C'></center></pre></bdo></b><th id='qCG0C'></th></span></q></dt></tr></i><div id='qCG0C'><tfoot id='qCG0C'></tfoot><dl id='qCG0C'><fieldset id='qCG0C'></fieldset></dl></div>
        <tfoot id='qCG0C'></tfoot>

        如何制作像codeigniter活动记录这样的laravel查询构建器

        how to make laravel query builder like codeigniter active record(如何制作像codeigniter活动记录这样的laravel查询构建器)
      1. <small id='Cj9IN'></small><noframes id='Cj9IN'>

            <bdo id='Cj9IN'></bdo><ul id='Cj9IN'></ul>

                  <i id='Cj9IN'><tr id='Cj9IN'><dt id='Cj9IN'><q id='Cj9IN'><span id='Cj9IN'><b id='Cj9IN'><form id='Cj9IN'><ins id='Cj9IN'></ins><ul id='Cj9IN'></ul><sub id='Cj9IN'></sub></form><legend id='Cj9IN'></legend><bdo id='Cj9IN'><pre id='Cj9IN'><center id='Cj9IN'></center></pre></bdo></b><th id='Cj9IN'></th></span></q></dt></tr></i><div id='Cj9IN'><tfoot id='Cj9IN'></tfoot><dl id='Cj9IN'><fieldset id='Cj9IN'></fieldset></dl></div>

                    <tbody id='Cj9IN'></tbody>
                1. <legend id='Cj9IN'><style id='Cj9IN'><dir id='Cj9IN'><q id='Cj9IN'></q></dir></style></legend>
                2. <tfoot id='Cj9IN'></tfoot>
                  本文介绍了如何制作像codeigniter活动记录这样的laravel查询构建器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在使用 Laravel 4 查询生成器时遇到问题,我想创建一个可重用的方法

                  I have a problem with Laravel 4 query builder, i want make a re-usable method

                  public function getData($where=array())
                  {
                      // $where = array('city' => 'jakarta', 'age' => '25');
                      return User::where($where)->get();
                  
                      // this will produce an error, because i think laravel didn't support it
                  }
                  

                  在 CodeIgniter 中很容易将数组传递给活动记录:

                  In CodeIgniter it easy to passing array to active record :

                  public function getData($where=array())
                  {
                      $rs = $this->db->where($where)->from('user')->get();
                  
                      return $rs->result();
                  }
                  
                  // it will produce :
                  // SELECT * FROM user WHERE city = 'jakarta' AND age = '25'
                  

                  知道如何在 Laravel 4 查询生成器上使用它吗?我有谷歌搜索但没有找到任何答案.之前谢谢.

                  Any idea how to have it on Laravel 4 query builder? I have googling but not find any answer. Thanks before.

                  推荐答案

                  你可以试试这个(假设这个函数在你的 User 模型中)

                  You may try this (Assumed, this function is in your User model)

                  class User extends Eloquent {
                  
                      public static function getData($where = null)
                      {
                          $query =  DB::table('User');
                          if(!is_null($where )) {
                              foreach($where as $k => $v){
                                  $query->where($k, $v);
                              }
                          }
                          return $query->get();
                      }
                  }
                  

                  请记住,= 是可选的.像这样称呼它

                  Rember that, = is optional. Call it like

                  $data = User::getData(array('first_name' => 'Jhon'));
                  

                  这篇关于如何制作像codeigniter活动记录这样的laravel查询构建器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Laravel 4 - Connect to other database(Laravel 4 - 连接到其他数据库)
                  Call external API function from controller, LARAVEL 4(从控制器调用外部 API 函数,LARAVEL 4)
                  Empty string instead of null values Eloquent(空字符串而不是空值 Eloquent)
                  quot;laravel.logquot; could not be opened: failed to open stream(“laravel.log无法打开:无法打开流)
                  Displaying the Error Messages in Laravel after being Redirected from controller(从控制器重定向后在 Laravel 中显示错误消息)
                  Laravel Creating Dynamic Routes to controllers from Mysql database(Laravel 从 Mysql 数据库创建到控制器的动态路由)
                    <bdo id='UVK3G'></bdo><ul id='UVK3G'></ul>

                        <i id='UVK3G'><tr id='UVK3G'><dt id='UVK3G'><q id='UVK3G'><span id='UVK3G'><b id='UVK3G'><form id='UVK3G'><ins id='UVK3G'></ins><ul id='UVK3G'></ul><sub id='UVK3G'></sub></form><legend id='UVK3G'></legend><bdo id='UVK3G'><pre id='UVK3G'><center id='UVK3G'></center></pre></bdo></b><th id='UVK3G'></th></span></q></dt></tr></i><div id='UVK3G'><tfoot id='UVK3G'></tfoot><dl id='UVK3G'><fieldset id='UVK3G'></fieldset></dl></div>
                      • <legend id='UVK3G'><style id='UVK3G'><dir id='UVK3G'><q id='UVK3G'></q></dir></style></legend>
                        <tfoot id='UVK3G'></tfoot>

                        <small id='UVK3G'></small><noframes id='UVK3G'>

                              <tbody id='UVK3G'></tbody>