summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerek Allard <derek.allard@ellislab.com>2008-06-20 07:56:51 +0200
committerDerek Allard <derek.allard@ellislab.com>2008-06-20 07:56:51 +0200
commitdb257212945875cfdc3ec0f384f5d2eaf0c2aad9 (patch)
tree43e2ee6b052b56fa47a1932454c8d6924d33c1ab
parentd3ee04109528470666c016fcc05c69941de879b2 (diff)
Added the ability to automatically output language items as form labels in the Language class.
-rw-r--r--system/libraries/Language.php14
-rw-r--r--user_guide/changelog.html1
-rw-r--r--user_guide/libraries/language.html10
3 files changed, 22 insertions, 3 deletions
diff --git a/system/libraries/Language.php b/system/libraries/Language.php
index f97db3506..a1f73d03b 100644
--- a/system/libraries/Language.php
+++ b/system/libraries/Language.php
@@ -108,12 +108,20 @@ class CI_Language {
* Fetch a single line of text from the language array
*
* @access public
- * @param string the language line
+ * @param string $line the language line
+ * @param string $label optional label
* @return string
*/
- function line($line = '')
+ function line($line = '', $label = '')
{
- return ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];
+ $line = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];
+
+ if ($label != '')
+ {
+ $line = '<label for="'.$label.'">'.$line."</label>";
+ }
+
+ return $line;
}
}
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 39568b93f..e07829053 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -74,6 +74,7 @@ SVN Revision: not currently released</p>
<li>Added support for query strings to the <a href="libraries/pagination.html">Pagination class</a>, automatically detected or explicitly declared.</li>
<li>Added <kbd>get_post()</kbd> to the <a href="libraries/input.html">Input class</a>.</li>
<li>Documented <kbd>get()</kbd> in the <a href="libraries/input.html">Input class</a>.</li>
+ <li>Added the ability to automatically output language items as form labels in the <a href="libraries/language.html">Language class</a>.</li>
</ul>
</li>
<li>Helpers
diff --git a/user_guide/libraries/language.html b/user_guide/libraries/language.html
index eff7d32a5..aa0774327 100644
--- a/user_guide/libraries/language.html
+++ b/user_guide/libraries/language.html
@@ -110,6 +110,16 @@ is the language set containing it (ie, english). If the second parameter is mis
<p>Where <samp>language_key</samp> is the array key corresponding to the line you wish to show.</p>
<p>Note: This function simply returns the line. It does not echo it for you.</p>
+
+<h3>Using language lines as form labels</h3>
+
+<p>If your application requires it, a language line can automatically be output as a &lt;label&gt; by specifying a second parameter, which will become the "for" attribute of the label.</p>
+
+<code>
+$this->lang->line('<samp>language_key</samp>', '<samp>form_item_id</samp>'); <br />
+// becomes &lt;label for="form_item_id"&gt;language_key&lt;/label&gt;
+</code>
+
<h2>Auto-loading Languages</h2>
<p>If you find that you need a particular language globally throughout your application, you can tell CodeIgniter to <a href="../general/autoloader.html">auto-load</a> it during system initialization. This is done by opening the application/config/autoload.php file and adding the language(s) to the autoload array.</p>
<p>&nbsp;</p>