How To Use Controllers
Controllers are the end point of every requests. They manipulate data inputs and update model states before returning a view filled with processed data. For more documentation about Controllers, check the section about the MVC module (Coming Soon).
Controllers must be located in the controllers
directory in order for the router to find it and to execute its code. Each controller files must contain only one controller class. A controller class must inherit from \Apine\MVC\Controller
. Controllers are part of the namespace \Apine\Controllers\User
.
- A controller class name is made of a name followed by "Controller" in a
PascalCased
fashion; - The file name must be the same as the class name.
Per example, if you are writting a controller for user management you want to name "user". The class name would be UserController then the file name would be UserController.php.
namespace Apine\Controllers\User;
use Apine\MVC\Controller
class HomeController extends Controller{
public function index(){
}
}
An action is a method in a controller class. Its designed to take an array as an optional argument. Its name is used by the router with the controller name to find and execute the action.
Controllers and their actions are by default accessible via controller/action
. Then you can append any number of parameter to the string. It is possible to modify this behavior with Routes.
In order to access to arguments from the query string or form data, you must specify one argument to you action method. It is an aggregate of the $_GET, $_POST and $_FILES super arrays previously passed through some pre-validation processes.
GET arguments are accessible with numeric indexes. POST and FILES arguments are accessible with their field name as index just like in $_POST and $_FILES arrays.
function about () {
// Do stuff here
}
function page ($params) {
$page_no = $params[0]; // First get arguments in URI
$username = $params[‘username’]; // A POST argument
}
An action should return a view that will be then processed and sent back to the client. There are two main types of views : HTML views and JSON views.
public empty_action () {
$view = new Apine\MVC\HTMLView();
return $view;
}
- Introduction
- Getting Started
- Requirements & Installation
- Application Configuration
- Database Connection
- How to use Controllers
- How to use Views
- How to Manage Session
- How to use the api (Coming Soon)
- Utilities
- Entity Manager
- File Manager
- Access and Save File (Coming Soon)
- Image Methods (Coming Soon)
- XML Manager
- XML Class (Coming Soon)
- Parser (Coming Soon)
- Writer (Coming Soon)
- Advanced Topics
- Extended Users
- Routes
- Templating (Coming Soon)
- Translations and Locales