For details about how to get started with CodeIgniter, refer to this article: [PHP] framework Tutorial: the easy-to-use platform of CodeIgniter framework is SAE: [SAE] Free Server: register Sina ECs SAE and use MySQL In BAE: [PHP] How to Use PHP on Baidu (BAE) and Sina (SAE) Cloud platforms to connect to MySQL and return results
For details about how to get started with CodeIgniter, refer to this article: [PHP] framework Tutorial: the easy-to-use platform of CodeIgniter framework is SAE: [SAE] Free Server: register Sina ECs SAE and use MySQL In BAE: [PHP] How to Use PHP on Baidu (BAE) and Sina (SAE) Cloud platforms to connect to MySQL and return results
Related links:
For more information about CodeIgniter, see [PHP] framework Tutorial: simple use of CodeIgniter framework.
The platform used is SAE: [SAE] Free server: Sina cloud server SAE registration and use
MySQL usage in BAE: [PHP] how to connect to MySQL on Baidu (BAE) and Sina (SAE) cloud platform using PHP and return result data
1. The first part is the Controller part. Blog. php acts as the Controller, that is, the Controller:
Load-> helper ('url'); $ this-> load-> helper ('form');} function index () {// set relevant data for the page to be redirected $ data ['title'] = "My Blog title"; $ data ['heading'] = "My Blog heading "; $ data ['todo '] = array ('hat', 'Sleep', 'call '); // connect to the database and return the query result $ SQL = "SELECT * FROM 'entries' LIMIT 0, 30"; // initialize the MySQL database $ mysql = new SaeMysql (); $ sqlData = $ mysql-> getData ($ SQL); // pass the database results to $ data ['query'] = $ sqlData; // use the variable $ data to input data to the target webpage $ this-> load-> view ('blo G_view ', $ data);} function comments () {// set relevant data for the page to be redirected $ data ['title'] = "My Comment title "; $ data ['heading'] = "My Comment heading "; // connect to the database and return the query result $ SQL = "SELECT * FROM 'comments' where 'entry _ id' = ". $ this-> uri-> segment (3); // initialize the MySQL database $ mysql = new SaeMysql (); $ sqlData = $ mysql-> getData ($ SQL ); // pass the database results to $ data ['query'] = $ sqlData; // use the variable $ data to input data to the target webpage $ this-> load-> view ('comment _ view', $ data);} function comment _ Insert () {// INSERT the comment data submitted by POST to MySQL $ SQL = "insert INTO 'comments' ('entry _ id', 'body', 'author ') VALUES ('". $ _ POST ['entry _ id']. "','". $ _ POST ['body']. "','". $ _ POST ['author']. "');"; // initialize the MySQL database $ mysql = new SaeMysql (); $ mysql-> runSql ($ SQL); redirect ('blog/comments /'. $ _ POST ['entry _ id']) ;}}?>
2. View is the View part. blog_view is the View of the blog list:
<? Php echo $ title?>
$ Value):?>
Comment_view is the content of the comment list:
<? Php echo $ title?>
0):/* Ensure that data is returned */?>
$ Value):?>
Uri-> segment (3);?>
: