ActiveRecord pattern in controllers

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
//Insert Data
$insert = array(
'title' => 'New post',
'createdTime' => new DbExpression('NOW()'),
'post' => 'somemessge',
);
Post::model()->add($insert);
//Update Data
$update = array(
'count' => new DbExpression( 'increment', array( 'by'=>1 ) ),
);
Post::model()->
criterias( array( 'groupid' => $_GET['id'] ),
array( 'published' => true ) ) ->
update($update);
//Select Data
$data = Post::model()->
criterias( array( 'groupid' => $_GET['id'] ),
array( 'published' => true ) ) ->
findAll();
//Delite Data
Post::model()->
criterias( array( 'groupid' => $_GET['id'] ) ) ->
delite();