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