diff options
Diffstat (limited to 'user_guide_src')
21 files changed, 167 insertions, 112 deletions
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 2d10f8f96..3a1804835 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -11,10 +11,25 @@ Release Date: Not Released - Added DoS mitigation to :php:func:`hash_pbkdf2()` :doc:`compatibility function <general/compatibility_functions>`. -- Database +- Database - Added ``list_fields()`` support for SQLite ('sqlite3' and 'pdo_sqlite' drivers). +- Libraries + + - :doc:`File Uploading Library <libraries/file_uploading>` changes: + + - Changed method ``set_error()`` to accept a custom log level (defaults to 'error'). + - Errors "no_file_selected", "file_partial", "stopped_by_extension", "no_file_types", "invalid_filetype", "bad_filename" are now logged at the 'debug' level. + - Errors "file_exceeds_limit", "file_exceeds_form_limit", "invalid_filesize", "invalid_dimensions" are now logged at the 'info' level. + + - Added 'is_resource' to the available expectations in :doc:`Unit Testing Library <libraries/unit_testing>`. + +- Helpers + + - Added Unicode support to :doc:`URL Helper <helpers/url_helper>` function :php:func:`url_title()`. + - Added support for passing the "extra" parameter as an array to all :doc:`Form Helper <helpers/form_helper>` functions that use it. + Bug fixes for 3.0.1 ------------------- @@ -22,11 +37,27 @@ Bug fixes for 3.0.1 - Fixed a bug (#3744) - Redis :doc:`Caching <libraries/caching>` driver didn't handle authentication failures properly. - Fixed a bug (#3761) - :doc:`URL Helper <helpers/url_helper>` function :php:func:`anchor()` didn't work with array inputs. - Fixed a bug (#3773) - ``db_select()`` didn't work for MySQL with the PDO :doc:`Database <database/index>` driver. -- Fixed a bug (#3771) - :doc:`Form Validation Library <libraries/form_validation>` was looking for a 'form_validation_' prefix when trying to translate field name labels. +- Fixed a bug (#3771) - :doc:`Form Validation Library <libraries/form_validation>` was looking for a 'form_validation\_' prefix when trying to translate field name labels. - Fixed a bug (#3787) - :doc:`FTP Library <libraries/ftp>` method ``delete_dir()`` failed when the target has subdirectories. - Fixed a bug (#3801) - :doc:`Output Library <libraries/output>` method ``_display_cache()`` incorrectly looked for the last modified time of a directory instead of the cache file. - Fixed a bug (#3816) - :doc:`Form Validation Library <libraries/form_validation>` treated empty string values as non-existing ones. - Fixed a bug (#3823) - :doc:`Session Library <libraries/sessions>` drivers Redis and Memcached didn't properly handle locks that are blocking the request for more than 30 seconds. +- Fixed a bug (#3846) - :doc:`Image Manipulation Library <libraries/image_lib>` method `image_mirror_gd()` didn't properly initialize its variables. +- Fixed a bug (#3854) - `field_data()` didn't work properly with the Oracle (OCI8) database driver. +- Fixed a bug in the :doc:`Database Utility Class <database/utilities>` method ``csv_from_result()`` didn't work with a whitespace CSV delimiter. +- Fixed a bug (#3890) - :doc:`Input Library <libraries/input>` method ``get_request_header()`` treated header names as case-sensitive. +- Fixed a bug (#3903) - :doc:`Form Validation Library <libraries/form_validation>` ignored "unnamed" closure validation rules. +- Fixed a bug (#3904) - :doc:`Form Validation Library <libraries/form_validation>` ignored "named" callback rules when the field is empty and there's no 'required' rule. +- Fixed a bug (#3922) - :doc:`Email <libraries/email>` and :doc:`XML-RPC <libraries/xmlrpc>` libraries could enter an infinite loop due to `PHP bug #39598 <https://bugs.php.net/bug.php?id=39598>`_. +- Fixed a bug (#3913) - :doc:`Cache Library <libraries/caching>` didn't work with the direct ``$this->cache->$driver_name->method()`` syntax with Redis and Memcache(d). +- Fixed a bug (#3932) - :doc:`Query Builder <database/query_builder>` didn't properly compile WHERE and HAVING conditions for field names that end with "and", "or". +- Fixed a bug in :doc:`Query Builder <database/query_builder>` where ``delete()`` didn't properly work on multiple tables with a WHERE condition previously set via ``where()``. +- Fixed a bug (#3952) - :doc:`Database <database/index>` method ``list_fields()`` didn't work with SQLite3. +- Fixed a bug (#3955) - :doc:`Cache Library <libraries/caching>` methods ``increment()`` and ``decrement()`` ignored the 'key_prefix' setting. +- Fixed a bug (#3963) - :doc:`Unit Testing Library <libraries/unit_testing>` wrongly tried to translate filenames, line numbers and notes values in test results. +- Fixed a bug (#3965) - :doc:`File Uploading Library <libraries/file_uploading>` ignored the "encrypt_name" setting when "overwrite" is enabled. +- Fixed a bug (#3968) - :doc:`Database Forge <database/forge>` method ``add_key()`` didn't treat array inputs as composite keys unless it's a PRIMARY KEY. +- Fixed a bug (#3715) - :doc:`Pagination Library <libraries/pagination>` could generate broken link when a protocol-relative base URL is used. Version 3.0.0 ============= diff --git a/user_guide_src/source/database/forge.rst b/user_guide_src/source/database/forge.rst index a4edada5c..646e3a56e 100644 --- a/user_guide_src/source/database/forge.rst +++ b/user_guide_src/source/database/forge.rst @@ -143,13 +143,15 @@ string into the field definitions with add_field() $this->dbforge->add_field("label varchar(100) NOT NULL DEFAULT 'default label'"); +.. note:: Passing raw strings as fields cannot be followed by ``add_key()`` calls on those fields. + .. note:: Multiple calls to add_field() are cumulative. Creating an id field -------------------- There is a special exception for creating id fields. A field with type -id will automatically be assinged as an INT(9) auto_incrementing +id will automatically be assigned as an INT(9) auto_incrementing Primary Key. :: diff --git a/user_guide_src/source/database/utilities.rst b/user_guide_src/source/database/utilities.rst index cc4aeb018..2fa5239c8 100644 --- a/user_guide_src/source/database/utilities.rst +++ b/user_guide_src/source/database/utilities.rst @@ -18,7 +18,7 @@ Initializing the Utility Class Load the Utility Class as follows:: - $this->load->dbutil() + $this->load->dbutil(); You can also pass another database object to the DB Utility loader, in case the database you want to manage isn't the default one:: @@ -35,7 +35,7 @@ assigning it directly to ``$this->dbutil``. Once initialized you will access the methods using the ``$this->dbutil`` object:: - $this->dbutil->some_method() + $this->dbutil->some_method(); **************************** Using the Database Utilities @@ -180,7 +180,7 @@ backup data can be compressed in either Zip or Gzip format. .. note:: For Interbase/Firebird databases, the backup file name is the only parameter. - Eg. $this->dbutil->backup('db_backup_filename'); + $this->dbutil->backup('db_backup_filename'); .. note:: Due to the limited execution time and memory available to PHP, backing up very large databases may not be possible. If your database is @@ -197,7 +197,7 @@ Usage Example $this->load->dbutil(); // Backup your entire database and assign it to a variable - $backup =& $this->dbutil->backup(); + $backup = $this->dbutil->backup(); // Load the file helper and write the file to your server $this->load->helper('file'); diff --git a/user_guide_src/source/general/environments.rst b/user_guide_src/source/general/environments.rst index f5a4f617e..7f030b6ef 100644 --- a/user_guide_src/source/general/environments.rst +++ b/user_guide_src/source/general/environments.rst @@ -48,5 +48,5 @@ Configuration Files Optionally, you can have CodeIgniter load environment-specific configuration files. This may be useful for managing things like differing API keys across multiple environments. This is described in -more detail in the environment section of the :doc:`Config -Class <../libraries/config#environments>`_ documentation.
\ No newline at end of file +more detail in the environment section of the :doc:`Config Class +<../libraries/config>`_ documentation.
\ No newline at end of file diff --git a/user_guide_src/source/general/reserved_names.rst b/user_guide_src/source/general/reserved_names.rst index a7b0c3465..5d745cba6 100644 --- a/user_guide_src/source/general/reserved_names.rst +++ b/user_guide_src/source/general/reserved_names.rst @@ -75,6 +75,7 @@ Constants - FOPEN_READ_WRITE_CREATE - FOPEN_WRITE_CREATE_STRICT - FOPEN_READ_WRITE_CREATE_STRICT +- SHOW_DEBUG_BACKTRACE - EXIT_SUCCESS - EXIT_ERROR - EXIT_CONFIG diff --git a/user_guide_src/source/general/security.rst b/user_guide_src/source/general/security.rst index fcfe4c24b..d4120d162 100644 --- a/user_guide_src/source/general/security.rst +++ b/user_guide_src/source/general/security.rst @@ -61,7 +61,7 @@ data from the SERVER array, you are encouraged to practice this three step approach: #. Validate the data to ensure it conforms to the correct type, length, - size, etc. (sometimes this step can replace step one) + size, etc. #. Filter the data as if it were tainted. #. Escape the data before submitting it into your database or outputting it to a browser. @@ -199,4 +199,4 @@ file to restrict access to those resources. CodeIgniter will have an index.html file in all of its directories in an attempt to hide some of this data, but have it in mind that this is not enough to prevent a serious -attacker.
\ No newline at end of file +attacker. diff --git a/user_guide_src/source/helpers/form_helper.rst b/user_guide_src/source/helpers/form_helper.rst index 9ddca89bc..6317f08ed 100644 --- a/user_guide_src/source/helpers/form_helper.rst +++ b/user_guide_src/source/helpers/form_helper.rst @@ -191,7 +191,7 @@ The following functions are available: :param array $data: Field attributes data :param string $value: Field value - :param string $extra: Extra attributes to be added to the tag *as is* + :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string :returns: An HTML text input field tag :rtype: string @@ -226,11 +226,16 @@ The following functions are available: $js = 'onClick="some_function()"'; echo form_input('username', 'johndoe', $js); + Or you can pass it as an array:: + + $js = array('onClick' => 'some_function();'); + echo form_input('username', 'johndoe', $js); + .. php:function:: form_password([$data = ''[, $value = ''[, $extra = '']]]) :param array $data: Field attributes data :param string $value: Field value - :param string $extra: Extra attributes to be added to the tag *as is* + :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string :returns: An HTML password input field tag :rtype: string @@ -242,7 +247,7 @@ The following functions are available: :param array $data: Field attributes data :param string $value: Field value - :param string $extra: Extra attributes to be added to the tag *as is* + :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string :returns: An HTML file upload input field tag :rtype: string @@ -255,7 +260,7 @@ The following functions are available: :param array $data: Field attributes data :param string $value: Field value - :param string $extra: Extra attributes to be added to the tag *as is* + :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string :returns: An HTML textarea tag :rtype: string @@ -270,7 +275,7 @@ The following functions are available: :param string $name: Field name :param array $options: An associative array of options to be listed :param array $selected: List of fields to mark with the *selected* attribute - :param string $extra: Extra attributes to be added to the tag *as is* + :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string :returns: An HTML dropdown select field tag :rtype: string @@ -324,6 +329,14 @@ The following functions are available: $js = 'id="shirts" onChange="some_function();"'; echo form_dropdown('shirts', $options, 'large', $js); + Or you can pass it as an array:: + + $js = array( + 'id' => 'shirts', + 'onChange' => 'some_function();' + ); + echo form_dropdown('shirts', $options, 'large', $js); + If the array passed as ``$options`` is a multidimensional array, then ``form_dropdown()`` will produce an <optgroup> with the array key as the label. @@ -334,7 +347,7 @@ The following functions are available: :param string $name: Field name :param array $options: An associative array of options to be listed :param array $selected: List of fields to mark with the *selected* attribute - :param string $extra: Extra attributes to be added to the tag *as is* + :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string :returns: An HTML dropdown multiselect field tag :rtype: string @@ -417,7 +430,7 @@ The following functions are available: :param array $data: Field attributes data :param string $value: Field value :param bool $checked: Whether to mark the checkbox as being *checked* - :param string $extra: Extra attributes to be added to the tag *as is* + :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string :returns: An HTML checkbox input tag :rtype: string @@ -450,13 +463,18 @@ The following functions are available: $js = 'onClick="some_function()"'; echo form_checkbox('newsletter', 'accept', TRUE, $js) + Or you can pass it as an array:: + + $js = array('onClick' => 'some_function();'); + echo form_checkbox('newsletter', 'accept', TRUE, $js) + .. php:function:: form_radio([$data = ''[, $value = ''[, $checked = FALSE[, $extra = '']]]]) :param array $data: Field attributes data :param string $value: Field value :param bool $checked: Whether to mark the radio button as being *checked* - :param string $extra: Extra attributes to be added to the tag *as is* + :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string :returns: An HTML radio input tag :rtype: string @@ -495,7 +513,7 @@ The following functions are available: :param string $data: Button name :param string $value: Button value - :param string $extra: Extra attributes to be added to the tag *as is* + :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string :returns: An HTML input submit tag :rtype: string @@ -513,7 +531,7 @@ The following functions are available: :param string $data: Button name :param string $value: Button value - :param string $extra: Extra attributes to be added to the tag *as is* + :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string :returns: An HTML input reset button tag :rtype: string @@ -525,7 +543,7 @@ The following functions are available: :param string $data: Button name :param string $content: Button label - :param string $extra: Extra attributes to be added to the tag *as is* + :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string :returns: An HTML button tag :rtype: string diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst index a3d712482..de816b6c7 100644 --- a/user_guide_src/source/installation/upgrade_300.rst +++ b/user_guide_src/source/installation/upgrade_300.rst @@ -8,9 +8,13 @@ Before performing an update you should take your site offline by replacing the i Step 1: Update your CodeIgniter files ************************************* -Replace all files and directories in your "system" folder and replace -your index.php file. If any modifications were made to your index.php -they will need to be made fresh in this new one. +**Replace** all files and directories in your *system/* directory and +replace your index.php file. If any modifications were made to your +index.php they will need to be made fresh in this new one. + +.. important:: You have to delete the old *system/* directory first and + then put the new one in its place. A simple copy-paste may cause + issues. .. note:: If you have any custom developed files in these folders please make copies of them first. @@ -34,12 +38,12 @@ For example, if you have the following library file: The same goes for driver libraries and extensions and/or overrides of CodeIgniter's own libraries and core classes. - application/libraries/MY_email.php + application/libraries/MY_email.php application/core/MY_log.php The above files should respectively be renamed to the following: - application/libraries/MY_Email.php + application/libraries/MY_Email.php application/core/MY_Log.php Controllers: @@ -76,9 +80,9 @@ Step 5: Move your Log class overrides or extensions The Log Class is considered as a "core" class and is now located in the **system/core/** directory. Therefore, in order for your Log class overrides -or extensions to work, you need to move them to **application/core/**:: +or extensions to work, you need to move them to **application/core/**: - application/libraries/Log.php -> application/core/Log.php + application/libraries/Log.php -> application/core/Log.php application/libraries/MY_Log.php -> application/core/MY_Log.php ***************************************** diff --git a/user_guide_src/source/libraries/caching.rst b/user_guide_src/source/libraries/caching.rst index f54de5faf..a7081ec6b 100644 --- a/user_guide_src/source/libraries/caching.rst +++ b/user_guide_src/source/libraries/caching.rst @@ -18,7 +18,7 @@ requirements are not met. Example Usage ************* -The following example will load the cache driver, specify `APC <#apc>`_ +The following example will load the cache driver, specify `APC <#alternative-php-cache-apc-caching>`_ as the driver to use, and fall back to file-based caching if APC is not available in the hosting environment. @@ -66,7 +66,7 @@ Class Reference hosting environment. :: - if ($this->cache->apc->is_supported() + if ($this->cache->apc->is_supported()) { if ($data = $this->cache->apc->get('my_cache')) { diff --git a/user_guide_src/source/libraries/config.rst b/user_guide_src/source/libraries/config.rst index 3138e3403..a45cacdf5 100644 --- a/user_guide_src/source/libraries/config.rst +++ b/user_guide_src/source/libraries/config.rst @@ -92,9 +92,9 @@ Fetching Config Items To retrieve an item from your config file, use the following function:: - $this->config->item('item name'); + $this->config->item('item_name'); -Where item name is the $config array index you want to retrieve. For +Where item_name is the $config array index you want to retrieve. For example, to fetch your language choice you'll do this:: $lang = $this->config->item('language'); diff --git a/user_guide_src/source/libraries/email.rst b/user_guide_src/source/libraries/email.rst index 54fb53f44..eadfcfd5c 100644 --- a/user_guide_src/source/libraries/email.rst +++ b/user_guide_src/source/libraries/email.rst @@ -373,7 +373,7 @@ Class Reference foreach ($list as $address) { $this->email->to($address); - $cid = $this->email->attach_cid($filename); + $cid = $this->email->attachment_cid($filename); $this->email->message('<img src='cid:". $cid ."' alt="photo1" />'); $this->email->send(); } diff --git a/user_guide_src/source/libraries/file_uploading.rst b/user_guide_src/source/libraries/file_uploading.rst index ea2fef7f2..6d2106be8 100644 --- a/user_guide_src/source/libraries/file_uploading.rst +++ b/user_guide_src/source/libraries/file_uploading.rst @@ -118,7 +118,7 @@ this code and save it to your **application/controllers/** directory:: $this->load->library('upload', $config); - if ( ! $this->upload->do_upload()) + if ( ! $this->upload->do_upload('userfile')) { $error = array('error' => $this->upload->display_errors()); @@ -352,4 +352,4 @@ Class Reference image_height Image height image_type Image type (usually the file name extension without the period) image_size_str A string containing the width and height (useful to put into an image tag) - ================ ====================================================================================================
\ No newline at end of file + ================ ==================================================================================================== diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst index da43a4bec..fa50c6dcf 100644 --- a/user_guide_src/source/libraries/form_validation.rst +++ b/user_guide_src/source/libraries/form_validation.rst @@ -327,15 +327,15 @@ 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]'); - $this->form_validation->set_rules('password', 'Password', 'trim|required|md5'); + $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[8]'); $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, checking for length -where necessary and converting the password to MD5. +where necessary and making sure that both password fields match. **Any native PHP function that accepts one parameter can be used as a -rule, like htmlspecialchars, trim, md5, etc.** +rule, like ``htmlspecialchars()``, ``trim()``, etc.** .. note:: You will generally want to use the prepping functions **after** the validation rules so if there is an error, the @@ -946,6 +946,7 @@ Rule Parameter Description ========================= ========== ============================================================================================= ======================= **required** No Returns FALSE if the form element is empty. **matches** Yes Returns FALSE if the form element does not match the one in the parameter. matches[form_item] +**regex_match** Yes Returns FALSE if the form element does not match the regular expression. regex_match[/regex/] **differs** Yes Returns FALSE if the form element does not differ from the one in the parameter. differs[form_item] **is_unique** Yes Returns FALSE if the form element is not unique to the table and field name in the is_unique[table.field] parameter. Note: This rule requires :doc:`Query Builder <../database/query_builder>` to be diff --git a/user_guide_src/source/libraries/image_lib.rst b/user_guide_src/source/libraries/image_lib.rst index ae2c8478e..e5f7c000f 100644 --- a/user_guide_src/source/libraries/image_lib.rst +++ b/user_guide_src/source/libraries/image_lib.rst @@ -89,7 +89,7 @@ If they fail you can retrieve the error message using this function:: echo $this->image_lib->display_errors(); -A good practice is use the processing function conditionally, showing an +A good practice is to use the processing function conditionally, showing an error upon failure, like this:: if ( ! $this->image_lib->resize()) @@ -187,7 +187,7 @@ Two Types of Watermarking There are two types of watermarking that you can use: -- **Text**: The watermark message will be generating using text, either +- **Text**: The watermark message will be generated using text, either with a True Type font that you specify, or using the native text output that the GD library supports. If you use the True Type version your GD installation must be compiled with True Type support (most @@ -231,7 +231,7 @@ bottom/center of the image, 20 pixels from the bottom of the image. Watermarking Preferences ======================== -This table shown the preferences that are available for both types of +This table shows the preferences that are available for both types of watermarking (text or overlay) ======================= =================== ======================= ========================================================================== @@ -264,7 +264,7 @@ Preference Default Value Options Description Text Preferences ---------------- -This table shown the preferences that are available for the text type of +This table shows the preferences that are available for the text type of watermarking. ======================= =================== =================== ========================================================================== @@ -289,7 +289,7 @@ Preference Default Value Options Description Overlay Preferences ------------------- -This table shown the preferences that are available for the overlay type +This table shows the preferences that are available for the overlay type of watermarking. ======================= =================== =================== ========================================================================== diff --git a/user_guide_src/source/libraries/migration.rst b/user_guide_src/source/libraries/migration.rst index 9eb9b78b1..97c72303c 100644 --- a/user_guide_src/source/libraries/migration.rst +++ b/user_guide_src/source/libraries/migration.rst @@ -164,7 +164,7 @@ Class Reference .. php:method:: latest() - :returns: TRUE if no migrations are found, current version string on success, FALSE on failure + :returns: Current version string on success, FALSE on failure :rtype: mixed This works much the same way as ``current()`` but instead of looking for diff --git a/user_guide_src/source/libraries/security.rst b/user_guide_src/source/libraries/security.rst index 16b397994..305a8e57c 100644 --- a/user_guide_src/source/libraries/security.rst +++ b/user_guide_src/source/libraries/security.rst @@ -35,12 +35,6 @@ To filter data through the XSS filter use the ``xss_clean()`` method:: $data = $this->security->xss_clean($data); -If you want the filter to run automatically every time it encounters -POST or COOKIE data you can enable it by opening your -application/config/config.php file and setting this:: - - $config['global_xss_filtering'] = TRUE; - An optional second parameter, *is_image*, allows this function to be used to test images for potential XSS attacks, useful for file upload security. When this second parameter is set to TRUE, instead of diff --git a/user_guide_src/source/libraries/unit_testing.rst b/user_guide_src/source/libraries/unit_testing.rst index 026781cb7..57934cba3 100644 --- a/user_guide_src/source/libraries/unit_testing.rst +++ b/user_guide_src/source/libraries/unit_testing.rst @@ -76,6 +76,7 @@ result. Here is a list of allowed comparison types: - is_double - is_array - is_null +- is_resource Generating Reports ================== diff --git a/user_guide_src/source/overview/at_a_glance.rst b/user_guide_src/source/overview/at_a_glance.rst index facbedaee..ce195c211 100644 --- a/user_guide_src/source/overview/at_a_glance.rst +++ b/user_guide_src/source/overview/at_a_glance.rst @@ -16,8 +16,8 @@ for a given task. CodeIgniter is Free =================== -CodeIgniter is licensed under an Apache/BSD-style open source license so -you can use it however you please. For more information please read the +CodeIgniter is licensed under the MIT license so you can use it however +you please. For more information please read the :doc:`license agreement <../license>`. CodeIgniter is Light Weight diff --git a/user_guide_src/source/tutorial/create_news_items.rst b/user_guide_src/source/tutorial/create_news_items.rst index 71d2080af..5c5270472 100644 --- a/user_guide_src/source/tutorial/create_news_items.rst +++ b/user_guide_src/source/tutorial/create_news_items.rst @@ -18,11 +18,11 @@ application/views/news/create.php. :: - <h2><?php echo $title ?></h2> + <h2><?php echo $title; ?></h2> <?php echo validation_errors(); ?> - <?php echo form_open('news/create') ?> + <?php echo form_open('news/create'); ?> <label for="title">Title</label> <input type="input" name="title" /><br /> diff --git a/user_guide_src/source/tutorial/news_section.rst b/user_guide_src/source/tutorial/news_section.rst index d8ebac4a3..286d620dc 100644 --- a/user_guide_src/source/tutorial/news_section.rst +++ b/user_guide_src/source/tutorial/news_section.rst @@ -15,10 +15,9 @@ should be placed in a model, so they can easily be reused later. Models are the place where you retrieve, insert, and update information in your database or other data stores. They represent your data. -Open up the application/models directory and create a new file called -News_model.php and add the following code. Make sure you've configured -your database properly as described -:doc:`here <../database/configuration>`. +Open up the *application/models/* directory and create a new file called +*News_model.php* and add the following code. Make sure you've configured +your database properly as described :doc:`here <../database/configuration>`. :: @@ -37,8 +36,8 @@ library. This will make the database class available through the ``$this->db`` object. Before querying the database, a database schema has to be created. -Connect to your database and run the SQL command below. Also add some -seed records. +Connect to your database and run the SQL command below (MySQL). +Also add some seed records. :: @@ -75,7 +74,7 @@ following code to your model. With this code you can perform two different queries. You can get all news records, or get a news item by its `slug <#>`_. You might have -noticed that the $slug variable wasn't sanitized before running the +noticed that the ``$slug`` variable wasn't sanitized before running the query; :doc:`Query Builder <../database/query_builder>` does this for you. Display the news @@ -83,9 +82,9 @@ Display the news Now that the queries are written, the model should be tied to the views that are going to display the news items to the user. This could be done -in our pages controller created earlier, but for the sake of clarity, a -new "news" controller is defined. Create the new controller at -application/controllers/News.php. +in our ``Pages`` controller created earlier, but for the sake of clarity, +a new ``News`` controller is defined. Create the new controller at +*application/controllers/News.php*. :: @@ -96,6 +95,7 @@ application/controllers/News.php. { parent::__construct(); $this->load->model('news_model'); + $this->load->helper('url_helper'); } public function index() @@ -113,11 +113,13 @@ Looking at the code, you may see some similarity with the files we created earlier. First, the ``__construct()`` method: it calls the constructor of its parent class (``CI_Controller``) and loads the model, so it can be used in all other methods in this controller. +It also loads a collection of :doc:`URL Helper <../helpers/url_helper>` +functions, because we'll use one of them in a view later. -Next, there are two methods to view all news items and one for a -specific news item. You can see that the $slug variable is passed to the -model's method in the second method. The model is using this slug to -identify the news item to be returned. +Next, there are two methods to view all news items and one for a specific +news item. You can see that the ``$slug`` variable is passed to the model's +method in the second method. The model is using this slug to identify the +news item to be returned. Now the data is retrieved by the controller through our model, but nothing is displayed yet. The next thing to do is passing this data to @@ -136,35 +138,35 @@ the views. } The code above gets all news records from the model and assigns it to a -variable. The value for the title is also assigned to the $data['title'] +variable. The value for the title is also assigned to the ``$data['title']`` element and all data is passed to the views. You now need to create a -view to render the news items. Create application/views/news/index.php +view to render the news items. Create *application/views/news/index.php* and add the next piece of code. :: - <h2><?php echo $title ?></h2> + <h2><?php echo $title; ?></h2> <?php foreach ($news as $news_item): ?> - <h3><?php echo $news_item['title'] ?></h3> + <h3><?php echo $news_item['title']; ?></h3> <div class="main"> - <?php echo $news_item['text'] ?> + <?php echo $news_item['text']; ?> </div> - <p><a href="<?php echo $news_item['slug'] ?>">View article</a></p> + <p><a href="<?php echo site_url('news/'.$news_item['slug']); ?>">View article</a></p> - <?php endforeach ?> + <?php endforeach; ?> Here, each news item is looped and displayed to the user. You can see we -wrote our template in PHP mixed with HTML. If you prefer to use a -template language, you can use CodeIgniter's :doc:`Template +wrote our template in PHP mixed with HTML. If you prefer to use a template +language, you can use CodeIgniter's :doc:`Template Parser <../libraries/parser>` class or a third party parser. The news overview page is now done, but a page to display individual news items is still absent. The model created earlier is made in such way that it can easily be used for this functionality. You only need to add some code to the controller and create a new view. Go back to the -news controller and update ``view()`` with the following: +``News`` controller and update ``view()`` with the following: :: @@ -198,12 +200,12 @@ The only things left to do is create the corresponding view at Routing ------- -Because of the wildcard routing rule created earlier, you need an -extra route to view the controller that you just made. Modify your -routing file (application/config/routes.php) so it looks as follows. -This makes sure the requests reaches the news controller instead of -going directly to the pages controller. The first line routes URI's with -a slug to the view method in the news controller. +Because of the wildcard routing rule created earlier, you need an extra +route to view the controller that you just made. Modify your routing file +(*application/config/routes.php*) so it looks as follows. +This makes sure the requests reaches the ``News`` controller instead of +going directly to the ``Pages`` controller. The first line routes URI's +with a slug to the ``view()`` method in the ``News`` controller. :: diff --git a/user_guide_src/source/tutorial/static_pages.rst b/user_guide_src/source/tutorial/static_pages.rst index 62b3469ad..66621471e 100644 --- a/user_guide_src/source/tutorial/static_pages.rst +++ b/user_guide_src/source/tutorial/static_pages.rst @@ -37,24 +37,24 @@ code. } } -You have created a class named "pages", with a view method that accepts -one argument named $page. The pages class is extending the -CI_Controller class. This means that the new pages class can access the -methods and variables defined in the CI_Controller class -(system/core/Controller.php). +You have created a class named ``Pages``, with a view method that accepts +one argument named ``$page``. The ``Pages`` class is extending the +``CI_Controller`` class. This means that the new pages class can access the +methods and variables defined in the ``CI_Controller`` class +(*system/core/Controller.php*). The **controller is what will become the center of every request** to your web application. In very technical CodeIgniter discussions, it may be referred to as the *super object*. Like any php class, you refer to -it within your controllers as $this. Referring to $this is how you will -load libraries, views, and generally command the framework. +it within your controllers as ``$this``. Referring to ``$this`` is how +you will load libraries, views, and generally command the framework. Now you've created your first method, it's time to make some basic page templates. We will be creating two "views" (page templates) that act as our page footer and header. -Create the header at application/views/templates/header.php and add the -following code. +Create the header at *application/views/templates/header.php* and add +the following code: :: @@ -64,17 +64,17 @@ following code. </head> <body> - <h1><?php echo $title ?></h1> + <h1><?php echo $title; ?></h1> The header contains the basic HTML code that you'll want to display before loading the main view, together with a heading. It will also -output the $title variable, which we'll define later in the controller. -Now create a footer at application/views/templates/footer.php that +output the ``$title`` variable, which we'll define later in the controller. +Now, create a footer at *application/views/templates/footer.php* that includes the following code: :: - <em>© 2014</em> + <em>© 2015</em> </body> </html> @@ -83,12 +83,12 @@ Adding logic to the controller Earlier you set up a controller with a ``view()`` method. The method accepts one parameter, which is the name of the page to be loaded. The -static page templates will be located in the application/views/pages/ +static page templates will be located in the *application/views/pages/* directory. -In that directory, create two files named home.php and about.php. Within -those files, type some text − anything you'd like − and save them. If -you like to be particularly un-original, try "Hello World!". +In that directory, create two files named *home.php* and *about.php*. +Within those files, type some text − anything you'd like − and save them. +If you like to be particularly un-original, try "Hello World!". In order to load those pages, you'll have to check whether the requested page actually exists: @@ -122,20 +122,21 @@ function that renders the default error page. In the header template, the ``$title`` variable was used to customize the page title. The value of title is defined in this method, but instead of assigning the value to a variable, it is assigned to the title element -in the $data array. +in the ``$data`` array. The last thing that has to be done is loading the views in the order they should be displayed. The second parameter in the ``view()`` method is used to pass values to the view. Each value in the ``$data`` array is assigned to a variable with the name of its key. So the value of -``$data['title']`` in the controller is equivalent to $title in the view. +``$data['title']`` in the controller is equivalent to ``$title`` in the +view. Routing ------- The controller is now functioning! Point your browser to -[your-site-url]index.php/pages/view to see your page. When you visit -index.php/pages/view/about you'll see the about page, again including +``[your-site-url]index.php/pages/view`` to see your page. When you visit +``index.php/pages/view/about`` you'll see the about page, again including the header and footer. Using custom routing rules, you have the power to map any URI to any @@ -143,8 +144,8 @@ controller and method, and break free from the normal convention: ``http://example.com/[controller-class]/[controller-method]/[arguments]`` Let's do that. Open the routing file located at -application/config/routes.php and add the following two lines. Remove -all other code that sets any element in the $route array. +*application/config/routes.php* and add the following two lines. +Remove all other code that sets any element in the ``$route`` array. :: @@ -161,9 +162,9 @@ arguments. More information about routing can be found in the URI Routing :doc:`documentation <../general/routing>`. -Here, the second rule in the $routes array matches **any** request using -the wildcard string (:any). and passes the parameter to the ``view()`` -method of the pages class. +Here, the second rule in the ``$routes`` array matches **any** request +using the wildcard string ``(:any)``. and passes the parameter to the +``view()`` method of the ``Pages`` class. -Now visit index.php/about. Did it get routed correctly to the ``view()`` +Now visit ``index.php/about``. Did it get routed correctly to the ``view()`` method in the pages controller? Awesome! |