Action
<?phpclass UserViewAction extends Action{public function index(){$user=new UserViewModel();$list=$user->select();dump($list);}}?>
自訂一個viewmodel
<?phpclass UserViewModel extends ViewModel{public $viewFields=array(//設定查詢的表名和欄位'User'=>array('id','username','password'),//message的id重新命名為mid//_on表示關聯條件;_type表示做關聯還是右關聯'UserMessage'=>array('id'=>'mid','msg','_on'=>'User.id=UserMessage.id','_type'=>'LEFT'),);}?>
緩衝的使用:
config的配置:
//設定緩衝//file:是在runtime/temp/下的序列化的資料//memecache:在記憶體之中'DATA_CACHE_TYPE'=>'file','DATA_CACHE_TIME'=>'3600',//開啟HASH子目錄進行緩衝'DATA_CACHE_SUBDIR'=>true,//子目錄的等級'DATA_PATH_LEVLE'=>3,
Action
<?phpclass CacheAction extends Action{ public function index(){ //$cache=Cache::getInstance('緩衝方式','緩衝參數'); //使用Xcache,設定有效期間60秒 //$cache=Cache::getInstance('Xcache',array('expace'=>60)); //$cache->set('緩衝名稱','值');$cache->name='值'; //$value=$cache->get('緩衝名稱');$cache->name //$cache->rm('緩衝名稱');unset($cache->name) //緩衝快捷方法:S('名字','資料','時間','類型'); $list=S('alist'); if (empty($list)) { echo '沒有緩衝啊,重新尋找'.'<br>'; $user=new UserViewModel(); $list=$user->select(); S('alist',$list,3000); } //檔案的快速緩衝F('名字','資料','位置'); //支援建立緩衝子目錄F('user/data','資料'); // dump($list); $this->assign('alist',$list); $this->display(); }}?>
html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title></title></head><body><volist name="alist" id="vo"><!--{$vo['username']}-->---<br></volist></body></html>