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.
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 = 'new'; by default, 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 only indicates 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', '/news /');
Else
$ This-> flash ('deletion failed', '/news /');
Exit ();
} // Delete
Function view ($ id ){
$ This-> news-> id = $ id;
$ This-> set ('news', $ this-> news-> find ());
}
}
?>
In this way, you can access
Http: // 127.0.0.1/app/news/(same as http: // 127.0.0.1/app/news/index)
Http: // 127.0.0.1/app/news/add
Http: // 127.0.0.1/app/news/view
Http: // 127.0.0.1/app/news/delete
However, the system will prompt you to miss view add. thtml view. thtml delete. thtml index. thtml
Because cake outputs the view name by default. your current action name. if you want it to output $ this-> render ('test'); that is, test. thtml
All these thml files are in the/app/views/controller/Directory. the current controller is news.
Therefore, files are stored in the/app/views/news/directory.
Add. thtml:
FormTag ('New/title'. $ id);?>
Input ('New/title');?>
Textarea ('New/content');?>
Submit ('submit ');?>
Index.html:
News:
For ($ I = 0; $ I ?>
Title:
}
?>
View. thtml:
Title:
Content: