时间:2021-05-25
本文实例讲述了基于CakePHP实现的简单博客系统。分享给大家供大家参考。具体实现方法如下:
PostsController.php文件:
<?phpclass PostsController extends AppController { public $helpers = array('Html', 'Form', 'Session'); public $components = array('Session'); public function index() { $this->set('posts', $this->Post->find('all')); } public function view($id=null) { $this->Post->id=$id; $this->set('post',$this->Post->read()); } public function add() { if($this->request->is("post")) { $this->Post->create(); if($this->Post->save($this->request->data)) { $this->Session->setFlash("your post added!"); $this->redirect(array('action'=>'index')); } else { $this->Session->setFlash("unable to create post!"); } } } public function edit($id=null) { $this->Post->id=$id; if($this->request->is('get')) { $this->request->data = $this->Post->read(); } else { if($this->Post->save($this->request->data)) { $this->Session->setFlash('Your post has been updated.'); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash('Unable to update your post.'); } } } public function delete($id) { if ($this->request->is('get')) { throw new MethodNotAllowedException(); } if ($this->Post->delete($id)) { $this->Session->setFlash('The post with id: ' . $id . ' has been deleted.'); $this->redirect(array('action' => 'index')); } }}?>Post.php文件:
<?phpclass Post extends AppModel {public $validate = array( 'title' => array( 'rule' => 'notEmpty'), 'body' => array( 'rule' => 'notEmpty'));}?>routes.php文件:
<?php/** * Routes configuration * * In this file, you set up routes to your controllers and their actions. * Routes are very important mechanism that allows you to freely connect * different urls to chosen controllers and their actions (functions). * * PHP 5 * * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project * @package app.Config * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://pleted on 2012-11-01 16:41:46希望本文所述对大家的php程序设计有所帮助。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了基于jsp+servlet实现的简单博客系统。分享给大家供大家参考。具体如下:没有用框架写的小博客,代码大量重复。个人感觉重复代码对于新手还是有好
本文实例讲述了CakePHP框架Model函数定义方法。分享给大家供大家参考,具体如下:在CakePHP中,MVC的架构是清晰的,而在实际做项目中,我发现仍然有
本文实例为大家分享了python个性签名设计的具体代码,供大家参考,具体内容如下参考博客:PythonGUITkinter简单实现个性签名设计参考博客:pyth
本文实例讲述了JavaScript基于DOM操作实现简单的数学运算功能。分享给大家供大家参考,具体如下:简单的DOM操作-实现简单的运算window.onloa
本文实例讲述了基于JS实现简单的样式切换效果。分享给大家供大家参考。具体如下:这是一款基于JS实现简单的样式切换代码,自由切换CSS样式,很多大网站现在正在用,