summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/libraries
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2015-01-12 16:23:26 +0100
committerAndrey Andreev <narf@devilix.net>2015-01-12 16:23:26 +0100
commit45a8afaabc6d09ad59bbb3c89a6cdfe8cbc3312c (patch)
tree7ca4207099f9225b5ef74b31f48627a282e7fdf2 /user_guide_src/source/libraries
parentcd94dd7e1d8969658810ccc4158a75d2936d0a44 (diff)
parent934d6d9797f4dadd4e4d05b12bc4d7309fedb6c3 (diff)
Merge branch 'develop' into feature/session
Diffstat (limited to 'user_guide_src/source/libraries')
-rw-r--r--user_guide_src/source/libraries/cart.rst3
-rw-r--r--user_guide_src/source/libraries/encryption.rst1
-rw-r--r--user_guide_src/source/libraries/form_validation.rst8
-rw-r--r--user_guide_src/source/libraries/input.rst56
-rw-r--r--user_guide_src/source/libraries/javascript.rst8
-rw-r--r--user_guide_src/source/libraries/language.rst94
-rw-r--r--user_guide_src/source/libraries/loader.rst3
-rw-r--r--user_guide_src/source/libraries/pagination.rst78
-rw-r--r--user_guide_src/source/libraries/parser.rst242
-rw-r--r--user_guide_src/source/libraries/security.rst6
-rw-r--r--user_guide_src/source/libraries/unit_testing.rst4
-rw-r--r--user_guide_src/source/libraries/zip.rst65
12 files changed, 409 insertions, 159 deletions
diff --git a/user_guide_src/source/libraries/cart.rst b/user_guide_src/source/libraries/cart.rst
index bedea4dbf..a023ccb36 100644
--- a/user_guide_src/source/libraries/cart.rst
+++ b/user_guide_src/source/libraries/cart.rst
@@ -7,6 +7,9 @@ while a user is browsing your site. These items can be retrieved and
displayed in a standard "shopping cart" format, allowing the user to
update the quantity or remove items from the cart.
+.. important:: The Card library is DEPRECATED and should not be used.
+ It is currently only kept for backwards compatibility.
+
Please note that the Cart Class ONLY provides the core "cart"
functionality. It does not provide shipping, credit card authorization,
or other processing components.
diff --git a/user_guide_src/source/libraries/encryption.rst b/user_guide_src/source/libraries/encryption.rst
index f29ebf4ed..2d0ee23a3 100644
--- a/user_guide_src/source/libraries/encryption.rst
+++ b/user_guide_src/source/libraries/encryption.rst
@@ -533,6 +533,7 @@ Class Reference
:param int $length: Optional output length
:param string $info: Optional context/application-specific info
:returns: A pseudo-random key or FALSE on failure
+ :rtype: string
Derives a key from another, presumably weaker key.
diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst
index aae9e3b89..f964965ec 100644
--- a/user_guide_src/source/libraries/form_validation.rst
+++ b/user_guide_src/source/libraries/form_validation.rst
@@ -326,14 +326,13 @@ In addition to the validation method like the ones we used above, you
can also prep your data in various ways. For example, you can set up
rules like this::
- $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|max_length[12]|xss_clean');
+ $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|max_length[12]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|md5');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'trim|required|matches[password]');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
-In the above example, we are "trimming" the fields, converting the
-password to MD5, and running the username through the `xss_clean()`
-method, which removes malicious data.
+In the above example, we are "trimming" the fields, checking for length
+where necessary and converting the password to MD5.
**Any native PHP function that accepts one parameter can be used as a
rule, like htmlspecialchars, trim, md5, etc.**
@@ -1002,7 +1001,6 @@ to use:
==================== ========= =======================================================================================================
Name Parameter Description
==================== ========= =======================================================================================================
-**xss_clean** No Runs the data through the XSS filtering method, described in the :doc:`Security Class <security>` page.
**prep_for_form** No Converts special characters so that HTML data can be shown in a form field without breaking it.
**prep_url** No Adds "\http://" to URLs if missing.
**strip_image_tags** No Strips the HTML from image tags leaving the raw URL.
diff --git a/user_guide_src/source/libraries/input.rst b/user_guide_src/source/libraries/input.rst
index f9dbf1686..4464e0fdc 100644
--- a/user_guide_src/source/libraries/input.rst
+++ b/user_guide_src/source/libraries/input.rst
@@ -17,6 +17,10 @@ The Input Class serves two purposes:
<div class="custom-index container"></div>
+***************
+Input Filtering
+***************
+
Security Filtering
==================
@@ -49,6 +53,10 @@ this::
Please refer to the :doc:`Security class <security>` documentation for
information on using XSS Filtering in your application.
+*******************
+Accessing form data
+*******************
+
Using POST, GET, COOKIE, or SERVER Data
=======================================
@@ -108,7 +116,7 @@ Class Reference
.. method:: post([$index = NULL[, $xss_clean = NULL]])
- :param string $index: POST parameter name
+ :param mixed $index: POST parameter name
:param bool $xss_clean: Whether to apply XSS filtering
:returns: $_POST if no parameters supplied, otherwise the POST value if found or NULL if not
:rtype: mixed
@@ -137,9 +145,21 @@ Class Reference
$this->input->post(NULL, TRUE); // returns all POST items with XSS filter
$this->input->post(NULL, FALSE); // returns all POST items without XSS filter
+ To return an array of multiple POST parameters, pass all the required keys
+ as an array.
+ ::
+
+ $this->input->post(array('field1', 'field2'));
+
+ Same rule applied here, to retrive the parameters with XSS filtering enabled, set the
+ second parameter to boolean TRUE.
+ ::
+
+ $this->input->post(array('field1', 'field2'), TRUE);
+
.. method:: get([$index = NULL[, $xss_clean = NULL]])
- :param string $index: GET parameter name
+ :param mixed $index: GET parameter name
:param bool $xss_clean: Whether to apply XSS filtering
:returns: $_GET if no parameters supplied, otherwise the GET value if found or NULL if not
:rtype: mixed
@@ -158,6 +178,18 @@ Class Reference
$this->input->get(NULL, TRUE); // returns all GET items with XSS filter
$this->input->get(NULL, FALSE); // returns all GET items without XSS filtering
+ To return an array of multiple GET parameters, pass all the required keys
+ as an array.
+ ::
+
+ $this->input->get(array('field1', 'field2'));
+
+ Same rule applied here, to retrive the parameters with XSS filtering enabled, set the
+ second parameter to boolean TRUE.
+ ::
+
+ $this->input->get(array('field1', 'field2'), TRUE);
+
.. method:: post_get($index[, $xss_clean = NULL])
:param string $index: POST/GET parameter name
@@ -188,7 +220,7 @@ Class Reference
.. method:: cookie([$index = NULL[, $xss_clean = NULL]])
- :param string $index: COOKIE parameter name
+ :param mixed $index: COOKIE name
:param bool $xss_clean: Whether to apply XSS filtering
:returns: $_COOKIE if no parameters supplied, otherwise the COOKIE value if found or NULL if not
:rtype: mixed
@@ -199,9 +231,15 @@ Class Reference
$this->input->cookie('some_cookie');
$this->input->cookie('some_cookie, TRUE); // with XSS filter
+ To return an array of multiple cookie values, pass all the required keys
+ as an array.
+ ::
+
+ $this->input->cookie(array('some_cookie', 'some_cookie2'));
+
.. method:: server($index[, $xss_clean = NULL])
- :param string $index: Value name
+ :param mixed $index: Value name
:param bool $xss_clean: Whether to apply XSS filtering
:returns: $_SERVER item value if found, NULL if not
:rtype: mixed
@@ -211,9 +249,15 @@ Class Reference
$this->input->server('some_data');
+ To return an array of multiple ``$_SERVER`` values, pass all the required keys
+ as an array.
+ ::
+
+ $this->input->server(array('SERVER_PROTOCOL', 'REQUEST_URI'));
+
.. method:: input_stream([$index = NULL[, $xss_clean = NULL]])
- :param string $index: Key name
+ :param mixed $index: Key name
:param bool $xss_clean: Whether to apply XSS filtering
:returns: Input stream array if no parameters supplied, otherwise the specified value if found or NULL if not
:rtype: mixed
@@ -407,4 +451,4 @@ Class Reference
echo $this->input->method(TRUE); // Outputs: POST
echo $this->input->method(FALSE); // Outputs: post
- echo $this->input->method(); // Outputs: post \ No newline at end of file
+ echo $this->input->method(); // Outputs: post
diff --git a/user_guide_src/source/libraries/javascript.rst b/user_guide_src/source/libraries/javascript.rst
index 9d0237e57..7f83b2f70 100644
--- a/user_guide_src/source/libraries/javascript.rst
+++ b/user_guide_src/source/libraries/javascript.rst
@@ -2,16 +2,16 @@
Javascript Class
################
-.. note:: This library is DEPRECATED and should not be used. It has always
- been with an 'experimental' status and is now no longer supported.
- Currently only kept for backwards compatibility.
-
CodeIgniter provides a library to help you with certain common functions
that you may want to use with Javascript. Please note that CodeIgniter
does not require the jQuery library to run, and that any scripting
library will work equally well. The jQuery library is simply presented
as a convenience if you choose to use it.
+.. important:: This library is DEPRECATED and should not be used. It has always
+ been with an 'experimental' status and is now no longer supported.
+ Currently only kept for backwards compatibility.
+
.. contents::
:local:
diff --git a/user_guide_src/source/libraries/language.rst b/user_guide_src/source/libraries/language.rst
index 6949c11c9..e833d9757 100644
--- a/user_guide_src/source/libraries/language.rst
+++ b/user_guide_src/source/libraries/language.rst
@@ -5,16 +5,25 @@ Language Class
The Language Class provides functions to retrieve language files and
lines of text for purposes of internationalization.
-In your CodeIgniter system folder you'll find one called language
-containing sets of language files. You can create your own language
-files as needed in order to display error and other messages in other
-languages.
-
-Language files are typically stored in your **system/language/** directory.
-Alternately you can create a directory called language inside your
-application folder and store them there. CodeIgniter will always load the
-one in **system/language/** first and will then look for an override in
-your **application/language/** directory.
+In your CodeIgniter **system** folder, you will find a **language** sub-directory
+containing a set of language files for the **english** idiom.
+The files in this directory (**system/language/english/**) define the regular messages,
+error messages, and other generally output terms or expressions, for the different parts
+of the CodeIgniter framework.
+
+You can create or incorporate your own language files, as needed, in order to provide
+application-specific error and other messages, or to provide translations of the core
+messages into other languages. These translations or additional messages would go inside
+your **application/language/** directory, with separate sub-directories for each idiom
+(for instance, 'french' or 'german').
+
+The CodeIgniter framework comes with a set of language files for the "english" idiom.
+Additional approved translations for different idioms may be found in the
+`CodeIgniter 3 Translations repositories <https://github.com/codeigniter3-translations>`_.
+Each repository deals with a single idiom.
+
+When CodeIgniter loads language files, it will load the one in **system/language/**
+first and will then look for an override in your **application/language/** directory.
.. note:: Each language should be stored in its own folder. For example,
the English files are located at: system/language/english
@@ -26,6 +35,71 @@ your **application/language/** directory.
<div class="custom-index container"></div>
+***************************
+Handling Multiple Languages
+***************************
+
+If you want to support multiple languages in your application, you would provide folders inside
+your **application/language/** directory for each of them, and you would specify the default
+language in your **application/config/config.php**.
+
+The **application/language/english/** directory would contain any additional language files
+needed by your application, for instance for error messages.
+
+Each of the other idiom-specific directories would contain the core language files that you
+obtained from the translations repositories, or that you translated yourself, as well as
+any additional ones needed by your application.
+
+You would store the language you are currently using, for instance in a session variable.
+
+Sample Language Files
+=====================
+
+::
+
+ system/
+ language/
+ english/
+ ...
+ email_lang.php
+ form_validation_lang.php
+ ...
+
+ application/
+ language/
+ english/
+ error_messages_lang.php
+ french/
+ ...
+ email_lang.php
+ error_messages_lang.php
+ form_validation_lang.php
+ ...
+
+Example of switching languages
+==============================
+
+::
+
+ $idiom = $this->session->get_userdata('language');
+ $this->lang->load('error_messages', $idiom);
+ $oops = $this->lang->line('message_key');
+
+********************
+Internationalization
+********************
+
+The Language class in CodeIgniter is meant to provide an easy and lightweight
+way to support multiplelanguages in your application. It is not meant to be a
+full implementation of what is commonly called `internationalization and localization
+<http://en.wikipedia.org/wiki/Internationalization_and_localization>`_.
+
+We use the term "idiom" to refer to a language using its common name,
+rather than using any of the international standards, such as "en", "en-US",
+or "en-CA-x-ca" for English and some of its variants.
+
+.. note:: There is nothing to prevent you from using those abbreviations in your application!
+
************************
Using the Language Class
************************
diff --git a/user_guide_src/source/libraries/loader.rst b/user_guide_src/source/libraries/loader.rst
index 107b3ece3..48ac6e174 100644
--- a/user_guide_src/source/libraries/loader.rst
+++ b/user_guide_src/source/libraries/loader.rst
@@ -18,8 +18,9 @@ can be libraries (classes) :doc:`View files <../general/views>`,
<div class="custom-index container"></div>
+**********************
Application "Packages"
-======================
+**********************
An application package allows for the easy distribution of complete sets
of resources in a single directory, complete with its own libraries,
diff --git a/user_guide_src/source/libraries/pagination.rst b/user_guide_src/source/libraries/pagination.rst
index 8a62376f1..8c5c2c63a 100644
--- a/user_guide_src/source/libraries/pagination.rst
+++ b/user_guide_src/source/libraries/pagination.rst
@@ -73,29 +73,25 @@ Customizing the Pagination
The following is a list of all the preferences you can pass to the
initialization function to tailor the display.
-$config['uri_segment'] = 3;
-===========================
+**$config['uri_segment'] = 3;**
The pagination function automatically determines which segment of your
URI contains the page number. If you need something different you can
specify it.
-$config['num_links'] = 2;
-=========================
+**$config['num_links'] = 2;**
The number of "digit" links you would like before and after the selected
page number. For example, the number 2 will place two digits on either
side, as in the example links at the very top of this page.
-$config['use_page_numbers'] = TRUE;
-===================================
+**$config['use_page_numbers'] = TRUE;**
By default, the URI segment will use the starting index for the items
you are paginating. If you prefer to show the the actual page number,
set this to TRUE.
-$config['page_query_string'] = TRUE;
-====================================
+**$config['page_query_string'] = TRUE;**
By default, the pagination library assume you are using :doc:`URI
Segments <../general/urls>`, and constructs your links something
@@ -113,8 +109,7 @@ the pagination link will become::
Note that "per_page" is the default query string passed, however can be
configured using ``$config['query_string_segment'] = 'your_string'``
-$config['reuse_query_string'] = FALSE;
-======================================
+**$config['reuse_query_string'] = FALSE;**
By default your Query String arguments (nothing to do with other
query string options) will be ignored. Setting this config to
@@ -126,14 +121,12 @@ URL after the URI segment and before the suffix.::
This helps you mix together normal :doc:`URI Segments <../general/urls>`
as well as query string arguments, which until 3.0 was not possible.
-$config['prefix'] = '';
-=======================
+**$config['prefix'] = '';**
A custom prefix added to the path. The prefix value will be right before
the offset segment.
-$config['suffix'] = '';
-=======================
+**$config['suffix'] = '';**
A custom suffix added to the path. The sufix value will be right after
the offset segment.
@@ -145,13 +138,11 @@ Adding Enclosing Markup
If you would like to surround the entire pagination with some markup you
can do it with these two preferences:
-$config['full_tag_open'] = '<p>';
-=================================
+**$config['full_tag_open'] = '<p>';**
The opening tag placed on the left side of the entire result.
-$config['full_tag_close'] = '</p>';
-===================================
+**$config['full_tag_close'] = '</p>';**
The closing tag placed on the right side of the entire result.
@@ -159,26 +150,22 @@ The closing tag placed on the right side of the entire result.
Customizing the First Link
**************************
-$config['first_link'] = 'First';
-================================
+**$config['first_link'] = 'First';**
The text you would like shown in the "first" link on the left. If you do
not want this link rendered, you can set its value to FALSE.
.. note:: This value can also be translated via a language file.
-$config['first_tag_open'] = '<div>';
-====================================
+**$config['first_tag_open'] = '<div>';**
The opening tag for the "first" link.
-$config['first_tag_close'] = '</div>';
-======================================
+**$config['first_tag_close'] = '</div>';**
The closing tag for the "first" link.
-$config['first_url'] = '';
-==========================
+**$config['first_url'] = '';**
An alternative URL to use for the "first page" link.
@@ -186,21 +173,18 @@ An alternative URL to use for the "first page" link.
Customizing the Last Link
*************************
-$config['last_link'] = 'Last';
-==============================
+**$config['last_link'] = 'Last';**
The text you would like shown in the "last" link on the right. If you do
not want this link rendered, you can set its value to FALSE.
.. note:: This value can also be translated via a language file.
-$config['last_tag_open'] = '<div>';
-===================================
+**$config['last_tag_open'] = '<div>';**
The opening tag for the "last" link.
-$config['last_tag_close'] = '</div>';
-=====================================
+**$config['last_tag_close'] = '</div>';**
The closing tag for the "last" link.
@@ -208,21 +192,18 @@ The closing tag for the "last" link.
Customizing the "Next" Link
***************************
-$config['next_link'] = '&gt;';
-==============================
+**$config['next_link'] = '&gt;';**
The text you would like shown in the "next" page link. If you do not
want this link rendered, you can set its value to FALSE.
.. note:: This value can also be translated via a language file.
-$config['next_tag_open'] = '<div>';
-===================================
+**$config['next_tag_open'] = '<div>';**
The opening tag for the "next" link.
-$config['next_tag_close'] = '</div>';
-=====================================
+**$config['next_tag_close'] = '</div>';**
The closing tag for the "next" link.
@@ -230,21 +211,18 @@ The closing tag for the "next" link.
Customizing the "Previous" Link
*******************************
-$config['prev_link'] = '&lt;';
-==============================
+**$config['prev_link'] = '&lt;';**
The text you would like shown in the "previous" page link. If you do not
want this link rendered, you can set its value to FALSE.
.. note:: This value can also be translated via a language file.
-$config['prev_tag_open'] = '<div>';
-===================================
+**$config['prev_tag_open'] = '<div>';**
The opening tag for the "previous" link.
-$config['prev_tag_close'] = '</div>';
-=====================================
+**$config['prev_tag_close'] = '</div>';**
The closing tag for the "previous" link.
@@ -252,13 +230,11 @@ The closing tag for the "previous" link.
Customizing the "Current Page" Link
***********************************
-$config['cur_tag_open'] = '<b>';
-================================
+**$config['cur_tag_open'] = '<b>';**
The opening tag for the "current" link.
-$config['cur_tag_close'] = '</b>';
-==================================
+**$config['cur_tag_close'] = '</b>';**
The closing tag for the "current" link.
@@ -266,13 +242,11 @@ The closing tag for the "current" link.
Customizing the "Digit" Link
****************************
-$config['num_tag_open'] = '<div>';
-==================================
+**$config['num_tag_open'] = '<div>';**
The opening tag for the "digit" link.
-$config['num_tag_close'] = '</div>';
-====================================
+**$config['num_tag_close'] = '</div>';**
The closing tag for the "digit" link.
diff --git a/user_guide_src/source/libraries/parser.rst b/user_guide_src/source/libraries/parser.rst
index 5af504a03..d66684d9b 100644
--- a/user_guide_src/source/libraries/parser.rst
+++ b/user_guide_src/source/libraries/parser.rst
@@ -2,24 +2,26 @@
Template Parser Class
#####################
-The Template Parser Class enables you to parse pseudo-variables
-contained within your view files. It can parse simple variables or
-variable tag pairs. If you've never used a template engine,
-pseudo-variables look like this::
+The Template Parser Class can perform simple text substitution for
+pseudo-variables contained within your view files.
+It can parse simple variables or variable tag pairs.
+
+If you've never used a template engine,
+pseudo-variable names are enclosed in braces, like this::
<html>
- <head>
- <title>{blog_title}</title>
- </head>
- <body>
-
- <h3>{blog_heading}</h3>
-
- {blog_entries}
- <h5>{title}</h5>
- <p>{body}</p>
- {/blog_entries}
- </body>
+ <head>
+ <title>{blog_title}</title>
+ </head>
+ <body>
+ <h3>{blog_heading}</h3>
+
+ {blog_entries}
+ <h5>{title}</h5>
+ <p>{body}</p>
+ {/blog_entries}
+
+ </body>
</html>
These variables are not actual PHP variables, but rather plain text
@@ -28,8 +30,9 @@ representations that allow you to eliminate PHP from your templates
.. note:: CodeIgniter does **not** require you to use this class since
using pure PHP in your view pages lets them run a little faster.
- However, some developers prefer to use a template engine if they work
- with designers who they feel would find some confusion working with PHP.
+ However, some developers prefer to use a template engine if
+ they work with designers who they feel would find some
+ confusion working with PHP.
.. important:: The Template Parser Class is **not** a full-blown
template parsing solution. We've kept it very lean on purpose in order
@@ -42,11 +45,15 @@ representations that allow you to eliminate PHP from your templates
<div class="custom-index container"></div>
+*******************************
+Using the Template Parser Class
+*******************************
+
Initializing the Class
======================
Like most other classes in CodeIgniter, the Parser class is initialized
-in your controller using the $this->load->library function::
+in your controller using the ``$this->load->library()`` method::
$this->load->library('parser');
@@ -56,12 +63,13 @@ $this->parser
Parsing templates
=================
-You can use the ``parse()`` method to parse (or render) simple templates, like this::
+You can use the ``parse()`` method to parse (or render) simple templates,
+like this::
$data = array(
- 'blog_title' => 'My Blog Title',
- 'blog_heading' => 'My Blog Heading'
- );
+ 'blog_title' => 'My Blog Title',
+ 'blog_heading' => 'My Blog Heading'
+ );
$this->parser->parse('blog_template', $data);
@@ -74,7 +82,7 @@ template would contain two variables: {blog_title} and {blog_heading}
There is no need to "echo" or do something with the data returned by
$this->parser->parse(). It is automatically passed to the output class
to be sent to the browser. However, if you do want the data returned
-instead of sent to the output class you can pass TRUE (boolean) to the
+instead of sent to the output class you can pass TRUE (boolean) as the
third parameter::
$string = $this->parser->parse('blog_template', $data, TRUE);
@@ -88,24 +96,24 @@ iteration containing new values? Consider the template example we showed
at the top of the page::
<html>
- <head>
- <title>{blog_title}</title>
- </head>
- <body>
-
- <h3>{blog_heading}</h3>
-
- {blog_entries}
- <h5>{title}</h5>
- <p>{body}</p>
- {/blog_entries}
- </body>
+ <head>
+ <title>{blog_title}</title>
+ </head>
+ <body>
+ <h3>{blog_heading}</h3>
+
+ {blog_entries}
+ <h5>{title}</h5>
+ <p>{body}</p>
+ {/blog_entries}
+
+ </body>
</html>
In the above code you'll notice a pair of variables: {blog_entries}
data... {/blog_entries}. In a case like this, the entire chunk of data
between these pairs would be repeated multiple times, corresponding to
-the number of rows in a result.
+the number of rows in the "blog_entries" element of the parameters array.
Parsing variable pairs is done using the identical code shown above to
parse single variables, except, you will add a multi-dimensional array
@@ -114,35 +122,156 @@ corresponding to your variable pair data. Consider this example::
$this->load->library('parser');
$data = array(
- 'blog_title' => 'My Blog Title',
- 'blog_heading' => 'My Blog Heading',
- 'blog_entries' => array(
- array('title' => 'Title 1', 'body' => 'Body 1'),
- array('title' => 'Title 2', 'body' => 'Body 2'),
- array('title' => 'Title 3', 'body' => 'Body 3'),
- array('title' => 'Title 4', 'body' => 'Body 4'),
- array('title' => 'Title 5', 'body' => 'Body 5')
- )
- );
+ 'blog_title' => 'My Blog Title',
+ 'blog_heading' => 'My Blog Heading',
+ 'blog_entries' => array(
+ array('title' => 'Title 1', 'body' => 'Body 1'),
+ array('title' => 'Title 2', 'body' => 'Body 2'),
+ array('title' => 'Title 3', 'body' => 'Body 3'),
+ array('title' => 'Title 4', 'body' => 'Body 4'),
+ array('title' => 'Title 5', 'body' => 'Body 5')
+ )
+ );
$this->parser->parse('blog_template', $data);
If your "pair" data is coming from a database result, which is already a
-multi-dimensional array, you can simply use the database result_array()
-function::
+multi-dimensional array, you can simply use the database ``result_array()``
+method::
$query = $this->db->query("SELECT * FROM blog");
$this->load->library('parser');
$data = array(
- 'blog_title' => 'My Blog Title',
- 'blog_heading' => 'My Blog Heading',
- 'blog_entries' => $query->result_array()
- );
+ 'blog_title' => 'My Blog Title',
+ 'blog_heading' => 'My Blog Heading',
+ 'blog_entries' => $query->result_array()
+ );
$this->parser->parse('blog_template', $data);
+Usage Notes
+===========
+
+If you include substitution parameters that are not referenced in your
+template, they are ignored::
+
+ $template = 'Hello, {firstname} {lastname}';
+ $data = array(
+ 'title' => 'Mr',
+ 'firstname' => 'John',
+ 'lastname' => 'Doe'
+ );
+ $this->parser->parse_string($template, $data);
+
+ // Result: Hello, John Doe
+
+If you do not include a substitution parameter that is referenced in your
+template, the original pseudo-variable is shown in the result::
+
+ $template = 'Hello, {firstname} {initials} {lastname}';
+ $data = array(
+ 'title' => 'Mr',
+ 'firstname' => 'John',
+ 'lastname' => 'Doe'
+ );
+ $this->parser->parse_string($template, $data);
+
+ // Result: Hello, John {initials} Doe
+
+If you provide a string substitution parameter when an array is expected,
+i.e. for a variable pair, the substitution is done for the opening variable
+pair tag, but the closing variable pair tag is not rendered properly::
+
+ $template = 'Hello, {firstname} {lastname} ({degrees}{degree} {/degrees})';
+ $data = array(
+ 'degrees' => 'Mr',
+ 'firstname' => 'John',
+ 'lastname' => 'Doe',
+ 'titles' => array(
+ array('degree' => 'BSc'),
+ array('degree' => 'PhD')
+ )
+ );
+ $this->parser->parse_string($template, $data);
+
+ // Result: Hello, John Doe (Mr{degree} {/degrees})
+
+If you name one of your individual substitution parameters the same as one
+used inside a variable pair, the results may not be as expected::
+
+ $template = 'Hello, {firstname} {lastname} ({degrees}{degree} {/degrees})';
+ $data = array(
+ 'degree' => 'Mr',
+ 'firstname' => 'John',
+ 'lastname' => 'Doe',
+ 'degrees' => array(
+ array('degree' => 'BSc'),
+ array('degree' => 'PhD')
+ )
+ );
+ $this->parser->parse_string($template, $data);
+
+ // Result: Hello, John Doe (Mr Mr )
+
+View Fragments
+==============
+
+You do not have to use variable pairs to get the effect of iteration in
+your views. It is possible to use a view fragment for what would be inside
+a variable pair, and to control the iteration in your controller instead
+of in the view.
+
+An example with the iteration controlled in the view::
+
+ $template = '<ul>{menuitems}
+ <li><a href="{link}">{title}</a></li>
+ {/menuitems}</ul>';
+
+ $data = array(
+ 'menuitems' => array(
+ array('title' => 'First Link', 'link' => '/first'),
+ array('title' => 'Second Link', 'link' => '/second'),
+ )
+ );
+ $this->parser->parse_string($template, $data);
+
+Result::
+
+ <ul>
+ <li><a href="/first">First Link</a></li>
+ <li><a href="/second">Second Link</a></li>
+ </ul>
+
+An example with the iteration controlled in the controller,
+using a view fragment::
+
+ $temp = '';
+ $template1 = '<li><a href="{link}">{title}</a></li>';
+ $data1 = array(
+ array('title' => 'First Link', 'link' => '/first'),
+ array('title' => 'Second Link', 'link' => '/second'),
+ );
+
+ foreach ($data1 as $menuitem)
+ {
+ $temp .= $this->parser->parse_string($template1, $menuitem, TRUE);
+ }
+
+ $template = '<ul>{menuitems}</ul>';
+ $data = array(
+ 'menuitems' => $temp
+ );
+ $this->parser->parse_string($template, $data);
+
+Result::
+
+ <ul>
+ <li><a href="/first">First Link</a></li>
+ <li><a href="/second">Second Link</a></li>
+ </ul>
+
***************
Class Reference
***************
@@ -167,8 +296,8 @@ Class Reference
:returns: Parsed template string
:rtype: string
- This method works exactly like ``parse()``, only it accepts the template as a
- string instead of loading a view file.
+ This method works exactly like ``parse()``, only it accepts
+ the template as a string instead of loading a view file.
.. method:: set_delimiters([$l = '{'[, $r = '}']])
@@ -176,4 +305,5 @@ Class Reference
:param string $r: Right delimiter
:rtype: void
- Sets the delimiters (opening and closing) for a value "tag" in a template. \ No newline at end of file
+ Sets the delimiters (opening and closing) for a
+ pseudo-variable "tag" in a template. \ No newline at end of file
diff --git a/user_guide_src/source/libraries/security.rst b/user_guide_src/source/libraries/security.rst
index 0c51e342b..a39ef5976 100644
--- a/user_guide_src/source/libraries/security.rst
+++ b/user_guide_src/source/libraries/security.rst
@@ -12,8 +12,9 @@ application, processing input data for security.
<div class="custom-index container"></div>
+*************
XSS Filtering
-=============
+*************
CodeIgniter comes with a Cross Site Scripting Hack prevention filter
which can either run automatically to filter all POST and COOKIE data
@@ -57,8 +58,9 @@ browser may attempt to execute.
// file failed the XSS test
}
+*********************************
Cross-site request forgery (CSRF)
-=================================
+*********************************
You can enable CSRF protection by altering your **application/config/config.php**
file in the following way::
diff --git a/user_guide_src/source/libraries/unit_testing.rst b/user_guide_src/source/libraries/unit_testing.rst
index 0bc860f61..7e91a7b95 100644
--- a/user_guide_src/source/libraries/unit_testing.rst
+++ b/user_guide_src/source/libraries/unit_testing.rst
@@ -18,6 +18,10 @@ code to determine if it is producing the correct data type and result.
<div class="custom-index container"></div>
+******************************
+Using the Unit Testing Library
+******************************
+
Initializing the Class
======================
diff --git a/user_guide_src/source/libraries/zip.rst b/user_guide_src/source/libraries/zip.rst
index 4ca14086a..b509236de 100644
--- a/user_guide_src/source/libraries/zip.rst
+++ b/user_guide_src/source/libraries/zip.rst
@@ -25,7 +25,9 @@ your controller using the $this->load->library function::
$this->load->library('zip');
-Once loaded, the Zip library object will be available using: $this->zip
+Once loaded, the Zip library object will be available using:
+
+ $this->zip
Usage Example
=============
@@ -41,7 +43,7 @@ your server, and download it to your desktop.
$this->zip->add_data($name, $data);
// Write the zip file to a folder on your server. Name it "my_backup.zip"
- $this->zip->archive('/path/to/directory/my_backup.zip');
+ $this->zip->archive('/path/to/directory/my_backup.zip');
// Download the file to your desktop. Name it "my_backup.zip"
$this->zip->download('my_backup.zip');
@@ -52,6 +54,14 @@ Class Reference
.. class:: CI_Zip
+ .. attribute:: $compression_level = 2
+
+ The compression level to use.
+
+ It can range from 0 to 9, with 9 being the highest and 0 effectively disabling compression::
+
+ $this->zip->compression_level = 0;
+
.. method:: add_data($filepath[, $data = NULL])
:param mixed $filepath: A single file path or an array of file => data pairs
@@ -60,7 +70,8 @@ Class Reference
Adds data to the Zip archive. Can work both in single and multiple files mode.
- When adding a single file, the first parameter must contain the name you would like given to the file and the second must contain the file contents::
+ When adding a single file, the first parameter must contain the name you would
+ like given to the file and the second must contain the file contents::
$name = 'mydata1.txt';
$data = 'A Data String!';
@@ -69,8 +80,9 @@ Class Reference
$name = 'mydata2.txt';
$data = 'Another Data String!';
$this->zip->add_data($name, $data);
-
- When adding multiple files, the first parameter must contain *file => contents* pairs and the second parameter is ignored::
+
+ When adding multiple files, the first parameter must contain *file => contents* pairs
+ and the second parameter is ignored::
$data = array(
'mydata1.txt' => 'A Data String!',
@@ -79,7 +91,8 @@ Class Reference
$this->zip->add_data($data);
- If you would like your compressed data organized into sub-directories, simply include the path as part of the filename(s)::
+ If you would like your compressed data organized into sub-directories, simply include
+ the path as part of the filename(s)::
$name = 'personal/my_bio.txt';
$data = 'I was born in an elevator...';
@@ -93,8 +106,9 @@ Class Reference
:param mixed $directory: Directory name string or an array of multiple directories
:rtype: void
- Permits you to add a directory. Usually this method is unnecessary since you can place your data into directories when using
- ``$this->zip->add_data()``, but if you would like to create an empty directory you can do so::
+ Permits you to add a directory. Usually this method is unnecessary since you can place
+ your data into directories when using ``$this->zip->add_data()``, but if you would like
+ to create an empty directory you can do so::
$this->zip->add_dir('myfolder'); // Creates a directory called "myfolder"
@@ -110,7 +124,7 @@ Class Reference
$path = '/path/to/photo.jpg';
- $this->zip->read_file($path);
+ $this->zip->read_file($path);
// Download the file to your desktop. Name it "my_backup.zip"
$this->zip->download('my_backup.zip');
@@ -120,7 +134,7 @@ Class Reference
$path = '/path/to/photo.jpg';
- $this->zip->read_file($path, TRUE);
+ $this->zip->read_file($path, TRUE);
// Download the file to your desktop. Name it "my_backup.zip"
$this->zip->download('my_backup.zip');
@@ -151,20 +165,21 @@ Class Reference
$path = '/path/to/your/directory/';
- $this->zip->read_dir($path);
+ $this->zip->read_dir($path);
// Download the file to your desktop. Name it "my_backup.zip"
$this->zip->download('my_backup.zip');
- By default the Zip archive will place all directories listed in the first parameter inside the zip.
- If you want the tree preceding the target directory to be ignored you can pass FALSE (boolean) in the second parameter. Example::
+ By default the Zip archive will place all directories listed in the first parameter
+ inside the zip. If you want the tree preceding the target directory to be ignored,
+ you can pass FALSE (boolean) in the second parameter. Example::
$path = '/path/to/your/directory/';
$this->zip->read_dir($path, FALSE);
- This will create a ZIP with a directory named "directory" inside, then all sub-directories stored correctly inside that, but will not include the
- */path/to/your* part of the path.
+ This will create a ZIP with a directory named "directory" inside, then all sub-directories
+ stored correctly inside that, but will not include the */path/to/your* part of the path.
.. method:: archive($filepath)
@@ -172,8 +187,9 @@ Class Reference
:returns: TRUE on success, FALSE on failure
:rtype: bool
- Writes the Zip-encoded file to a directory on your server. Submit a valid server path ending in the file name.
- Make sure the directory is writable (755 is usually OK). Example::
+ Writes the Zip-encoded file to a directory on your server. Submit a valid server path
+ ending in the file name. Make sure the directory is writable (755 is usually OK).
+ Example::
$this->zip->archive('/path/to/folder/myarchive.zip'); // Creates a file named myarchive.zip
@@ -182,7 +198,8 @@ Class Reference
:param string $filename: Archive file name
:rtype: void
- Causes the Zip file to be downloaded from your server. You must pass the name you would like the zip file called. Example::
+ Causes the Zip file to be downloaded from your server.
+ You must pass the name you would like the zip file called. Example::
$this->zip->download('latest_stuff.zip'); // File will be named "latest_stuff.zip"
@@ -195,7 +212,8 @@ Class Reference
:returns: Zip file content
:rtype: string
- Returns the Zip-compressed file data. Generally you will not need this method unless you want to do something unique with the data. Example::
+ Returns the Zip-compressed file data. Generally you will not need this method unless you
+ want to do something unique with the data. Example::
$name = 'my_bio.txt';
$data = 'I was born in an elevator...';
@@ -208,8 +226,9 @@ Class Reference
:rtype: void
- The Zip class caches your zip data so that it doesn't need to recompile the Zip archive for each method you use above.
- If, however, you need to create multiple Zip archives, each with different data, you can clear the cache between calls. Example::
+ The Zip class caches your zip data so that it doesn't need to recompile the Zip archive
+ for each method you use above. If, however, you need to create multiple Zip archives,
+ each with different data, you can clear the cache between calls. Example::
$name = 'my_bio.txt';
$data = 'I was born in an elevator...';
@@ -217,9 +236,9 @@ Class Reference
$this->zip->add_data($name, $data);
$zip_file = $this->zip->get_zip();
- $this->zip->clear_data();
+ $this->zip->clear_data();
$name = 'photo.jpg';
$this->zip->read_file("/path/to/photo.jpg"); // Read the file's contents
- $this->zip->download('myphotos.zip'); \ No newline at end of file
+ $this->zip->download('myphotos.zip');