麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 網(wǎng)站 > 建站經(jīng)驗 > 正文

基于CakePHP實現(xiàn)的簡單博客系統(tǒng)實例

2024-04-25 20:37:51
字體:
供稿:網(wǎng)友

本文實例講述了基于CakePHP實現(xiàn)的簡單博客系統(tǒng)。分享給大家供大家參考。具體實現(xiàn)方法如下:

PostsController.php文件:

<?php

class 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文件:

<?php

class 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://www.opensource.org/licenses/mit-license.php)

*/

/**

* Here, we are connecting '/' (base path) to controller called 'Pages',

* its action called 'display', and we pass a param to select the view file

* to use (in this case, /app/View/Pages/home.ctp)...

*/

//Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));

Router::connect('/', array('controller' => 'posts', 'action' => 'index'));

/**

* ...and connect the rest of 'Pages' controller's urls.

*/

Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));

/**

* Load all plugin routes. See the CakePlugin documentation on

* how to customize the loading of plugin routes.

*/

CakePlugin::routes();

/**

* Load the CakePHP default routes. Only remove this if you do not want to use

* the built-in default routes.

*/

require CAKE . 'Config' . DS . 'routes.php';

blog.sql文件如下:

 

-- MySQL dump 10.13 Distrib 5.5.19, for Win64 (x86)

--

-- Host: localhost Database: facebook

-- ------------------------------------------------------

-- Server version 5.5.19

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;

/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;

/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;

/*!40101 SET NAMES utf8 */;

/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;

/*!40103 SET TIME_ZONE='+00:00' */;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;

/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;

/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;

/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--

-- Table structure for table `posts`

--

DROP TABLE IF EXISTS `posts`;

/*!40101 SET @saved_cs_client = @@character_set_client */;

/*!40101 SET character_set_client = utf8 */;

CREATE TABLE `posts` (

`id` int(10) unsigned NOT NULL AUTO_INCREMENT,

`title` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,

`body` text COLLATE utf8_unicode_ci,

`created` datetime DEFAULT NULL,

`modified` datetime DEFAULT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

/*!40101 SET character_set_client = @saved_cs_client */;

--

-- Dumping data for table `posts`

--

LOCK TABLES `posts` WRITE;

/*!40000 ALTER TABLE `posts` DISABLE KEYS */;

INSERT INTO `posts` VALUES (1,'The title','This is the post body.','2012-11-01 15:43:41',NULL),(2,'A title once again','And the post body follows.','2012-11-01 15:43:41',NULL),(3,'Title strikes back','This is really exciting! Not.','2012-11-01 15:43:41',NULL),(4,'ggjjkhkhhk','7777777777777777777777777rn777777777777777777777777','2012-11-01 20:16:28','2012-11-01 20:16:28');

/*!40000 ALTER TABLE `posts` ENABLE KEYS */;

UNLOCK TABLES;

--

-- Table structure for table `schema_migrations`

--

DROP TABLE IF EXISTS `schema_migrations`;

/*!40101 SET @saved_cs_client = @@character_set_client */;

/*!40101 SET character_set_client = utf8 */;

CREATE TABLE `schema_migrations` (

`version` varchar(255) COLLATE utf8_unicode_ci NOT NULL,

UNIQUE KEY `unique_schema_migrations` (`version`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

/*!40101 SET character_set_client = @saved_cs_client */;

--

-- Dumping data for table `schema_migrations`

--

LOCK TABLES `schema_migrations` WRITE;

/*!40000 ALTER TABLE `schema_migrations` DISABLE KEYS */;

INSERT INTO `schema_migrations` VALUES ('20121013024711'),('20121013030850');

/*!40000 ALTER TABLE `schema_migrations` ENABLE KEYS */;

UNLOCK TABLES;

/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;

/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;

/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;

/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2012-11-01 16:41:46

希望本文所述對大家的php程序設計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 黄色毛片一级视频 | 久久精品成人影院 | 欧美 国产 亚洲 卡通 综合 | 精品一区二区在线观看视频 | 久久国产精品一区 | 亚洲精品一区二区三区大胸 | 97黄色网| 日日摸夜夜添夜夜添牛牛 | 国产午夜精品久久久久婷 | 99精品视频在线 | 欧美成人午夜精品久久久 | 色淫影院| 国产精品久久999 | 国产一级一级片 | 久久91亚洲人成电影网站 | 福利在线播放 | 欧美一级一区二区三区 | 成人av一区二区免费播放 | 巨根插入 | 91成人一区二区三区 | avav在线播放 | 精品中文字幕视频 | 亚洲精品久久久久久下一站 | 在线a毛片免费视频观看 | 国产精品一区二区三区在线播放 | 久久亚洲精品国产一区 | 超碰99在线观看 | 免费在线中文字幕 | 婷婷中文字幕一区二区三区 | 毛片免费一区二区三区 | 久久亚洲激情 | 牛牛碰在线 | 黄色av.com | 久久国产精品无码网站 | 国产精品久久久久久久久久久天堂 | 久久99综合 | 国产成人精品免费视频大全最热 | av免费入口 | 深夜福利久久久 | 男女羞羞视频 | 国产99久久久久久免费看农村 |