API Documentation
- Documents the View class.
- Main class used for building a page.
- Extended for each view in views.php
- Accessed by $page in the template.
Utilised in vews.php
- string $title
Sets the page's <title> element. Defaults to the title defined in settings.php
Example of usage:
$this->title = 'Yellowgrey framework - example page';
- string $template
Sets the base template to use.
Example of usage:
$this->template = 'baseHTML';
- string $view
Sets the page body, defaults to the name of the class or the home page body. This is the php file in the templates directory that will be used to generate body()
Example of usage:
$this->view = 'example';
- void set_HTTP_status_code()
Sets the status code. If a valid location is not provided for a 300 series redirect a 200 OK response will be sent.
Parameters:
- int $code Status code to set. Allowed values are: 200, 301, 302, 303, 307, 404, 410, 500
- string $location Location for redirection, must be an absolute URL starting with http://
Examples of usage:
$this->set_HTTP_status_code(200);
$this->set_HTTP_status_code(301, 'http://example.com/redirect-target'); - void set_content_type()
Sets the content type and, optionally, the character set.
Parameters:
- string $type Mime type of content
- string $charset Character set of content (optional)
Examples of usage:
$this->set_content_type('application/pdf');
$this->set_content_type('text/xml','utf-8'); - void add_css()
- void remove_css()
Change stylesheet inclusion. main.css is included by default.
Parameters:
- string $css Name of css file to add/remove, omitting .css extension.
Examples of usage:
$this->remove_css('main');
$this->add_css('extra'); - void add_js()
- void remove_js()
Change JavaScript inclusion. main.js is included by default
Parameters:
- string $js Name of JavaScript file to add/remove, omitting .js extension.
Examples of usage:
$this->remove_js('main');
$this->add_js('extra');
Utilised in templates
- string body()
Returns the body content. Processes the view, executes code and returns the resulting output.
Example of usage:
<?php echo $page->body() ?>
- string headers()
Returns the stylesheets and JavaScript includes as HTML code.
Example of usage:
<?php echo $page->headers() ?>
- string title()
Returns the page title as HTML code.
Example of usage:
<?php echo $page->title() ?>
- string link_to_route()
Returns a link to a route as HTML code.
Parameters:
- string $route Value of route key from routing array defined in urls.php
- string $text Link text to display.
- string $class HTML class attribute of anchor. (optional)
- string $id HTML id attribute of anchor. (optional)
- string $rel HTML rel attribute of anchor. (optional)
Example of usage:
<?php echo $page->link_to_route('home', 'Home Page') ?>
Utilised anywhere
- string debug()
Returns a debug message if DEBUG is set to True in settings.php May cause errors if called in views.php when headers are subsequently called on page build.
Parameters:
- string $string Message to display.
Example of usage:
<?php echo $page->debug("View selected was: {$page->view}") ?>
- string resolve_route()
Returns the URI of a route relative to the server root. Combined with $_SERVER['HTTP_HOST'] this can be used to build absolute URLs suitable for redirection.
Parameters:
- string $route Value of route key from routing array defined in urls.php
Example of usage:
$this->resolve_route('example');