Controllers

A Controller is simply a library file that is named in a way that can be associated with a URI.

Consider this URI:

example.com/index.lc/blog/

In the above example, revIgniter would attempt to find a controller named blog.lc and load it. When a controller's name matches the first segment of a URI, it will be loaded.

# Let's try it:

Let's create a simple controller so you can see it in action. Using your text editor, create a file called blog.lc, and put the following code in it:

# Good Practice

It is good practice, though not mandatory, to load all needed libraries, models, helpers and plugins in a handler named after the controller itself.

This handler, if present, is called first and automatically by the front controller. So, this is a good place to load required libraries, helpers, plugins, models, a database etc.

Let's say your controller is called "blog.lc", then your code would look like this:

<?rev # PUT YOUR HANDLER NAMES INTO THE GLOBAL gControllerHandlers AS A COMMA SEPARATED LIST put "index,blog" into gControllerHandlers command blog # LOAD REQUIRED LIBRARIES, MODELS, HELPERS, PLUGINS end blog command index # REMEMBER TO PUT ALL THE VARIABLES TO BE MERGED WITH VIEWS INTO THE ARRAY VARIABLE gData -- do something here end index --| END OF blog.lc --| Location: ./system/application/controllers/blog.lc

Note: Name conflicts

Be careful not to name the sub-folder the same as that of an existing controller, as the controller will take precedence and the subfolder route will be ignored.

For instance if you have a sub-folder called "feast" and a controller called "feast.lc" then you need to rename the folder or controller in order not to confuse the routing.