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”