微信管家yyuc框架开发手册内容摘要:

$notelable(39。 postdate39。 )}: {$notedate(39。 postdate39。 )} {$notelable(39。 bepublished39。 )}:{$notecheckbox(39。 bepublished39。 )}br/ {$notelable(39。 content39。 )}: br/ {$notetexteditor(39。 content39。 )}br/ button type=submit提交 /button /form /body /html 刷新页面显示效果和之前的是一样的。 新增信息保存 修改控制器文件: controller/notes/。 ?php $note = new Model(39。 notes39。 )。 if(Request::post()){ //如果有 post 信息 则认为是新增后的 Form 提交 //单纯的 post 信息判断是不安全的 因为没有具体的字段要求和判断所以可以这样写 $noteload_from_post()。 $notesave()。 } ? 访问: 提交 ”。 这样各个字段的信息就会自动的保存到数据库中了。 信息列表展示 用户访问时默认展示列表页,所以我们建立的列表页面 的控制器名称为。 创建控制器文件: controller/notes/ 对应列表展示的控制器。 内容如下: ?php $note = new Model(39。 notes39。 )。 $notes = $notelist_all()。 ? 创建视图文件: view/default/notes/ 对应列表展示的视图。 内容如下: !DOCTYPE html html head meta content=text/html。 charset=UTF8 equiv=contenttype titleCRUD 测试 列表 /title styletype=text/css /style /head body table tr th{$notelable(39。 title39。 )}/th th{$notelable(39。 author39。 )}/th th{$notelable(39。 theme39。 )}/th th{$notelable(39。 postdate39。 )}/th /tr {loop $notes as $n} tr td{$ntitle}/td td{$nauthor}/td td{$nfield_text(39。 theme39。 )}/td td{date(39。 Ymd39。 ,$npostdate)}/td /tr {/loop} tr/tr /table /body /html 对于 theme 字段,因为存储为枚举类型,而枚举的值不是最终要显示的值,所以调用 field_text 方法展示要调用的文本。 浏览器输入: 了。 此时,我们再修改下新增页面,使新增完成后自动跳转到列表页 内容改为: ?php $note =new Model(39。 notes39。 )。 if(Request::post()){ //如果有 post 信息 则认为是新增后的 Form 提交 //单纯的 post 信息判断是不安全的 因为没有具体的字段要求和判断所以可以这样写 $noteload_from_post()。 $notesave()。 Redirect::to(39。 index39。 )。 } ? 通过调用框架的 Redirect::to 方法而不是直接的视图引用,可以有效的屏蔽了F5刷新引起的重复提交问题。 信息详细页面 创建控制器文件: controller/notes/ 对应详细信息展示的控制器。 内容如下: ?php $note = new Model(39。 notes39。 )。 $notefind(get(1))。 ? 创建视图文件: view/default/notes/ 对应详细信息展示的视图。 内容如下: !DOCTYPE html html head meta content=text/html。 charset=UTF8 equiv=contenttype titleCRUD 测试 详细信息 /title style type=text/css /style /head body form action= method=post {$notelable(39。 title39。 )}: {$notetitle}br/ {$notelable(39。 author39。 )}: {$noteauthor}br/ {$notelable(39。 theme39。 )}: {$notefield_text(39。 theme39。 )}br/ {$notelable(39。 postdate39。 )}: {date(39。 Ymd39。 ,$notepostdate)}br/ {$notelable(39。 bepublished39。 )}:{$notefield_text(39。 bepublished39。 )}br/ {$notelable(39。 content39。 )}: br/ {$notecontent}br/ /form /body /html 浏览器输入: 信息删除 修改列表展示页面,让每条信息点击后进入相应的详细页面,并添加删除按钮和编辑按钮。 内容改为: !DOCTYPE html html head meta content=text/html。 charset=UTF8 equiv=contenttype titleCRUD 测试 列表 /title style type=text/css /style /head body table tr th{$notelable(39。 title39。 )}/th th{$notelable(39。 author39。 )}/th th{$notelable(39。 theme39。 )}/th th{$notelable(39。 postdate39。 )}/th th删除 /th th编辑 /th /tr {loop $notes as $n} tr tda href=show{$nid}.html{$ntitle}/a/td td{$nauthor}/td td{$nfield_text(39。 theme39。 )}/td td{date(39。 Ymd39。 ,$npostdate)}/td tda href=javascript:。 onclick=if(confirm(39。 确定要删除吗。 39。 )){ goto(39。 delete{$nid}.html39。 )。 }删除 /a/td tda href=edit{$nid}.html编辑 /a/td /tr {/loop} tr/tr /table /body /html 关于模板标签的说明: 对于视图模板中的 JS 方法,因为同样是要包含大括号 {}” 的,所以在模板解释中会被解析器误认为是 PHP 模板标签,解决的方法是对于 JS 方法 ”{” 之后要紧跟空格或者回车,这样解释器就不 会将其解释成 php 语言。 因为 IE 的某些问题,当要用到 JS 跳转时要调用框架中的 goto 方法,请不要采用传统的 =。 的方式。 这样控制器中的 Redirect::back()方法才会生效。 创建控制器文件: controller/notes/ 对应信息删除的控制器。 内容为: ?php if (isset($_GET[1])){ //指定要操作的模型 id 删除之 $note = new Model(39。 notes39。 )。 $noteid($_GET[1])。 $noteremove()。 } //返回请求前的页面 Redirect::back()。 ? 信息修改页面 创建控制器文件: controller/notes/ 对应每条数据的修改页面。 代码如下: ?php $note = new Model(39。 notes39。 )。 if(get()){ //如果存在 get 提交的信息 $notefind(get(1))。 } ? 创建视图文件: view/default/notes/ 对应修改展示 的视图。 内容如下: !DOCTYPE html html head meta content=text/html。 charset=UTF8equiv=contenttype titleCRUD 测试 /title style type=text/css /style /head body form action=method=post {$notelable(39。 title39。 )}: {$notetext(39。 title39。 )}br/ {$notelable(39。 author39。 )}: {$notetext(39。 author39。 )} {$notelable(39。 theme39。 )}: {$noteselect(39。 theme39。 )}br/ {$notelable(39。 postdate39。 )}: {$notedate(39。 postdate39。 )} {$notelable(39。 bepublished39。 )}:{$notecheckbox(39。 bepublished39。 )}br/ {$notelable(39。 content39。 )}: br/ {$notetexteditor(39。 content39。 )}br/ button type=submit提交 /button {$notehidden(39。 id39。 )}br/ /form /body /html 浏览器输入: , 进行相应的数据修改,点击 提交 ” ,此条信息就会被更新。 你会发现 和 基本一致,有以下两处不同: 的 form 的 action 为空这样默认是当前页面,也就是。 而同样的 的 form 的 action 也为。 也就是说两个页面提交的信息都是通过 处理的。 $notesave()。 既可以新增,也可以更新,框架 是通过判断模型中是否定义了主键 ID来区分的。 比 多了一行代码 {$notehidden(39。 id39。 )}这是隐藏的数 据 的主 键 id 的 提交 信 息。 其实 在 中也 是 可以 加 上{$notehidden(39。 id39。 )}这句的,因为进入视图 之 前 $note 的 id并未被赋值,自然提交请求之后,控制器还是会新增一条数据的。 这样两个视图就变的一模一样。 索性,我们删掉。 然后将 的代码改为: ?php $note = new Model(39。 notes39。 )。 if(Request::post()){ //如果有 post 信息 则为新增后的 Form 提交 $noteload_from_post()。 $notesave()。 Redirect::to(39。 index39。 )。 } Page::view(39。 edit39。 )。 ? Page::view(39。 edit39。 )的意思是说,这个控制器的视图改为同级目录下的。 不过,实际的开发中,两个视图总会有些差别的,所以为了减少代码量和通用性就需要将通用的部分抽离出来作为单独的模板供其他视图引用。 视图模板的引用 读到这里你会发现所有页面并没有导航条,这样只能靠直接输入地址。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。