Where does the CI framework start? How to start learning the CI framework and initial CI settings

Source: Internet
Author: User
Many friends do not know where to start learning the CI framework. it is not difficult to learn a new framework. As long as you study it carefully, it is very easy to study and explore it! Many friends do not know where to start learning the CI framework. it is not difficult to learn a new framework. As long as you study it carefully, it is very easy to study and explore it!

Overview and basic configuration parameters

Configure CI:

Application/config. php: 14 configure your domain name

Application/config/database. php: 40 configure the relevant parameters of your database

Configure htaccess-based redirection

RewriteEngine on

RewriteCond $1! ^ (Index ?. Php | images | robots ?. Txt)

RewriteRule ^ (. *) $/index. php/$1 [L]

Any HTTP requests except index.php, images, and robots.txt are treated as requests to the index. php file.

Add URL suffix

Application/config. php: 57 configure $ config ['url _ suffix '] = pai.html ";

Access is allowed after configuration with or without a suffix

Access control class using the get method of index. php

In application/config. php:

$ Config ['enable _ query_strings '] = true;

$ Config ['Controller _ trigger'] = 'C ';

$ Config ['function _ trigger'] = 'M ';

Access Method: index. php? C = controller & m = method

Custom simple control class

Class Blog extends Controller {

Function index ()

{

Echo 'Hello World! ';

}

}

?>

Controller access and parameter transfer

Www.your-site.com/classname/functionname/para1/para2

Www.your-site.com/classname/functionname/para1/para2.html

Define default controller

Configure $ route ['default _ controller'] = 'classname' in application/config/routes. php ';

Predefined methods in the controller

_ Remap () method: no matter which method is called in the uri, the request will be redirected to this method.

The overwritten method names will be passed in as parameters, and the parameters will be sorted in order

_ Output () method: the output result of any function in the class will be handed over to the client browser after processing the function.

Function _ output ($ output) {echo $ output };

View

Load a specific view in the controller: $ this-> load-> view ('name ');

Name is the file name of the view file, excluding the. php suffix.

$ This-> load-> view ('folder _ name/file_name ');

Transmit dynamic data to the view:

$ This-> load-> view ('blogview', $ data, $ data2 );

$ Data can be an array or an object (example of a class );

View using PHP syntax

Model

Introduce Model: $ this-> load-> model ('Model _ name ');

Once introduced: you can use the functions: $ this-> Model_name-> function ();

You can also specify the model name:

$ This-> load-> model ('Model _ name', 'fubar ');



$ This-> fubar-> function ();

After the model is loaded, database connections will not be automatically established and will only be called.

To establish a database connection when a model is introduced, you need $ this-> load-> Model ('Model _ name', ", TRUE );

Assistant

The assistant contains a series of functions that complete specific functions. after importing a specific assistant, you can use the functions provided by the CI assistant just like using the built-in php functions.

$ This-> load-> helper ('name ');

Load multiple assistants: $ this-> load-> helper (array ('helper1', 'helper2', 'helper3 '));

Automatically load a helper: configure the application/config/autoload. php file and add the plug-in to the automatically loaded array (autoload array ).

Plug-ins

Like helper, the plug-in only provides a single function, while helper provides a series of functions

$ This-> load-> plugin ('name ');

For example, $ this-> load-> plugin ('captcha '); loads captcha_pi.php

$ This-> load-> plugin (array ('inin1', 'inin2', 'plugin3 '));

Automatic loading: application/config/autoload. php

CI Library

Load the library: $ this-> load-> library ('class name ');

Create your own database, which must be capitalized,

Reference the CI resource: get_instance () function in the custom library

$ CI = & get_instance ();



$ CI-> load-> helper ('URL ');

$ CI-> load-> library ('session ');

$ CI-> config-> item ('base _ url ');

Use CI to manage databases

Application/config/routes. php: $ route ['scaffolding _ trigger'] = "zhougege ";

Add $ this-> load-> scaffolding ('Marry _ user_profile ') to your controller constructor ');

You can access http: // localhost/yourclass/zhougege to manage your database.

CI error handling

Index. php displays all errors by default: error_reporting (E_ALL );

Show_error ('message') function. the error information is displayed by application/errors/error_general.php as the template.

Show_404 ('page') function. Press application/errors/error_404.php as the template to display a 404 error.

The log_message ('level', 'message') function writes error messages to error logs. You must provide error levels (three types) in the first parameter to indicate the levels of errors (debug, error, info). The second parameter is the error information.

Note: to generate an error log file, you must open the "log_errors" option in the application/config. php file and ensure that the "logs" folder is writable. In addition, you can set "threshold" for logs ". For example, you can record Error Messages, but not the other two types.

CI cache:

Open the cache in the controller: $ this-> output-> cache (n); n indicates the cache time, in seconds.

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.