基本的配置:
数据库设置 我这里使用的是数据库news
apache : rewrite module 打开
我这里是设置好一个虚拟主机指向到www/app,如果是虚拟目录方式,查看相关文档。
新建news表 里面的字段 id,title,content,time,sort
因为一定要操作news这个表,所以先建立news的model
/app/models/news.php
class news extends AppModel{
var $name=''news'';
}
?>
如果没有var $name=''news'';这一行 模型会默认为要处理的表是newss(个人猜想,没试过)
是这个属性来标识使用的数据库 var $useTable=''users''; $name 只是标识model 的name
属性$table 估计是在处理model之间关系的时候用到的吧? 保存此疑惑
然后新建/app/controllers/news_controller.php
class newsController extends AppController{
var $uses=array(''news''); //使用news这个模型
function index(){
$this->set(''lists'',$this->news->findAll())
} //默认
function add($id=0){
if($id){
$this->set(''id'',$id);
$this->news->id=$id;
}
if(!empty($this->data)){
$ret=$this->news->save($this->data[''news'']);
if($ret){
if($id)
$this->flash(''更新成功'',''/news/'');
else
$this->flash(''添加成功'',''/news/'');
}else{
if($id)
$this->flash(''更新失败'',''/news/add/''.$id);
else
$this->flash(''添加失败'',''/news/add'');
}
}
exit();
} //添加/修改
function delete($id){
$this->news->id=$id;
$ret=$this->news->remove();
if($ret)
$this->flash(''删除成功'',

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools