-
Notifications
You must be signed in to change notification settings - Fork 194
Controller Plain
Controller | Extends | Path |
---|---|---|
Plain_Controller | CI_Controller | /application/core/Plain_Controller.php |
This controller is extended by most of the other controllers in the system. It handles the logic to figure out if to start a session or not, handles redirects and figures what type of view to render.
No need, it's done for you. Back off Buster Brown.
Property | Visibility | Default Value | Description |
---|---|---|---|
$clean | Public | object | If any POST or GET data is found, it is cleaned and placed in this object. |
$csrf_token | Public | string | The CSRF token to be used by the application for the user. |
$current_user | Public | array | Holds all the user information about the currently logged in user. |
$data | Public | array | Holds all the key/values pairs to pass to the views. |
$db_clean | Public | object | If any POST or GET data is found, it is cleaned and escaped for the database and placed in this object. |
$flash_message | Public | array | Holds an array of the type and message if one is set for the next view. |
$footer | Public | string | The default footer to user for the current view. |
$header | Public | string | The default header to use for the current view. |
$html_clean | Public | object | If any POST or GET data is found, it is cleaned and escaped for the database wtih HTML tags **NOT** stripped out and placed in this object. |
$is_api | Public | boolean | Set to true if current request is an API call, false if not. |
$limit | Public | integer | The default limit to use for extracting records from the database. |
$logged_in | Public | boolean | Set to true if user is logged in, false if not. |
$original | Public | object | If any POST or GET data is found, it will be placed in this object. |
$user_admin | Public | boolean | Set to true if user is an admin, false if not. |
$user_id | Public | integer | The current user's ID. |
$user_token | Public | string | The current user's security token. |
Called automatically which in turn calls the parent constructor. It also does the following:
- Figures whether to start a session or not
- Cleans any GET or POST variables
- Gets the current user's information
- Generates a CSRF token where applicable
- Figures if CSRF token sent is a match to current where applicable
- Gets any flash messages
Adds a mark to the systems and to the user's account.
Variable | Type | Default | Required | Options | Description |
---|---|---|---|---|---|
$data | Array | N/A | Yes | data['url'], data['title'], $data['label_id'] | An array of data to create the mark for. |
$data['url'] | String | N/A | Yes | N/A | The URL to create the mark from. |
$data['title'] | String | No Title | No | N/A | The page title from the URL sent. |
$data['label_id'] | Integer | N/A | No | N/A | If you want to apply a label directly to this record for the user, supply it. |
$mark = $this->addMark(array(
'url' => 'http://somesite.com',
'title' => 'Site Title',
'label_id' => 7
));
Used to check if a mark already exists for the current user. If so it returns the mark, if not it returns false.
Variable | Type | Default | Required | Options | Description |
---|---|---|---|---|---|
$url | string | N/A | Yes | N/A | The URL to check for in the current user's account. |
// Calling from child controller
$mark = parent::checkMark('http://google.com');
if ($mark == false) {
// Add it
}
else {
// Return it
}
Used to check for GET or POST variables. If found, it saves the original copy, cleaned copy, database cleaned copy and an html cleaned copy under the class properties of $this->original
, $this->clean
, $this->db_clean
and $this->html_clean
.
$this->clean();
Used to figure out if the view should render a JSON only result, a redirect or a web view.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$view | string | null | No | The view to show for the web view. |
$redirect | string | null | No | The redirect path or url to redirect to when applicable. |
// For API or XMLHttpRequest calls only
$this->figureView();
// Could be a web view, API or XMLHttpRequest call
$this->figureView('marks/index');
// Redirect user
$this->figureView(null, '/marks/tag/TAG_SLUG');
Used to verify the current CSRF token vs any REQUEST['csrf_token']
if found. Also will generate a CSRF token if the user does not have one in their session. Safe to call at all times. If not using a session it will automatically figure that out.
$this->generateCSRF();
Checks to find any flash messages and the flash message type. If found it sets the data to $this->flash_message
and unsets from session.
$this->getFlashMessages();
Used to set $this->user_token
, $this->user_id
, $this->user_admin
and $this->logged_in
on every request. Will read from session or API user token.
$this->getUserInfo();
Returns true or false if the user is an admin.
if ($this->isAdmin() === true) {
// Cool, lucky you
}
Returns true or false if the request is an XMLHttpRequest request.
if ($this->isXMLHttpRequest() === true) {
// Well aren't you fancy
}
Returns true or false if the request if an API request.
if ($this->isAPI() === true) {
// Smarty Pants
}
Returns true or false if the request is coming from the Chrome extension
if ($this->isChromeExtension() === true) {
// hey hey hey
}
Returns true or false if the request is coming from the command line.
if ($this->isCommandLine() === true) {
// Super geek
}
Returns true or false if the request is an XMLHttpRequest request originating from the same domain.
if ($this->isInternalXMLHttpRequest() === true) {
// Do work!
}
Returns true or false if the call is coming from the PJAX library. If so it renders the full HTML view minus the header and footer.
if ($this->isPJAX() === true) {
// don't forget to pushState!
}
Returns true or false if the host and referer are the same domain.
if ($this->isSameHost() === true) {
// Samsies
}
Returns true or false if the current request is for a web view.
if ($this->isWebView() === true) {
// Samsies
}
Redirects the user to the url specified if the CSRF is invalid.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$url | string | / | No | The url or path to redirect the user to. |
$this->redirectIfInvalidCSRF();
Redirects the user to the url specified if they are logged in.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$url | string | / | No | The url or path to redirect the user to. |
$this->redirectIfLoggedIn();
Redirects the user to the url specified if the user is logged out.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$url | string | / | No | The url or path to redirect the user to. |
$this->redirectIfLoggedOut();
Redirects the user to the url specified if the user is not an admin.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$url | string | / | No | The url or path to redirect the user to. |
$this->redirectIfNotAdmin();
Redirects the user to the url specified if the request is not an API request.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$url | string | / | No | The url or path to redirect the user to. |
$this->redirectIfNotAPI();
Redirects the user to the url specified if the request is not coming from the command line.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$url | string | / | No | The url or path to redirect the user to. |
$this->redirectIfNotCommandLine();
Redirects the user to the url specified if the request is not a web view or an internal call.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$url | string | / | No | The url or path to redirect the user to. |
$this->redirectIfNotInternal();
Redirects the user to the url specified if the request is for a web view.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$url | string | / | No | The url or path to redirect the user to. |
$this->redirectIfWebView();
Reads the data from $this->data
, turns it into a JSON string and prints the response.
$this->data['success'] = true;
$this->renderJSON();
Sets all the user data to the user's current session. Also sets logged_in
key to true for the user's session.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$user | object | N/A | Yes | The user object to pull data from to set into the session. |
$this->load->model('users_model', 'user');
$user = $this->user->read("email = 'EMAIL'", 1);
if (isset($user->user_id)) {
$this->sessionAddUser($user);
}
Removes all session data and cookies.
$this->sessionClear();
Figures if the application should start a session based on the request. Command line and API requests will NOT start a session.
$this->sessionStart();
Sets a flash message into memory.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$message | string | N/A | Yes | The flash message/ |
$type | string | error | No | The flash message type. Can be `error` or `success`. |
$this->setFlashMessage('my message')
Used to render views. If your $data
argument you can set any number of variables just like the CI_View to be rendered in templates. This view will also support header and footer and automatically append any flash messages for the user it finds to the data. You don't need to do that.
The header and footer are prepended and appended to your view if submitted. Also debug information is always shown under the footer in non-production mode. Get used to it.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$view | string | N/A | Yes | The view from the view folder to render. (IE: 'index' or 'stats/index' if in a folder). |
$data | array | array() | No | The data to pass to each view. It will be merged with that is already found in `$this->data`. |
$this->view('marks/index', array(
'page_title' => 'Your Marks'
));