Cakephp instance-PHP source code

Source: Internet
Author: User
Ec (2); basic configuration: Database settings & nbsp; I am using database news & nbsp; apache: the rewritemodule is opened. Here, a VM is set to point to wwwapp. If it is a virtual directory, view relevant documents. Create the field id, title, content, time, and sort in the news table because you must operate new script ec (2); script

Basic Configuration:
Database settings I use database news here
Open apache: rewrite module
Here I set up a VM pointing to www/app. If it is a virtual directory, view the relevant documentation.

Create the id, title, content, time, and sort fields in the news table.

Because you must operate the news table, create the news model first.
/App/models/news. php

Class news extends AppModel {
Var $ name = ''news '';
}
?>

If there is no var $ name = ''news''; by default, this model indicates that the table to be processed is newss (I guess I have not tried it)
This attribute is used to identify the database var $ useTable = ''users'; $ name is only the name of the model.
Attribute $ table is used to process the relationship between models? Save this question
Create/app/controllers/news_controller.php
Class newsController extends AppController {
Var $ uses = array (''news''); // use the news model.
Function index (){
$ This-> set (''lists', $ this-> news-> findAll ())
} // Default
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 (''updated successfully '',''/news /'');
Else
$ This-> flash (''added successfully '',''/news /'');
} Else {
If ($ id)
$ This-> flash (''update failed', ''/news/add/''. $ id );
Else
$ This-> flash (''add failed', ''/news/add '');
}
}
Exit ();
} // Add/modify
Function delete ($ id ){
$ This-> news-> id = $ id;
$ Ret = $ this-> news-> remove ();
If ($ ret)
$ This-> flash (''deleted successfully '', </

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.