Featured post
php - Override Doctrine_Record validate method with a Doctrine_Template -
in symfony project use new strategy manage data form.
i don't want use symfony form object, want use model build them.
i don't want redeclare base doctrine_record class, wrote new doctrine_template: extendedmodel.
in extendemodel template i've new objects , methods, need override validate() function of doctrine_record.
i tried with
class extendedmodel extends doctrine_template { [...] public $validatorschema; public function setvalidatorschema(sfvalidatorschema $validatorschema) { $this->validatorschema = $validatorschema; } public function getvalidatorschema() { return $this->validatorschema; } public function validate() { $this->getinvoker()->setup(); $errorstack = $this->getinvoker()->geterrorstack(); if ($this->getvalidatorschema()) { try { $this->getvalidatorschema()->addoption('allow_extra_fields', true); $this->getvalidatorschema()->clean($this->getinvoker()->toarray(false)); } catch (sfvalidatorerrorschema $errorschema) { $errorstack = $this->getinvoker()->geterrorstack(); foreach ($errorschema->geterrors() $key => $error) { /* @var $error sfvalidatorerror */ $errorstack->add($key, $error->getmessage()); } } } $this->getinvoker()->validate(); } }
but doctrine use original validate() function.
i want override doctrine_record functions new methods declared doctrine_template.
could suggest me solution problem?
tnx!
templates not override doctrine_record methods, fallbacks invoked via php magic __call
method when native method isn't found.
to this, need have own class in doctrine_record inheritance chain. fortunately, pretty easy:
1. create mydoctrinerecord
abstract class mydoctrinerecord extends sfdoctrinerecord { public function commonrecordmethod() { } }
i place file in lib/record, can put anywhere autoloader see it.
2. set symfony use class in configuredoctrine callback of projectconfiguration:
public function configuredoctrine(doctrine_manager $manager) { sfconfig::set('doctrine_model_builder_options', array('baseclassname' => 'mydoctrinerecord')); }
this copied/pasted previous answer similar question. you'll have rebuild model well.
- Get link
- X
- Other Apps
Comments
Post a Comment