CodeIgniter 中使用file() 或file_get_contents()等函数

在CodeIgniter(以下简称CI)中加载文件有两种方式,一是使用PHP的原生函数file() 或file_get_contents()等,二是使用CI的helper类。

  • PHP 的file() 或file_get_contents()方式

在CI中使用file() 或file_get_contents()等函数时,所用相对路径是从CI的index.php引导文件开始计算的。如:在未改变CI原有结构的前提下,controllers中使用file_get_contents()函数加载views中的test.php文件时,写法是file_get_contents(“application/views/test.php”)。

  • CI的helper类使用方式



Working with RESTful Services in CodeIgniter

Part 1 – Creating a RESTful API

Step 1: Setting up the Demo

Firstly you need to download the codeigniter-restserver code from GitHub and extract it and move the code to your server.

When you open the folder, you will see an entire CodeIgniter install, which is there to power the demo. This allows people to have a play with the REST demo before integrating with your existing application.

Open up “application/config/config.php” and set the base_url to get links working. This base_url will be different for everyone and depends entirely on where you uploaded your files.

Step 2: The URLs

With the files extracted and the base_url set, we are ready to load up our RESTful CodeIgniter installation, and have a look at the demo supplied with it. Browse the base URL, which by default is: 继续阅读“Working with RESTful Services in CodeIgniter”

KNDB Session For CodeIgniter

KNDB Session

Native Session makes good use of PHP’s native session handling abilities, but it does not allow the use of a database for session storage. KNDB Session (which stands for Kirilisa’s Native Database session) is a hybrid which is based upon Native Session (with some notable changes) but allows use of databases via PHP’s ability to store sessions in a DB. 继续阅读“KNDB Session For CodeIgniter”

Replacing CodeIgniter’s session by PHP’s Native Session

For last 8 months, I have been working on a web application. We are developing the application based onCodeIgniter framework. In our project there are normal web version and mobile view version. Some days ago we noticed that, some people can’t login their account via mobile version though there username & password are correct. After debugging and digging the problem we found that in iPod Touch 2G/3GS Safari browser, this problem is happening.

We are using CodeIgniter’s built in session library and that is different than normal PHP’s session. We found that for each visit of the user, the server can’t track the session and regenerating new session id each time. Very weird situation for us. As we coded all over based on CodeIginter’s session library’s function so its not optimal solution for us to remove the codes and use PHP’s native session. Because in that case there is high possibility to generate new bugs. After lots of searching in the net at last we found a wrapper class for CodeIgniter. 继续阅读“Replacing CodeIgniter’s session by PHP’s Native Session”