Skip to content

Commit 1d3c00f

Browse files
committed
Adding common functions docs.
1 parent 008a572 commit 1d3c00f

File tree

2 files changed

+157
-2
lines changed

2 files changed

+157
-2
lines changed

system/Common.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ function service(string $name, ...$params)
248248

249249
//--------------------------------------------------------------------
250250

251-
if (! function_exists('sharedService'))
251+
if (! function_exists('shared_service'))
252252
{
253-
function sharedService(string $name, ...$params)
253+
function shared_service(string $name, ...$params)
254254
{
255255
// Ensure the number of params we are passing
256256
// meets the number the method expects, since
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
################
2+
Common Functions
3+
################
4+
5+
CodeIgniter uses provides a few functions that are globally defined, and are available to you at any point. These
6+
do not require loading any additional libraries or helpers.
7+
8+
.. contents:: Page Contents
9+
:local:
10+
11+
12+
.. php:function:: log_message ($level, $message [, array $context])
13+
14+
:param string $level: The level of severity
15+
:param string $message: The message that is to be logged.
16+
:param array $context: An associative array of tags and their values that should be replaced in $message
17+
:returns: TRUE if was logged succesfully or FALSE if there was a problem logging it
18+
:rtype: bool
19+
20+
Logs a message using the Log Handlers defined in **application/Config/Logger.php**.
21+
22+
Level can be one of the following values: **emergency**, **alert**, **critical**, **error**, **warning**,
23+
**notice**, **info**, or **debug**.
24+
25+
Context can be used to substitute values in the message string. For full details, see the
26+
:doc:`Logging Information <logging>` page.
27+
28+
.. php:function:: view ($name [, $data [, $options ]])
29+
30+
:param string $name: The name of the file to load
31+
:param array $data: An array of key/value pairs to make available within the view.
32+
:param array $options: An array of options that will be passed to the rendering class.
33+
:returns: The output from the view.
34+
:rtype: string
35+
36+
Grabs the current RenderableInterface-compatible class
37+
and tells it to render the specified view. Simply provides
38+
a convenience method that can be used in Controllers,
39+
libraries, and routed closures.
40+
41+
The $option array is not used by CodeIgniter, but is provided to facilitate third-party integrations with
42+
libraries like Twig.
43+
44+
Example::
45+
46+
$data = ['user' => $user];
47+
48+
echo view('user_profile', $data);
49+
50+
For more details, see the :doc:`Views <views>` page.
51+
52+
.. php:function:: esc ( $data, $context='html' [, $encoding])
53+
54+
:param string|array $data: The information to be escaped.
55+
:param string $context: The escaping context. Default is 'html'.
56+
:param string $encoding: The character encoding of the string.
57+
:returns: The escaped data.
58+
:rtype: string
59+
60+
Escapes data for inclusion in web pages, to help prevent XSS attacks.
61+
This uses the Zend Escaper library to handle the actual filtering of the data.
62+
63+
If $data is a string, then it simply escapes and returns it.
64+
If $data is an array, then it loops over it, escaping each 'value' of the key/value pairs.
65+
66+
Valid context values: html, js, css, url, attr, raw, null
67+
68+
.. php:function:: is_cli ()
69+
70+
:returns: TRUE if the script is being executed from the command line or FALSE otherwise.
71+
:rtype: bool
72+
73+
.. php:function:: route_to ( $method [, ...$params] )
74+
75+
:param string $method: The named route alias, or name of the controller/method to match.
76+
:param mixed $params: One or more parameters to be passed to be matched in the route.
77+
78+
Generates a relative URI for you based on either a named route alias, or a controller::method
79+
combination. Will take parameters into effect, if provided.
80+
81+
For full details, see the :doc:`routing` page.
82+
83+
.. php:function:: service ( $name [, ...$params] )
84+
85+
:param string $name: The name of the service to load
86+
:param mixed $params: One or more parameters to pass to the service method.
87+
:returns: An instance of the service class specified.
88+
:rtype: mixed
89+
90+
Provides easy access to any of the :doc:`Services <../concepts/services>` defined in the system.
91+
92+
Example::
93+
94+
$logger = service('logger');
95+
$renderer = service('renderer', APPPATH.'views/');
96+
97+
.. php:function:: shared_service ( $name [, ...$params] )
98+
99+
:param string $name: The name of the service to load
100+
:param mixed $params: One or more parameters to pass to the service method.
101+
:returns: An instance of the service class specified.
102+
:rtype: mixed
103+
104+
Identical to the **service()** function described above, except that all calls to this
105+
function will share the same instance of the service, where **service** returns a new
106+
instance every time.
107+
108+
.. php:function:: remove_invisible_characters($str[, $url_encoded = TRUE])
109+
110+
:param string $str: Input string
111+
:param bool $url_encoded: Whether to remove URL-encoded characters as well
112+
:returns: Sanitized string
113+
:rtype: string
114+
115+
This function prevents inserting NULL characters between ASCII
116+
characters, like Java\\0script.
117+
118+
Example::
119+
120+
remove_invisible_characters('Java\\0script');
121+
// Returns: 'Javascript'
122+
123+
.. php:function:: load_helper( $filename )
124+
125+
:param string $filename: The name of the helper file to load.
126+
127+
Loads a helper file.
128+
129+
For full details, see the :doc:`helpers` page.
130+
131+
.. php:function:: get_csrf_token_name ()
132+
133+
:returns: The name of the current CSRF token.
134+
:rtype: string
135+
136+
Returns the name of the current CSRF token.
137+
138+
.. php:function:: get_csrf_hash ()
139+
140+
:returns: The current value of the CSRF hash.
141+
:rtype: string
142+
143+
Returns the current CSRF hash value.
144+
145+
.. php:function:: force_https ( $duration = 31536000 [, $request = null [, $response = null]] )
146+
147+
:param int $duration: The number of seconds browsers should convert links to this resource to HTTPS.
148+
:param RequestInterface $request: An instance of the current Request object.
149+
:param ResponseInterface $response: An instance of the current Response object.
150+
151+
Checks to see if the page is currently being accessed via HTTPS. If it is, then
152+
nothing happens. If it is not, then the user is redirected back to the current URI
153+
but through HTTPS. Will set the HTTP Strict Transport Security header, which instructs
154+
modern browsers to automatically modify any HTTP requests to HTTPS requests for the $duration.
155+

0 commit comments

Comments
 (0)