ThinkPHP學習筆記(十六)使用視圖(資料庫檢視)和緩衝____PHP

來源:互聯網
上載者:User

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>



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.