sayou
sayou

Reputation: 913

How to generate / create my own PHP CLI command

On most of PHP frameworks, they have our CLI PHP command to do something (Create controller, create database ... etc).

I have a framework created from scratch, for that, I want to create my own CLI PHP command to easier my work.

I search a lot for this point, but unfortunately no information I get it.

Is there any solution? or method to do it?

Upvotes: 2

Views: 2105

Answers (1)

sayou
sayou

Reputation: 913

After answers of users,

You can create your own CLI Command by creating a PHP script and call it with this command : php nameofyouscript.php or you can create a file without extension and add #!/usr/bin/env php on the first line and write you php code, to call it you can use this command : php nameofyourscript

To receive information from user you can add this line to you php code :

$line = readline("Write something: ");
echo $line

Finally, if you want to create a command like this php nameofyouscript something you can add this on you php code :

echo $argv[1]; //to get 'something'

PS: If you have any other information please edit this comment or write your own.

I hope that can help.

Upvotes: 2

Related Questions