Для получения полного доступа
зарегистрируйтесь.
RSS

All snippets tagged with "codeigniter" tag


samdark
  • Reputation: 349
  • Snippets: 57
  • Revisions: 5

Named scopes are quite useful and are familiar to developers who work with Yii. The code shows how to get these in CodeIgniter.

class Post extends Model
{
    function __construct() {
        parent::__construct();
        $this->db->from('post')->order_by("created_at", "desc");
    }
 
    function limit($number) {
        $this->db->limit($number);
        return $this;
    }
 
    function all() {
        return $this->db->get()->result();        
    }
}

$posts = $this->post->limit(10)->find();
foreach($posts as $post) {
	// ..