是否有像_compile_select或get_compiled_select()这样的函数?

mir*_*rza 11 activerecord codeigniter codeigniter-2

看起来_compile_select已弃用,get_compiled_select不会添加到2.1.0.还有其他类似的功能吗?而且我很好奇.是否有任何特殊原因不添加get_compiled_select()到Active Record并删除_compile_select

小智 16

我添加get_compiled_select()来DB_active_rec.php,它似乎没有问题的工作,但我不会删除_compile_select(),因为它在许多其他的方法使用.

添加此方法的pull请求在这里,还有一些其他有用的方法,如:

  • get_compiled_select()
  • get_compiled_insert()
  • get_compiled_update()
  • get_compiled_delete()

https://github.com/EllisLab/CodeIgniter/pull/307

如果你只想要这个方法,就是这样:

/**
 * Get SELECT query string
 *
 * Compiles a SELECT query string and returns the sql.
 *
 * @access  public
 * @param   string  the table name to select from (optional)
 * @param   boolean TRUE: resets AR values; FALSE: leave AR vaules alone
 * @return  string
 */
public function get_compiled_select($table = '', $reset = TRUE)
{
    if ($table != '')
    {
        $this->_track_aliases($table);
        $this->from($table);
    }

    $select =  $this->_compile_select();

    if ($reset === TRUE)
    {
        $this->_reset_select();
    }

    return $select;
}
Run Code Online (Sandbox Code Playgroud)