YY框架的学习
yyuc框架的開發(fā)手冊地址:
?http://www.yyuc.net/yyuc/00summary/00summary.html
一些自己整理的知識點
1.簡單的輸出hello word
方法一:
<?php
Page::ignore_view();
Response::write("hello_word");
解釋:
page::ignore_view默認為 true,執(zhí)行完這個php文件之后框架會繼續(xù)加載它對應的視圖文件來執(zhí)行,Page::ignore_view()將其設為 false則執(zhí)行完php文件后就不再尋找視圖文件了。
Response::write 方法是向客戶端進行文本輸出,執(zhí)行后立即退出腳本。
?
方法二:
hello.php 文件不寫任何代碼,可以建立空文件:controller/demo/hello.php。
建立文件:view/default/demo/hello.html
<h1>hello word</h1>
?
2.數(shù)據(jù)庫的配置:
yyuc/conf.php 在這個文件里面, 里面的東西很詳細
?
3.新增信息保存
首先先創(chuàng)建一個對應的model類,
<?php
$note = new Model('notes');
html的代碼:
<form action="" method="post"> 標題:{$note->text('title')}<br/> 作者:{$note->text('author')} 主題:{$note->select('theme')}<br/> 發(fā)表時間:{$note->date('postdate')} 是否發(fā)布:{$note->checkbox('bepublished')}<br/> 內容:<br/> {$note->textarea('content')}<br/> <button type="submit">提交</button>
?
解釋一下html中一些紅的數(shù)據(jù)
保存:
if(Request::post()){ //如果有post信息 則認為是新增后的Form提交 //單純的post信息判斷是不安全的 因為沒有具體的字段要求和判斷所以可以這樣寫 $note->load_from_post(); $note->save(); }
?
4.列表展示
<?php
$note = new Model('notes');
$notes = $note->list_all();
?
前段展示是用loop代替foreach的、
{loop $notes as $n}
<tr> <td>{$n->title}</td> <td>{$n->author}</td> <td>{$n->field_text('theme')}</td> <td>{date('Y-m-d',$n->postdate)}</td> </tr> {/loop}
?
5.信息的刪除
<?php
先獲取你要刪除的id
if (isset($_GET[1])){ //指定要操作的模型id 刪除之 $note = new Model('notes'); $note->id($_GET[1]); $note->remove(); } //返回請求前的頁面 Redirect::back();
?
6.分頁功能的實現(xiàn)
<?php $note = new Model('notes'); $pagination = new Pagination(8, 7); $notes = $pagination->model_list($note); ?>
?
7.簡單模型
sampleModel
前臺的form表單向后臺提交數(shù)據(jù),提交的數(shù)據(jù)你并不需要保存在數(shù)據(jù)庫之中。這時候你就可以使用SampleModel了。
sampleModel::__construct(string $tablename, string $postid){
?
}
?
其他的方法詳細見文檔
8.緩存
常規(guī)緩存
page::cache_normal();
基于時間的緩存
page::cache_time(0.001);
基于庫表變動的緩存
page::cache_dbs('news','users');
memcached緩存
?
Cache::set($k,$v); 設置緩存
Cache::get($k); 讀取緩存
Cache::remove($k) 刪除某段緩存
Cache::has($k) 查看是否存在某個緩存值
Cache::forever($k,$v)永久性的保存緩存數(shù)據(jù) 已文件形式存儲的
Cache::forget($k)永久刪除某個緩存
9.會話控制 session cookie
?
Session::set($k,$v); 設置會話控制
Session::get($k);獲取Session內容
Session::has($k);檢查session是否有指定的內容
Session::remove($k)刪除指定session內容
Session::once($k,$v);一次性Session顯示存入
Session::flush($k);獲取session一次性內容
Session::hold($k);判斷session是否含有一次性顯示的內容
?
10.request請求
?
Request::get(string $pam, mixed $default)獲取get方式提交的參數(shù)
如果參數(shù)為null,則判斷是否有get提交
Request::post(string $param,mixed $default)
獲取post方式提交的參數(shù),如果參數(shù)為null,則判斷是否有post提交
Request::obtain(string $param,mixed $default);
通用,get和post
Request::ip()獲取客戶端ip(真實的ip地址)
Request::page();
url請求中含有分頁參數(shù)表示的頁數(shù)
沒有分頁參數(shù)則返回1
Request::part();
層級式url解析時的各級名稱
例子:
http://www.yyuc.net/linux/install/sendmail.html
?
$link0 = Request::part(0); $link0的值為linux。
$link1 = Request::part(1); $link1的值為install。
$link2 = Request::part(2); $link2的值為sendmail。
?
Request::is_normal_cache() 判斷當前請求是不是常規(guī)緩存的請求
Request::url();
獲取用戶請求的真實url,不帶請求后綴
Request::json()
獲取ajax請求的json數(shù)據(jù),并轉成php數(shù)組
客戶端請求的參數(shù)名稱必須為data
?
11.response
?
Response::write(string $str, Mime $mime)
文本輸出,輸出后退出
Response::json($arr)
json輸出,輸出后退出
Response::exejs('要執(zhí)行的js腳本')
客戶端直接執(zhí)行js
Response::download(string $filename, mixed $content, Mime $mime)
為客戶端進行文件下載
Auth類的操作方法:
Auth::im_admin(mixed $adminlevel)
管理員聲明
如果管理員分為多種類型可以調用Auth::im_admin('home'),Auth::im_admin('office')。由傳入的組即可區(qū)分聲明是家庭管理員還是辦公管理員。 Auth::im_admin(array('home','office'))。即是家庭也是辦公
Auth::im_user($userlevel, string $userkey);
mixed $userlevel用戶級別(string|array) string $userkey 群組標識
im_user也可以不傳任何參數(shù)直接調用,用來聲明當前用戶為普通用戶:Auth::im_user()。
Auth::is_admin()
判斷用戶是否是管理員
Auth::is_user()
判斷用戶是否登錄
?
數(shù)據(jù)庫的原生操作:
?
DB::query(string $sql, array $pam) 普通SQL查詢
eg:
$db = DB::get_db(); //普通SQL $res = $db->query("select * from a, b where a.id<3 and a.name=b.name and b.sex='男'"); //參數(shù)查詢 $res = $db->query("select * from a, b where a.id<? and a.name=b.name and b.sex=?",array('3','男'));
?
DB::execute(string $sql, array $pam) 執(zhí)行無結果查詢(增,刪,改)
?
事務之間的操作
DB::begin_transaction() 開啟事務
DB::rollback() 事務回滾
DB::commit() 事務提交
?
DB::list_fields(表名);
獲得數(shù)據(jù)庫表字段名稱一維數(shù)組 成功獲得后將存入 靜態(tài)變量中 作為數(shù)據(jù)緩沖
總結
- 上一篇: ffmpeg实现摄像头拉流_ffmpeg
- 下一篇: 本原BCH码