Skip to content

Commit

Permalink
make sure validation rules always have 3 parameters
Browse files Browse the repository at this point in the history
updated the validation docs to reflect this; also updated the example
  • Loading branch information
WanWizard committed Feb 18, 2011
1 parent 079b157 commit d80c1e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 13 additions & 11 deletions docs/classes/validation.html
Original file line number Diff line number Diff line change
Expand Up @@ -345,21 +345,23 @@ <h3><a name="errors">Error messages</a></h3>
<h3><a name="methods">Extending Validation class</a></h3>

<p>There are few aproaches to extend the validation class:</p>

<p>1. To extend the core class like described in the <a href="../general/extending_core.html">Extending Core Classes</a></p>

<p>2. To create a class in <b>app/classes/myvalidation.php</b> (for example)</p>
<pre class="php"><code>// app/classes/myvalidation.php
class Myvalidation {
public function _validation_unique($val, $options)

public function _validation_unique($val, $options, $object)
{
list($table, $field) = explode('.', $options);

$result = DB::select("LOWER (\"$field\")")
->where("$field", '=', MBSTRING ? mb_strtolower($val) : strtolower($val))
->from($table)->execute();

$object->set_message('unique', 'The field :label must have an unique value.');

if($result->count() > 0)
return false;
else
Expand All @@ -373,17 +375,17 @@ <h3><a name="methods">Extending Validation class</a></h3>
$val->add_callable('myvalidation'); // here we add the class to load rules from

$val->add_field('username', 'Your username', 'trim|strip_tags|required|unique[users.username]');</code></pre>

<p>3. Calling callbacks from a model. It works like a method described above, but we only need to call it in other way:</p>
<pre class="php"><code>$val = Validation::factory();
$val->add_model('Model_User');</code></pre>
<p class="note">
<strong>Note: </strong>

<p class="note">
<strong>Note: </strong>
You need the '_validation_' prefix for a method to be used in validation.
</p>
</p>
</article>

<article>
<h3><a name="methods">All methods</a></h3>

Expand All @@ -400,4 +402,4 @@ <h3><a name="methods">All methods</a></h3>
</section>

</body>
</html>
</html>
2 changes: 1 addition & 1 deletion fuel/core/classes/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function run($input = null, $allow_partial = false)
foreach ($field->rules as $rule)
{
$callback = $rule[0];
$params = $rule[1];
$params = empty($rule[1]) ? array(null) : $rule[1];

$this->_run_rule($callback, $value, $params, $field);
}
Expand Down

0 comments on commit d80c1e0

Please sign in to comment.