Running revIgniter via the CLI

Controllers can also be loaded via the command-line interface (CLI). That's handy for:

Hello World Example

Following is a simple example demonstrating revIgniter's CLI capability. Create a file called hello.lc, and put the following code in it:

<?lc

put "index,hello,message" into gControllerHandlers


command hello
  # MAKE SURE THAT THE CONTROLLER IS ONLY ACCESSIBLE VIA COMMAND LINE
  if $_SERVER["PATH_TRANSLATED"] <> empty then
    put "This script can only be accessed via the command line."
    exit to top
  end if
end hello


command index
  put "Hello World!" & return
end index


command message
  put rigFetchSegment(3) into tTo
  
  if tTo is FALSE then
    put "Jane Doe" into tTo
  end if
  
  put "Hello" && tTo & "!" & return
end message

Save the file to your application/controllers/ folder. Normally you would load the controller using a URL similar to this:

example.com/index.lc/hello

Instead, we are going to open the terminal and navigate to our revIgniter project.

$ cd /path/to/project
$ path/to/LiveCode/executable index.lc hello

If you did it right, the terminal should print "Hello World!".

Note:  To avoid always having to write the complete path to the LC server executable, consider adding the location of LC server to the PATH environment variable.

Now add a third argument "message" to the command like:

$ path/to/LiveCode/executable index.lc hello message

This calls the "message" handler instead of the default handler (index). The output should be "Hello Jane Doe!"

You could replace "Jane Doe" by adding your name in a fourth argument like:

$ path/to/LiveCode/executable index.lc hello message "Your Name"

This should print "Hello Your Name!"

That's it!

That, in a nutshell, is all there is to know about controllers on the command line.