This article mainly introduces the CodeIgniterCLI mode. if you need it, refer to the CI framework.
Let's take Hello World as an example. First, create a simple controller. Use your text editor to create a file named tools. php and enter the following code:
The code is as follows:
Class Tools extends CI_Controller {
Public function message ($ to = 'world ')
{
Echo "Hello {$ }! ". PHP_EOL;
}
}
?>
Save the file to your application/controllers/folder. Under normal circumstances, you can access it through the URL of your website:
The code is as follows:
Example.com/index.php/tools/message/to
In addition, you can open the terminal in Mac/Linux, enter "run" in Windows, enter "cmd", and enter the directory of our CodeIgniter project.
The code is as follows:
$ Cd/path/to/project;
$ Php index. php tools message
If you run it step by step, you will see Hello World !.
The code is as follows:
$ Php index. php tools message "John Smith"
So far, we have passed a parameter to the URL parameter. "John Smith" is passed as a parameter, and the output is also: Hello John Smith !.