: This article mainly introduces the usage of the phpCI framework. if you are interested in the PHP Tutorial, please refer to it. The CI framework has been frequently used recently. here we will focus on background development. we will focus on a summary of the Model and Controller layers:
1. when it comes to interactive databases, we first add the connection information of the database we need to use in database. php, as shown in the following example (we need to complete the relevant information ):
$ Db ['name'] ['hostname'] = '';
$ Db ['name'] ['username'] = '';
$ Db ['name'] ['password'] = '';
$ Db ['name'] ['database'] = '';
$ Db ['name'] ['dbdriver '] = '';
$ Db ['name'] ['dbprefix'] = '';
$ Db ['name'] ['pconnect '] = FALSE;
$ Db ['name'] ['DB _ debug'] = FALSE;
$ Db ['name'] ['cache _ on'] = FALSE;
$ Db ['name'] ['cachedir'] = '';
$ Db ['name'] ['char _ set'] = '';
$ Db ['name'] ['dbcollat'] = '';
$ Db ['name'] ['swap _ pre'] = '';
$ Db ['name'] ['autoinit '] = TRUE;
$ Db ['name'] ['stricton '] = FALSE;
2. in our Model: $ this-> db = $ this-> load-> database ("name", TRUE ); in this way, we can use the database we configured in the Model (multiple databases can be referenced ).
It can be referenced in function _ construct () or in a specific method;
3. then we can write functions to implement specific SQL functions. The following provides a simple function connection Database template:
Function funcname ($ canshu1, $ canshu2)
{
$ SQL = "update tablename
Set column (column name) = column + 1
Where game_id =?
And qudao_order>? ";
$ Binds = array (
$ Canshu1,
$ Canshu2
);
$ Is_true = $ this-> db-> query ($ SQL, $ binds); // this is the SQL format.
If ($ is_true ){
Return true;
} Else return false;
}
4. Reference Model in Controller, $ this-> load-> model ('modelname'); you can use the method in model;
5. use model functions in Controller functions $ return = $ this-> modelname-> funcname ($ canshu1, $ canshu2 );
Then we continue to complete our functions.
The above is a direct access method. we can use PDO to access the database.
Put the connection information of our database in Array, which makes it easier to add and then use PDO for access. of course, you need to add the PDO module in php. See the following for reference:
Public $ db_info = array (
'Test' => array (
'Host' => '2017. 0.0.1 ',
'Dbname' => 'test ',
'Username' => 'root ',
'Password' => 'jxdisno1'
)
'Other' => array (
)
);
Public function getconn ($ db)
{
$ Conn = new PDO ("mysql: host = ". $ this-> db_info [$ db] ['host']. '; dbname = '. $ this-> db_info [$ db] ['dbname'], $ this-> db_info [$ db] ['username'], $ this-> db_info [$ db] ['password']);
Return $ conn;
}
The interaction between the Controller and the View layer is not described here, and will be described separately next time. Let's share some of your experiences.
Currently, when using the MVC framework, it is found that, unless there are complex requirements on SQL, the interaction on the Model and Controller layers becomes simpler and more repetitive, at the front-end, there are more and more tasks,
The data interaction between the View and Controller layers is more diversified, and the front-end needs to process more data than before.
Therefore, the background is not higher than the front-end development. we will become more and more aware of the importance and complexity of front-end development.
Of course, I do not know much about it, and I do not have enough experience. I hope you can share this with us.
The above is a small summary of the use of the php CI framework, including some content, and hope to help those who are interested in the PHP Tutorial.