LoginSignup
0
0

More than 5 years have passed since last update.

FuelPHPのOrmのObserverで、保存する前に値をtrimするように設定する

Posted at

1.Observerに登録

model/orm.php
protected static $_observers = array(
    'Orm\\Observer_Self' => array(
        'events' => array('before_save')
    ),
);
  1. Observer呼び出し時のトリミング処理
model/orm.php
public function _event_before_save()
{
    $properties = array_keys($this->properties());
    foreach ($properties as $property) {
        if(!isset($this->{$property})) {
            continue;
        }
        if (!is_string($this->{$property})) {
            continue;
        }
        $this->{$property} = trim($this->{$property});
    }
}

全角スペースのトリミングはこちらを参考にしました。
https://qiita.com/saku/items/2cac8fbd7cfd4c493b52

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0