php - Create a token for each record using Code Igniter and Doctrine ORM -
i have model setup using doctrine. generate token each record, think need overload doctrine's save() function found using symfony:
class jobeetaffiliate extends basejobeetaffiliate { public function save(doctrine_connection $conn = null) { if (!$this->gettoken()) { $this->settoken(sha1($this->getemail().rand(11111, 99999))); } return parent::save($conn); } // ... }
my current model looks this:
<?php class photo extends doctrine_record { public function settabledefinition() { $this->hascolumn('photo_path', 'string', 255, array('unique' => 'true')); $this->hascolumn('count', 'integer', 4, array('unsigned' => 'true')); $this->hascolumn('is_count', 'integer', 4, array('unsigned' => 'true')); $this->hascolumn('region_id', 'integer', 4); $this->hascolumn('region_id', 'integer', 4); $this->hascolumn('token', 'string', 255); } public function setup() { $this->actas('timestampable'); $this->hasone('region', array( 'local' => 'region_id', 'foreign' => 'id' )); } }
any generating token field in model appreciated, of yet can't figure out how overload save() in model appropriately.
you should doctrine's record hooks , it's presave()
function. need work inside model:
public function settabledefinition() { $this->hascolumn('photo_path', 'string', 255, array('unique' => 'true')); $this->hascolumn('count', 'integer', 4, array('unsigned' => 'true')); $this->hascolumn('is_count', 'integer', 4, array('unsigned' => 'true')); $this->hascolumn('region_id', 'integer', 4); $this->hascolumn('region_id', 'integer', 4); $this->hascolumn('token', 'string', 255); } public function setup() { $this->actas('timestampable'); $this->hasone('region', array( 'local' => 'region_id', 'foreign' => 'id' )); } public funcion presave($event) { if( ! $this->token) { $this->settoken(sha1($this->getemail().rand(11111, 99999))); } }
Comments
Post a Comment