CodeIgniter CLI模式简介_php实例

WBOY
Release: 2016-06-07 17:18:52
Original
910 people have browsed it

让我们以Hello World为例,首先创建一个简单的控制器。使用你的文本编辑器,创建一个叫做 tools.php 的文件,并且输入如下代码:

复制代码 代码如下:

class Tools extends CI_Controller {

  public function message($to = 'World')
  {
    echo "Hello {$to}!".PHP_EOL;
  }
}
?>

然后将这个文件保存到你的 application/controllers/ 文件夹里。现在正常情况下你可以通过你网站的 URL 来访问它:

复制代码 代码如下:

example.com/index.php/tools/message/to

除此之外,我们也可以在 Mac/Linux 中打开终端,或者在 Windows 下进入“运行”输入“cmd”,并进入我们的 CodeIgniter 项目的目录。

复制代码 代码如下:

$ cd /path/to/project;
$ php index.php tools message

如果你跟这样一步步运行下来,应该会看到 Hello World!。

复制代码 代码如下:

$ php index.php tools message "John Smith"

至此我们像使用 URL 参数一样给它传递了一个参数。“John Smith”作为一个参数被传递了,并且输出也变成:Hello John Smith!。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!