Skip to content

Commit 8f47a6e

Browse files
committed
Added more Common functions and improved rendering [ci skip]
1 parent 098b7fe commit 8f47a6e

7 files changed

Lines changed: 182 additions & 124 deletions

File tree

user_guide_src/source/concepts/autoloader.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ application's files. This is most important for any business-logic related class
4040
etc. The ``psr4`` array in the configuration file allows you to map the namespace to the directory
4141
those classes can be found in::
4242

43-
$psr4 = [
44-
'App' => APPPATH,
45-
'CodeIgniter' => SYSTEMPATH,
46-
];
43+
$psr4 = [
44+
'App' => APPPATH,
45+
'CodeIgniter' => SYSTEMPATH,
46+
];
4747

4848
The key of each row is the namespace itself. This does not need a trailing slash. If you use double-quotes
4949
to define the array, be sure to escape the backward slash. That means that it would be ``My\\App``,
@@ -55,13 +55,13 @@ libraries, or models in the application directory, if you do, they will be found
5555
You may change this namespace by editing the **/app/Config/Constants.php** file and setting the
5656
new namespace value under the ``APP_NAMESPACE`` setting::
5757

58-
define('APP_NAMESPACE', 'App');
58+
define('APP_NAMESPACE', 'App');
5959

6060
You will need to modify any existing files that are referencing the current namespace.
6161

6262
.. important:: Config files are namespaced in the ``Config`` namespace, not in ``App\Config`` as you might
63-
expect. This allows the core system files to always be able to locate them, even when the application
64-
namespace has changed.
63+
expect. This allows the core system files to always be able to locate them, even when the application
64+
namespace has changed.
6565

6666
Classmap
6767
========
@@ -70,9 +70,9 @@ The classmap is used extensively by CodeIgniter to eke the last ounces of perfor
7070
by not hitting the file-system with extra ``is_file()`` calls. You can use the classmap to link to
7171
third-party libraries that are not namespaced::
7272

73-
$classmap = [
74-
'Markdown' => APPPATH .'third_party/markdown.php'
75-
];
73+
$classmap = [
74+
'Markdown' => APPPATH .'third_party/markdown.php'
75+
];
7676

7777
The key of each row is the name of the class that you want to locate. The value is the path to locate it at.
7878

@@ -89,7 +89,7 @@ Composer Support
8989
================
9090

9191
Composer support is automatically initialized by default. By default, it looks for Composer's autoload file at
92-
ROOTPATH.'vendor/autoload.php'. If you need to change the location of that file for any reason, you can modify
92+
``ROOTPATH.'vendor/autoload.php'``. If you need to change the location of that file for any reason, you can modify
9393
the value defined in ``Config\Constants.php``.
9494

9595
.. note:: If the same namespace is defined in both CodeIgniter and Composer, CodeIgniter's autoloader will be

user_guide_src/source/general/ajax.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@ Fetch API
1616
fetch(url, {
1717
method: "get",
1818
headers: {
19-
2019
"Content-Type": "application/json",
21-
2220
"X-Requested-With": "XMLHttpRequest"
23-
2421
}
25-
2622
});
2723
2824
@@ -35,9 +31,7 @@ For libraries like jQuery for example, it is not necessary to make explicit the
3531
3632
$.ajax({
3733
url: "your url",
38-
3934
headers: {'X-Requested-With': 'XMLHttpRequest'}
40-
4135
});
4236
4337

user_guide_src/source/general/common_functions.rst

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Global Functions and Constants
33
##############################
44

5-
CodeIgniter uses provides a few functions and variables that are globally defined, and are available to you at any point.
5+
CodeIgniter provides a few functions and variables that are globally defined, and are available to you at any point.
66
These do not require loading any additional libraries or helpers.
77

88
.. contents::
@@ -81,6 +81,14 @@ Service Accessors
8181

8282
For more information, see the :doc:`Localization </outgoing/localization>` page.
8383

84+
.. php:function:: model($name [, $getShared = true [, &$conn = null ]])
85+
86+
:param string $name:
87+
:param boolean $getShared:
88+
:param ConnectionInterface|null $conn:
89+
:returns: More simple way of getting model instances
90+
:rtype: mixed
91+
8492
.. php:function:: old( $key[, $default = null, [, $escape = 'html' ]] )
8593
8694
:param string $key: The name of the old form data to check for.
@@ -166,9 +174,27 @@ Service Accessors
166174

167175
For more details, see the :doc:`Views </outgoing/views>` page.
168176

177+
.. php:function:: view_cell ( $library [, $params = null [, $ttl = 0 [, $cacheName = null]]] )
178+
179+
:param string $library:
180+
:param null $params:
181+
:param integer $ttl:
182+
:param string|null $cacheName:
183+
:returns: View cells are used within views to insert HTML chunks that are managed by other classes.
184+
:rtype: string
185+
186+
For more details, see the :doc:`View Cells </outgoing/view_cells>` page.
187+
169188
Miscellaneous Functions
170189
=======================
171190

191+
.. php:function:: app_timezone ()
192+
193+
:returns: The timezone the application has been set to display dates in.
194+
:rtype: string
195+
196+
Returns the timezone the application has been set to display dates in.
197+
172198
.. php:function:: csrf_token ()
173199
174200
:returns: The name of the current CSRF token.
@@ -195,7 +221,7 @@ Miscellaneous Functions
195221
:returns: A string with the HTML for hidden input with all required CSRF information.
196222
:rtype: string
197223

198-
Returns a hidden input with the CSRF information already inserted:
224+
Returns a hidden input with the CSRF information already inserted::
199225

200226
<input type="hidden" name="{csrf_token}" value="{csrf_hash}">
201227

@@ -204,7 +230,7 @@ Miscellaneous Functions
204230
:returns: A string with the HTML for meta tag with all required CSRF information.
205231
:rtype: string
206232

207-
Returns a meta tag with the CSRF information already inserted:
233+
Returns a meta tag with the CSRF information already inserted::
208234

209235
<meta name="{csrf_header}" content="{csrf_hash}">
210236

@@ -219,11 +245,23 @@ Miscellaneous Functions
219245
but through HTTPS. Will set the HTTP Strict Transport Security header, which instructs
220246
modern browsers to automatically modify any HTTP requests to HTTPS requests for the $duration.
221247

248+
.. php:function:: function_usable ( $function_name )
249+
250+
:param string $function_name: Function to check for
251+
:returns: TRUE if the function exists and is safe to call, FALSE otherwise.
252+
:rtype: bool
253+
222254
.. php:function:: is_cli ()
223255
224256
:returns: TRUE if the script is being executed from the command line or FALSE otherwise.
225257
:rtype: bool
226258

259+
.. php:function:: is_really_writable ( $file )
260+
261+
:param string $file: The filename being checked.
262+
:returns: TRUE if you can write to the file, FALSE otherwise.
263+
:rtype: bool
264+
227265
.. php:function:: log_message ($level, $message [, $context])
228266
229267
:param string $level: The level of severity
@@ -319,6 +357,14 @@ Miscellaneous Functions
319357
function will return a new instance of the class, where **service** returns the same
320358
instance every time.
321359

360+
.. php:function:: slash_item ( $item )
361+
362+
:param string $item: Config item name
363+
:returns: The configuration item or NULL if the item doesn't exist
364+
:rtype: string|null
365+
366+
Fetch a config file item with slash appended (if not empty)
367+
322368
.. php:function:: stringify_attributes ( $attributes [, $js] )
323369
324370
:param mixed $attributes: string, array of key value pairs, or object

user_guide_src/source/general/errors.rst

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,40 @@ This section is a quick overview for newer programmers, or for developers who ar
2020
Exceptions are simply events that happen when the exception is "thrown". This halts the current flow of the script, and
2121
execution is then sent to the error handler which displays the appropriate error page::
2222

23-
throw new \Exception("Some message goes here");
23+
throw new \Exception("Some message goes here");
2424

2525
If you are calling a method that might throw an exception, you can catch that exception using a ``try/catch`` block::
2626

27-
try {
28-
$user = $userModel->find($id);
29-
}
30-
catch (\Exception $e)
31-
{
32-
die($e->getMessage());
33-
}
27+
try
28+
{
29+
$user = $userModel->find($id);
30+
}
31+
catch (\Exception $e)
32+
{
33+
die($e->getMessage());
34+
}
3435

3536
If the ``$userModel`` throws an exception, it is caught and the code within the catch block is executed. In this example,
3637
the scripts dies, echoing the error message that the ``UserModel`` defined.
3738

38-
In this example, we catch any type of Exception. If we only want to watch for specific types of exceptions, like
39-
a UnknownFileException, we can specify that in the catch parameter. Any other exceptions that are thrown and are
39+
In the example above, we catch any type of Exception. If we only want to watch for specific types of exceptions, like
40+
a ``UnknownFileException``, we can specify that in the catch parameter. Any other exceptions that are thrown and are
4041
not child classes of the caught exception will be passed on to the error handler::
4142

42-
catch (\CodeIgniter\UnknownFileException $e)
43-
{
44-
// do something here...
45-
}
43+
catch (\CodeIgniter\UnknownFileException $e)
44+
{
45+
// do something here...
46+
}
4647

4748
This can be handy for handling the error yourself, or for performing cleanup before the script ends. If you want
4849
the error handler to function as normal, you can throw a new exception within the catch block::
4950

50-
catch (\CodeIgniter\UnknownFileException $e)
51-
{
52-
// do something here...
51+
catch (\CodeIgniter\UnknownFileException $e)
52+
{
53+
// do something here...
5354

54-
throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
55-
}
55+
throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
56+
}
5657

5758
Configuration
5859
=============
@@ -97,10 +98,10 @@ This is used to signal a 404, Page Not Found error. When thrown, the system will
9798
If, in ``Config/Routes.php``, you have specified a 404 Override, that will be called instead of the standard
9899
404 page::
99100

100-
if (! $page = $pageModel->find($id))
101-
{
102-
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
103-
}
101+
if (! $page = $pageModel->find($id))
102+
{
103+
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
104+
}
104105

105106
You can pass a message into the exception that will be displayed in place of the default message on the 404 page.
106107

@@ -110,7 +111,7 @@ ConfigException
110111
This exception should be used when the values from the configuration class are invalid, or when the config class
111112
is not the right type, etc::
112113

113-
throw new \CodeIgniter\Exceptions\ConfigException();
114+
throw new \CodeIgniter\Exceptions\ConfigException();
114115

115116
This provides an HTTP status code of 500 and an exit code of 3.
116117

@@ -120,7 +121,7 @@ DatabaseException
120121
This exception is thrown for database errors, such as when the database connection cannot be created,
121122
or when it is temporarily lost::
122123

123-
throw new \CodeIgniter\Database\Exceptions\DatabaseException();
124+
throw new \CodeIgniter\Database\Exceptions\DatabaseException();
124125

125126
This provides an HTTP status code of 500 and an exit code of 8.
126127

@@ -130,9 +131,9 @@ RedirectException
130131
This exception is a special case allowing for overriding of all other response routing and
131132
forcing a redirect to a specific route or URL::
132133

133-
throw new \CodeIgniter\Router\Exceptions\RedirectException($route);
134+
throw new \CodeIgniter\Router\Exceptions\RedirectException($route);
134135

135136
``$route`` may be a named route, relative URI, or a complete URL. You can also supply a
136137
redirect code to use instead of the default (``302``, "temporary redirect")::
137138

138-
throw new \CodeIgniter\Router\Exceptions\RedirectException($route, 301);
139+
throw new \CodeIgniter\Router\Exceptions\RedirectException($route, 301);

0 commit comments

Comments
 (0)