diff options
author | Andrey Andreev <narf@bofh.bg> | 2012-11-26 22:55:37 +0100 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2012-11-26 22:55:37 +0100 |
commit | 3b407060439258c7ef9f30ac35b5f9f34101fd69 (patch) | |
tree | 32649e20306d390cf19fdef1ace7c8e1da75bda1 | |
parent | b11b9f38f3ae0f9699612ac61000ee789665f2d6 (diff) |
Language helper lang() to accept optional HTML attributes
(an improved version of PR #1235)
-rw-r--r-- | system/helpers/language_helper.php | 9 | ||||
-rw-r--r-- | user_guide_src/source/changelog.rst | 3 | ||||
-rw-r--r-- | user_guide_src/source/helpers/language_helper.rst | 10 |
3 files changed, 12 insertions, 10 deletions
diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php index 658be6de7..f931208e1 100644 --- a/system/helpers/language_helper.php +++ b/system/helpers/language_helper.php @@ -45,18 +45,19 @@ if ( ! function_exists('lang')) * * Fetches a language variable and optionally outputs a form label * - * @param string the language line - * @param string the id of the form element + * @param string $line The language line + * @param string $for The "for" value (id of the form element) + * @param array $attributes Any additional HTML attributes * @return string */ - function lang($line, $id = '') + function lang($line, $for = '', $attributes = array()) { $CI =& get_instance(); $line = $CI->lang->line($line); if ($id !== '') { - $line = '<label for="'.$id.'">'.$line.'</label>'; + $line = '<label for="'.$id.'"'._stringify_attributes($attributes).'>'.$line.'</label>'; } return $line; diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 525559159..ab1d99dab 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -96,7 +96,8 @@ Release Date: Not Released - Deprecated function ``repeater()`` - it's just an alias for PHP's native ``str_repeat()``. - Deprecated function ``trim_slashes()`` - it's just an alias for PHP's native ``trim()`` (with a slash as its second argument). - Deprecated randomization type options **unique** and **encrypt** for funcion :php:func:`random_string()` (they are only aliases for **md5** and **sha1** respectively). - - :doc:`Directory Helper <helpers/directory_helper>` ``directory_map()`` will now append DIRECTORY_SEPARATOR to directory names in the returned array. + - :doc:`Directory Helper <helpers/directory_helper>` :php:func:`directory_map()` will now append ``DIRECTORY_SEPARATOR`` to directory names in the returned array. + - :doc:`Language Helper <helpers/language_helper>` :php:func:`lang()` now accepts an optional list of additional HTML attributes. - Deprecated the :doc:`Email Helper <helpers/email_helper>` as its ``valid_email()``, ``send_email()`` functions are now only aliases for PHP native functions ``filter_var()`` and ``mail()`` respectively. - Database diff --git a/user_guide_src/source/helpers/language_helper.rst b/user_guide_src/source/helpers/language_helper.rst index 8b039374d..1911e3bfd 100644 --- a/user_guide_src/source/helpers/language_helper.rst +++ b/user_guide_src/source/helpers/language_helper.rst @@ -19,18 +19,18 @@ The following functions are available: lang() ====== -.. php:function:: lang($line, $id = '') +.. php:function:: lang($line, $for = '', $attributes = array()) :param string $line: Language line key - :param string $id: ID of the element we're creating a label for + :param string $for: HTML "for" attribute (ID of the element we're creating a label for) + :param array $attributes: Any additional HTML attributes :returns: string This function returns a line of text from a loaded language file with simplified syntax that may be more desirable for view files than ``CI_Lang::line()``. -The optional second parameter will also output a form label for you. Example:: - echo lang('language_key', 'form_item_id'); - // becomes <label for="form_item_id">language_key</label>
\ No newline at end of file + echo lang('language_key', 'form_item_id', array('class' => 'myClass'); + // Outputs: <label for="form_item_id" class="myClass">Language line</label>
\ No newline at end of file |