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