class DefaultController extends AppController
{
protected $components = array('smarty');
/**Default event (method)*/
public function index()
{
$db_test = M('members'); //Load and instantiate A model
/**Add data*/
$data = array(
'title' => 'Writing test',
'body' => 'Written content ',
);
$result = $db_test->create($data);
if(FALSE != $result)
{
dump("
< ;strong>exampel 1:
Data written successfully!
");
}
/**Add multiple pieces of data*/
dump( "
exampel 2:
");
$data = array(
array('title'=>'data 1', 'body'=>'Content1'),
array('title'=>'Data2', 'body'=>'Content2'),
array('title'=> ;'data3', 'body'=>'content3'),
array('title'=>'data4', 'body'=>'content4'),
array ('title'=>'Data5', 'body'=>'Content5'),
);
foreach($data as $item)
{
$result = $db_test->create($item);
if(FALSE != $result)
{
dump("data".$item['title']."< /strong>Write successfully!
");
}
}
dump("
");
/**Update data*/
$data = array( 'title'=>'Modify data title', 'body'=>'Modify data content');
$result = $db_test->where(array('id'=>3))- >update($data);
if(FALSE != $result)
{
dump("
exampel 3:
");
}
/**Delete data*/
$result = $db_test->where("id=5")-> remove();
if(FALSE != $result)
{
dump("
exampel 3:
Data deleted successfully !
");
}
/**Perform data queries using coherent operators*/
$db_test->where(array('id'=>12, 'action'=> 1))
->order("`id` DESC")
->fields("id,name,action")
->findAll();
$this- >shownav();
}
//Image processing event
public function image()
{
$file = Configure::read('app_path').'/yagas/ K750c_small_06.jpg';
$im = M('SYS', 'image'); //Load and instantiate a system model
$im->th_width = 200;
$im-> ;th_height = 150;
$im->thumb($file, null, false);
}
/**another controller event*/
public function admin()
{
dump($this);
$this->shownav();
}
/**another controller event*/
public function info()
{
$this->shownav();
phpinfo();
}
/**This is an internal event and cannot be accessed from the browser address*/
private function shownav()
{
echo '< ;a href="/">Access default event |
Access event admin |
Access event info';
}
}
?>