Let us take Hello World as an example and first create a simple controller. Using your text editor, create a file called tools.php and enter the following code:
Copy code The code is as follows:
class Tools extends CI_Controller {
public function message($to = 'World')
{
echo "Hello {$to}!".PHP_EOL;
}
}
?>
Then save this file to your application/controllers/ folder. Now normally you can access it via your website’s URL:
Copy code The code is as follows:
example.com/index.php/tools/message/to
In addition, we can also open a terminal in Mac/Linux, or enter "Run" and enter "cmd" under Windows, and enter the directory of our CodeIgniter project.
Copy code The code is as follows:
$ cd /path/to/project;
$ php index.php tools message
If you follow this step by step, you should see Hello World!.
Copy code The code is as follows:
$ php index.php tools message "John Smith"
At this point we pass it a parameter just like a URL parameter. "John Smith" is passed as a parameter, and the output becomes: Hello John Smith!.
http://www.bkjia.com/PHPjc/825344.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825344.htmlTechArticleLet us take Hello World as an example and first create a simple controller. Using your text editor, create a file called tools.php and enter the following code: Copy code...