class Model_Admin extends Model
{
$form->add('first_name',
'First Name',
array(
'type' => 'text',
'value' => ! empty($admin['first_name']) ? $admin['first_name'] : '',
'id' => 'first-name',
'size' => 50,
),
array(
array('required'),
array('trim'),
array('max_length', 50),
)
);
// Other form fields and logic
class Validation extends \Fuel\Core\Validation
{
public function _validation_unique($val, $options)
{
list($table, $field) = explode('.', $options);
$result = DB::select("LOWER (\"$field\")")
->where("$field", '=', MBSTRING ? mb_strtolower($val) : strtolower($val))
->from($table)->execute();
if($result->count() > 0)
return false;
else
return true;
}
Where and how do I add this callback using fieldset/model? public function action_add_edit_example($example_id = null)
{
...
$form = Fieldset::factory('form_example')->add_model('Model_Mexamples', $example_id, 'set_form_fields_example');
...
}
class Model_Mexamples extends Model
{
public static function set_form_fields_example(Fieldset $form, $example_id = null)
{
if ($example_id != null)
{
$data = self::get_example_info($example_id);
}
...
$form->add('email',
'Email',
array(
'type' => 'text',
'value' => ! empty($user['email']) ? $user['email'] : '',
'id' => 'email',
'size' => 50,
),
array(
array('required'),
array('trim'),
array('max_length', 255),
array('valid_email'),
array('unique', 'auth_users', 'email', 'user_id', $user_id),
)
);
...
}
public function _validation_unique($form_value, $db_table, $unique_field, $id_field, $id)
{
$query = DB::select($unique_field)
->from($db_table)
->where("$unique_field", '=', MBSTRING ? mb_strtolower($form_value) : strtolower($form_value))
->and_where($id_field, '!=', $id)
;
$result = $query->execute();
if ($result->count() == 0)
{
return true;
}
else
{
$this->set_message('unique', 'That :label is already used. Please pick a different :label.');
return false;
}
}
Autoloader::add_classes(array( // Add classes you want to override here // Example: 'View' => APPPATH.'classes/view.php', 'Security' => APPPATH.'classes/security.php', 'Session' => APPPATH.'classes/session.php', 'Validation' => APPPATH.'classes/validation.php', 'Fieldset' => APPPATH.'classes/fieldset.php', ));
$form->add('username',
'User Name',
array(
'type' => 'text',
'value' => ! empty($admin['username']) ? $admin['username'] : '',
'id' => 'phone',
'size' => 50,
),
array(
array('required'),
array('trim'),
array('max_length', 50),
array('unique[simpleusers.username]'),
)
);
When I run the code, function notice() in error.php is called with msg:class MySession extends Session
{
public static function print_flash()
{
$flash = Session::get_flash();
if (isset($flash['success']))
{
return '<p class="success">' . Session::get_flash('success') . '</p>';
}
else if (isset($flash['notice']))
{
return '<p class="notice">' . Session::get_flash('notice') . '</p>';
}
else if (isset($flash['error']))
{
return '<p class="error">' . Session::get_flash('error') . '</p>';
}
else
{
return null;
}
}
}
Calls to Session::print_flash() result in an error: Call to undefined method Fuel\core\Session::print_flash(). Please let me know if you see what I'm doing wrong.
If your question was why am I extending the core classes at all, you can probably see from the example that I'm basically wrapping the Fuel functionality in a higher level wrapper.
All suggestions for better ways to do things are always welcome. Autoloader::add_classes(array( 'Session' => APPPATH.'classes/session.php', ));
class Session extends Fuel\Core\Session {
}
Autoloader::add_classes(array( // Add classes you want to override here // Example: 'View' => APPPATH.'classes/view.php', 'Security' => APPPATH.'classes/security.php', 'Session' => APPPATH.'classes/session.php', 'Validation' => APPPATH.'classes/validation.php', 'Fieldset' => APPPATH.'classes/fieldset.php', ));
class Validation extends \Fuel\Core\Validation
{
public function _validation_unique($val, $options)
{
list($table, $field) = explode('.', $options);
$result = DB::select("LOWER (\"$field\")")
->where("$field", '=', MBSTRING ? mb_strtolower($val) : strtolower($val))
->from($table)->execute();
if($result->count() > 0)
return false;
else
return true;
}
public static function set_form_fields(Fieldset $form, $user_id = null)
{
....
$form->add('username',
'User Name',
array(
'type' => 'text',
'value' => ! empty($admin['username']) ? $admin['username'] : '',
'id' => 'phone',
'size' => 50,
),
array(
array('required'),
array('trim'),
array('max_length', 50),
array('unique[simpleusers.username]'),
)
);
....
It looks like you're new here. If you want to get involved, click one of these buttons!