CodeIgniter CLI Mode Introduction _php instance

Source: Internet
Author: User
Tags codeigniter
Let's take the example of Hello World and first create a simple controller. Using your text editor, create a file called tools.php and enter the following code:

Copy the Code code as follows:
Class Tools extends Ci_controller {

Public Function message ($to = "World")
{
echo "Hello {$to}!". Php_eol;
}
}
?>

Then save the file in your application/controllers/folder. Now normally you can access it through the URL of your website:

Copy the Code code as follows:
Example.com/index.php/tools/message/to

In addition, we can also open the terminal in Mac/linux, or enter "run" input "cmd" under Windows, and enter the directory of our CodeIgniter project.

Copy the Code code as follows:
$ cd/path/to/project;
$ PHP index.php Tools Message

If you run down with such a step, you should see Hello world!.

Copy the Code code as follows:
$ PHP index.php Tools Message "John Smith"

At this point we pass a parameter to it as if it were a URL parameter. "John Smith" was passed as a parameter, and the output became: Hello John smith!.

  • 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.