summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/general/cli.rst
diff options
context:
space:
mode:
authordchill42 <dchill42@gmail.com>2012-07-23 16:53:47 +0200
committerdchill42 <dchill42@gmail.com>2012-07-23 16:53:47 +0200
commitc5079de78e5141330c07e990811ef15e998e95aa (patch)
tree0f39d8c4fc7614246fc185810bfeaa7fad88a33a /user_guide_src/source/general/cli.rst
parent00fcb545109d4e61bc14e403ec828749c34a54b3 (diff)
parentede49ba66b127535f3430e20aac72ceed2c4611a (diff)
Merge branch develop of github.com:/EllisLab/CodeIgniter into session
Diffstat (limited to 'user_guide_src/source/general/cli.rst')
-rw-r--r--user_guide_src/source/general/cli.rst78
1 files changed, 78 insertions, 0 deletions
diff --git a/user_guide_src/source/general/cli.rst b/user_guide_src/source/general/cli.rst
new file mode 100644
index 000000000..7dc1ca319
--- /dev/null
+++ b/user_guide_src/source/general/cli.rst
@@ -0,0 +1,78 @@
+###################
+Running via the CLI
+###################
+
+As well as calling an applications :doc:`Controllers <./controllers>`
+via the URL in a browser they can also be loaded via the command-line
+interface (CLI).
+
+.. contents:: Page Contents
+
+What is the CLI?
+================
+
+The command-line interface is a text-based method of interacting with
+computers. For more information, check the `Wikipedia
+article <http://en.wikipedia.org/wiki/Command-line_interface>`_.
+
+Why run via the command-line?
+=============================
+
+There are many reasons for running CodeIgniter from the command-line,
+but they are not always obvious.
+
+- Run your cron-jobs without needing to use wget or curl
+- Make your cron-jobs inaccessible from being loaded in the URL by
+ checking for ``$this->input->is_cli_request()``
+- Make interactive "tasks" that can do things like set permissions,
+ prune cache folders, run backups, etc.
+- Integrate with other applications in other languages. For example, a
+ random C++ script could call one command and run code in your models!
+
+Let's try it: Hello World!
+==========================
+
+Let's create a simple controller so you can see it in action. Using your
+text editor, create a file called tools.php, and put the following code
+in it::
+
+ <?php
+ class Tools extends CI_Controller {
+
+ public function message($to = 'World')
+ {
+ echo "Hello {$to}!".PHP_EOL;
+ }
+ }
+ ?>
+
+Then save the file to your application/controllers/ folder.
+
+Now normally you would visit the your site using a URL similar to this::
+
+ example.com/index.php/tools/message/to
+
+Instead, we are going to open Terminal in Mac/Lunix or go to Run > "cmd"
+in Windows and navigate to our CodeIgniter project.
+
+.. code-block:: bash
+
+ $ cd /path/to/project;
+ $ php index.php tools message
+
+If you did it right, you should see Hello World!.
+
+.. code-block:: bash
+
+ $ php index.php tools message "John Smith"
+
+Here we are passing it a argument in the same way that URL parameters
+work. "John Smith" is passed as a argument and output is: Hello John
+Smith!.
+
+That's it!
+==========
+
+That, in a nutshell, is all there is to know about controllers on the
+command line. Remember that this is just a normal controller, so routing
+and _remap works fine.