<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查询构建器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                    <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>