yyuc框架的开发手册地址:
http://www.yyuc.net/yyuc/00summary/00summary.html
一些自己整理的知识点
1.简单的输出hello word
方法一:
<?php
Page::ignore_view();
Response::write("hello_word");
解释:
page::ignore_view默认为 true,执行完这个php文件之后框架会继续加载它对应的视图文件来执行,Page::ignore_view()将其设为 false则执行完php文件后就不再寻找视图文件了。
Response::write 方法是向客户端进行文本输出,执行后立即退出脚本。
方法二:
hello.php 文件不写任何代码,可以建立空文件:controller/demo/hello.php。
建立文件:view/default/demo/hello.html
<h1>hello word</h1>
2.数据库的配置:
yyuc/conf.php 在这个文件里面, 里面的东西很详细
3.新增信息保存
首先先创建一个对应的model类,
<?php
$note = new Model('notes');
html的代码:
<form action="" method="post"> 标题:{$note->text('title')}<br/> 作者:{$note->text('author')} 主题:{$note->select('theme')}<br/> 发表时间:{$note->date('postdate')} 是否发布:{$note->checkbox('bepublished')}<br/> 内容:<br/> {$note->textarea('content')}<br/> <button type="submit">提交</button>
解释一下html中一些红的数据
保存:
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.分页功能的实现
<?php $note = new Model('notes'); $pagination = new Pagination(8, 7); $notes = $pagination->model_list($note); ?>
7.简单模型
sampleModel
前台的form表单向后台提交数据,提交的数据你并不需要保存在数据库之中。这时候你就可以使用SampleModel了。
sampleModel::__construct(string $tablename, string $postid){
}
其他的方法详细见文档
8.缓存
常规缓存
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)永久性的保存缓存数据 已文件形式存储的
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方式提交的参数
如果参数为null,则判断是否有get提交
Request::post(string $param,mixed $default)
获取post方式提交的参数,如果参数为null,则判断是否有post提交
Request::obtain(string $param,mixed $default);
通用,get和post
Request::ip()获取客户端ip(真实的ip地址)
Request::page();
url请求中含有分页参数表示的页数
没有分页参数则返回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() 判断当前请求是不是常规缓存的请求
Request::url();
获取用户请求的真实url,不带请求后缀
Request::json()
获取ajax请求的json数据,并转成php数组
客户端请求的参数名称必须为data
11.response
Response::write(string $str, Mime $mime)
文本输出,输出后退出
Response::json($arr)
json输出,输出后退出
Response::exejs('要执行的js脚本')
客户端直接执行js
Response::download(string $filename, mixed $content, Mime $mime)
为客户端进行文件下载
Auth类的操作方法:
Auth::im_admin(mixed $adminlevel)
管理员声明
如果管理员分为多种类型可以调用Auth::im_admin('home'),Auth::im_admin('office')。由传入的组即可区分声明是家庭管理员还是办公管理员。 Auth::im_admin(array('home','office'))。即是家庭也是办公
Auth::im_user($userlevel, string $userkey);
mixed $userlevel用户级别(string|array) string $userkey 群组标识
im_user也可以不传任何参数直接调用,用来声明当前用户为普通用户:Auth::im_user()。
Auth::is_admin()
判断用户是否是管理员
Auth::is_user()
判断用户是否登录
数据库的原生操作:
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='男'"); //参数查询 $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) 执行无结果查询(增,删,改)
事务之间的操作
DB::begin_transaction() 开启事务
DB::rollback() 事务回滚
DB::commit() 事务提交
DB::list_fields(表名);
获得数据库表字段名称一维数组 成功获得后将存入 静态变量中 作为数据缓冲