Phpci basic application development

Source: Internet
Author: User
: This article mainly introduces the basic application of phpci development. For more information about PHP tutorials, see. 1. set up the ci project, http://codeigniter.org.cn/p to download a ci framework on this website, I am currently using 3.0.0. (Help instructions are provided on the website)

2. delete unnecessary files and directories, such:

R & D is mainly in the application directory, and the system directory is the framework directory. The public directory is created by me and is mainly used for js, css, and images.

3. ci basic configuration, css \ js \ images reference, added a system variable in config. php under the config Directory:

$ Config ['asset _ url'] = "http: // 127.0.0.1/"; // access address of js \ css \ images, differentiated

4. set the default access controller, config/routes. php:

$ Route ['default _ controller'] = 'home'; // default controller name $ route ['192 _ override'] = ''; // 404 $ route ['translate _ uri_dashes '] = TRUE;

5. the controller inherits the methods of the base class. Create a MY_Controller.php file in the core directory (you can download it directly from the blog). The code is as follows:

 Uri-> segment (1) get controller name * $ this-> uri-> segment (2) get action name */class AdminBase extends MY_Controller {public $ skip_filter = array (); // array ('Controller _ name', 'Controller _ name') public $ data = array (); function _ construct () {parent :: __construct (); $ this-> data ['infos '] = array (); // variable passed to the foreground page, the variable is named infos $ this-> load-> library ('Session'); $ this-> load-> library ('layout '); // load if (! Is_login () {redirect ('login/index'); // If you have not logged on to the logon page}/** filter method */public function is_login () {if (in_array ($ this-> uri-> segment (1), $ skip_filter) {return true ;} // controller if ($ this-> session-> has_userdata ('User _ id') that does not need to be logged on {// method, determine whether the user is blocked return true;} else {return false; }}/ *** the controller base class method is described above, just inherit HomeBase **/class HomeBase extends MY_Controller {function _ construct () {parent ::__ construct ();}}

6.1 how to reference the Layout template: create a new Layout. php file under the libraries Directory, and download the file under the blog at least. Note:

$ This-> layout = 'layouts/'. $ layout; // 'layouts/' layouts is the views directory, which is mainly used to store templates

6.2layouts mainly refers to the template for placing the entire page:

The following dashes start with a local code. the layout of the entire page begins with a letter. (features: You do not need to call public files repeatedly to modify public files, clear layout ).

The index. php code is as follows:

 

Load-> view ('layouts/_ top_menu '); // start with the header $ this-> load-> view ('layouts/_ left_menu '); // start from the menu on the left?>

// $ This-> load-> view ('info/Index', $ this-> data ); // The template file $ this-> layout-> view ('info/Index', $ this-> data) is not used ); // write the reference template $ this-> data is the variables that can be uploaded to the view layer, for example: $ this-> data = array ('infos '=> array (), 'Page' => 1) indicates that there are two variables: infos and page.

The above introduces the basic application of php ci development, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

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.