diff options
Diffstat (limited to 'user_guide_src/source/libraries')
-rw-r--r-- | user_guide_src/source/libraries/cart.rst | 3 | ||||
-rw-r--r-- | user_guide_src/source/libraries/encryption.rst | 1 | ||||
-rw-r--r-- | user_guide_src/source/libraries/form_validation.rst | 8 | ||||
-rw-r--r-- | user_guide_src/source/libraries/input.rst | 28 | ||||
-rw-r--r-- | user_guide_src/source/libraries/javascript.rst | 8 | ||||
-rw-r--r-- | user_guide_src/source/libraries/language.rst | 82 | ||||
-rw-r--r-- | user_guide_src/source/libraries/loader.rst | 3 | ||||
-rw-r--r-- | user_guide_src/source/libraries/parser.rst | 202 | ||||
-rw-r--r-- | user_guide_src/source/libraries/security.rst | 6 | ||||
-rw-r--r-- | user_guide_src/source/libraries/unit_testing.rst | 4 | ||||
-rw-r--r-- | user_guide_src/source/libraries/zip.rst | 65 |
11 files changed, 229 insertions, 181 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 112347129..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 ======================================= @@ -136,15 +144,17 @@ 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]]) @@ -167,15 +177,17 @@ 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]) @@ -218,10 +230,11 @@ 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]) @@ -239,7 +252,8 @@ Class Reference To return an array of multiple ``$_SERVER`` values, pass all the required keys as an array. :: - $this->input->server(array('SERVER_PROTOCOL', 'REQUEST_URI')); + + $this->input->server(array('SERVER_PROTOCOL', 'REQUEST_URI')); .. method:: input_stream([$index = NULL[, $xss_clean = NULL]]) @@ -437,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 c3f9b6d5a..e833d9757 100644 --- a/user_guide_src/source/libraries/language.rst +++ b/user_guide_src/source/libraries/language.rst @@ -5,26 +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 will find a **language** -subfolder containing a set of language files for the **english** idiom. -The files in this folder (**system/language/english/**) define the regular messages, +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 core framework. +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 folder, -with separate subfolders for each idiom (for instance french or german). +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 +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. +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 @@ -41,7 +40,7 @@ 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 +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 @@ -58,45 +57,46 @@ 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 - ... + 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('nessage_key'); + $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 multiple -languages 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>`_. +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. +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! 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/parser.rst b/user_guide_src/source/libraries/parser.rst index e7c7e3abd..d66684d9b 100644 --- a/user_guide_src/source/libraries/parser.rst +++ b/user_guide_src/source/libraries/parser.rst @@ -10,18 +10,18 @@ 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 @@ -30,8 +30,8 @@ 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 + 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 @@ -53,7 +53,7 @@ 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'); @@ -63,12 +63,12 @@ $this->parser Parsing templates ================= -You can use the ``parse()`` method to parse (or render) simple templates, +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); @@ -96,18 +96,18 @@ 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} @@ -122,31 +122,31 @@ 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); @@ -154,94 +154,95 @@ function:: Usage Notes =========== -If you include substitution parameters that are not referenced in your +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' + 'title' => 'Mr', + 'firstname' => 'John', + 'lastname' => 'Doe' ); $this->parser->parse_string($template, $data); - Result: Hello, John Doe + // Result: Hello, John Doe -If you do not include a substitution parameter that is referenced in your +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' + 'title' => 'Mr', + 'firstname' => 'John', + 'lastname' => 'Doe' ); $this->parser->parse_string($template, $data); - Result: Hello, John {initials} Doe + // Result: Hello, John {initials} Doe -If you provide a string substitution parameter when an array is expected, +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') - - ) + '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}) + // 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:: +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') - - ) + '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 ) + // 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 +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>'; + <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'), - ) + 'menuitems' => array( + array('title' => 'First Link', 'link' => '/first'), + array('title' => 'Second Link', 'link' => '/second'), + ) ); $this->parser->parse_string($template, $data); - Result: - - First Link - - Second Link +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:: @@ -252,19 +253,24 @@ using a view fragment:: array('title' => 'First Link', 'link' => '/first'), array('title' => 'Second Link', 'link' => '/second'), ); - foreach ($data1 as $menuitem) { - $temp .= $this->parser->parse_string($template1, $menuitem, TRUE); + + foreach ($data1 as $menuitem) + { + $temp .= $this->parser->parse_string($template1, $menuitem, TRUE); } $template = '<ul>{menuitems}</ul>'; $data = array( - 'menuitems' => $temp + 'menuitems' => $temp ); $this->parser->parse_string($template, $data); - Result: - - First Link - - Second Link +Result:: + + <ul> + <li><a href="/first">First Link</a></li> + <li><a href="/second">Second Link</a></li> + </ul> *************** Class Reference @@ -290,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 = '}']]) @@ -299,5 +305,5 @@ Class Reference :param string $r: Right delimiter :rtype: void - Sets the delimiters (opening and closing) for a - pseudo-variable "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'); |