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 '', </