Controllers¶
Controllers are the heart of your application, as they determine how HTTP requests should be handled.
Page Contents
What is a Controller?¶
A Controller is simply a class file that is named in a way that can be associated with a URI.
Consider this URI:
example.com/index.php/blog/
In the above example, CodeIgniter would attempt to find a controller named Blog.php and load it.
When a controller’s name matches the first segment of a URI, it will be loaded.
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 Blog.php, and put the following code in it:
<?php
class Blog extends CI_Controller {
public function index()
{
echo 'Hello World!';
}
}
Then save the file to your application/controllers/ directory.
QVCI Framework Specifics¶
QVCI documentation on controllers follows.
Making public functions private to the outside¶
The Qvc_controller has several functions that need to be public so they can be called from other parts of the software, such as views. The problem is, we don’t want these functions available as methods from a URL. The solution is to use a leading underscore in the name.