public function search($fields, $limit = -1)
    {
        if (!is_array($fields)) {
            $fields = array($this->getIndex() => $fields);
        }

        $fieldsValue = $fields;
        $fields = $this->getFields();
        $sql = '';
        $args = array();
        foreach ($fields as $field) {
            if (isset($fieldsValue[$field])) {
                $value = $fieldsValue[$field];
                if ($this->isString($field)) {
                    $sql .= '`' . $field . '` LIKE ? OR ';
                    $args[] = '%' . $value . '%';
                } else {
                    $sql .= '`' . $field . '` = ? OR ';
                    $args[] = $value;
                }
            }
        }
        if (!empty($sql)) {
            $sql = substr($sql, 0, -4);
            if($limit > 0) {
                $sql .= " LIMIT $limit";
            }
            return $this->build($this->db->select('SELECT * FROM `' . $this->table_name . '` WHERE ' . $sql, $args));
        }
        return $this->build(array());
    }
public function search($fields, $limit = -1)
    {
        if (!is_array($fields)) {
            $fields = array($this->getIndex() => $fields);
        }

        $fieldsValue = $fields;
        $fields = $this->getFields();
        $sql = '';
        $args = array();
        foreach ($fields as $field) {
            if (isset($fieldsValue[$field])) {
                $value = $fieldsValue[$field];
                if ($this->isString($field)) {
                    $sql .= '`' . $field . '` LIKE ? OR ';
                    $args[] = '%' . $value . '%';
                } else {
                    $sql .= '`' . $field . '` = ? OR ';
                    $args[] = $value;
                }
            }
        }
        if (!empty($sql)) {
            $sql = substr($sql, 0, -4);
            if($limit > 0) {
                $sql .= " LIMIT $limit";
            }
            return $this->build($this->db->select('SELECT * FROM `' . $this->table_name . '` WHERE ' . $sql, $args));
        }
        return $this->build(array());
    }
public function search ( $ fields , $ limit = - 1 ) { if ( ! is_array ( $ fields ) ) { $ fields = array ( $ this -> getIndex ( ) => $ fields ) ; } $ fieldsValue = $ fields ; $ fields = $ this -> getFields ( ) ; $ sql = '' ; $ args = array ( ) ; foreach ( $ fields as $ field ) { if ( isset ( $ fieldsValue [ $ field ] ) ) { $ value = $ fieldsValue [ $ field ] ; if ( $ this -> isString ( $ field ) ) { $ sql .= '`' . $ field . '` LIKE ? OR ' ; $ args [ ] = '%' . $ value . '%' ; } else { $ sql .= '`' . $ field . '` = ? OR ' ; $ args [ ] = $ value ; } } } if ( ! empty ( $ sql ) ) { $ sql = substr ( $ sql , 0 , - 4 ) ; if ( $ limit > 0 ) { $ sql .= " LIMIT $limit" ; } return $ this -> build ( $ this -> db -> select ( 'SELECT * FROM `' . $ this -> table_name . '` WHERE ' . $ sql , $ args ) ) ; } return $ this -> build ( array ( ) ) ; }
Busca en forma de texto en la tabla

@param $fields
@param int $limit
@return ModelResult
Busca en forma de texto en la tabla