[PHP] framework Tutorial: simple use of the CodeIgniter framework

Source: Internet
Author: User
Tags php foreach
CodeIgniter is a small but powerful PHP framework. You can download the framework from the official website. The following describes the simple operations in CodeIgniter. 1. Create and set the Controller. 1. Create the blog. php file in the Controller Directory: 2. The code in blog. php is as follows :? PhpclassBlogextendsCI_C

CodeIgniter is a small but powerful PHP framework. You can download the framework from the official website. The following describes the simple operations in CodeIgniter. 1. Create and set the Controller. 1. Create the blog. php file in the Controller Directory: 2. The code in blog. php is as follows :? Phpclass Blog extends CI_C

CodeIgniter is a small but powerful PHP framework.

You can download the framework from the official website.


The following describes the simple operations in CodeIgniter.

1. Create and Set Controller

1. Create the blog. php file in the Controller directory:

2. The code in blog. php is as follows:

 

3. Enter the address. Note: Do not add a suffix. Browsing page:

The data shown here is actually the data in the index function, because the index method is called by default.

Modify the Code as follows:

 

After modifying the access path, you will find that the input or no input/index is the access index method. However, if you enter other values, you will access the content of other functions:


In CodeIgniter, many settings have been configured, And we can modify them directly.

For example, to modify the default access page, there is a route. php In applications/config:

$route['default_controller'] = "welcome";$route['404_override'] = '';

Change default_controller to blog, and enter index. php In the taskbar. The output is HelloWorld, that is, the blog. php page is accessed:


Ii. Create and set a View

1. Create a file blog_view.php in the views directory:

2. Return to blog. php In the controller folder and load the blog_view page with simple echo to realize the true value of its controller:

 load->view('blog_view');}}?>

3. Enter the URL on the page to access the website. The page has changed:

3. data transmission between Controller and View

1. modify the code in Controller as follows:

 load->view('blog_view',$data);}}?>



2. modify the code in the View as follows. Note that instead of using the data array, you can call data directly:

<?php echo $myName.$head?>I am 
 

3. browse the website:


PS: In CodeIgniter Equivalent


Use php to output an array.

1. Add an array with the following changes in the Controller:

 load->view('blog_view',$data);}}?>
2. Modify the display array in View as follows:

<?php echo $myName.$head?>I am 
 
 
 

3. Refresh the page and the page will be displayed normally:

If you are not used to endforeach, you can also use the standard PHP language:

<?php echo $myName.$head?>I am 
 
 
 

Of course, you can also rewrite the constructor method:

 load->view('blog_view',$data);}}?>

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.