[PHP] Using CodeIgniter to quickly build a blog framework

Source: Internet
Author: User
Tags codeigniter
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);?>


:

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.