On Tue, Oct 30, 2012 at 12:44 PM, Steve Rayner <srayne...@googlemail.com> wrote: > I strongly disagree. Zend Framework should not dictate how you name > your database fields. > > I guess you need some king of mapping service to translate between you > database field names and your class properties. > Sorry i can't provide a better answer. I personally use Doctrine ORM. > > > On Sat, Oct 27, 2012 at 12:52 PM, luk <l...@mierzwa.cc> wrote: >> o.mellinger wrote >>> Hi everybody, >>> >>> I am trying to write my first module on zf2. For that, I am following the >>> getting started tutorial for zf2. >>> >>> I followed the examples concerning the tableGateway and especially the >>> implementation of the exchangeArray method of the Album class. >>> >>> I have the impression that this pattern assumes all class attributes names >>> are equals to the fields name in the db table and this is something that >>> disturbs me a lot. >>> >>> So let's take a simple db table like this one >>> >>> Table : expression_translations >>> et_id >>> et_string >>> et_locale >>> (...) >>> >>> I created a expression class like that >>> <code> >>> namespace Translate\Model; >>> >>> use Zend\InputFilter\Factory as InputFactory; >>> use Zend\InputFilter\InputFilter; >>> use Zend\InputFilter\InputFilterAwareInterface; >>> use Zend\InputFilter\InputFilterInterface; >>> >>> class Expression implements InputFilterAwareInterface >>> { >>> public $id; >>> public $locale; >>> public $string; >>> public (..) >>> } >>> </code> >>> I don't want to name my attributes with the 'et_' prefix as, for me, it is >>> not the responsability of this class to know how my table is structured. >>> >>> You could answer me that I could deal with this difference in the >>> 'exchangeArray' method of this class, doing something like that >>> <code> >>> function exchangeArray($data) >>> { >>> $this->id = (isset($data['te_id'])) ? $data['te_id'] : null; >>> $this->locale = (isset($data['te_locale'])) ? $data['te_locale'] : null; >>> $this->string = (isset($data['te_string'])) ? $data['te_string'] : null; >>> (..) >>> } >>> </code> >>> but it will mean that in my forms or in my inputFilter configurations, I >>> will have to name my elements with the 'et_' prefix. >>> >>> I don't know if I am talking about something stupid but it disturbs me. >>> >>> I looked into the zf2 code and I was looking for a kind of hook in the >>> Zend\Db\ResultSet\ResultSet::current() method >>> <code> >>> public function current() >>> { >>> $data = parent::current(); >>> >>> if ($this->returnType === self::TYPE_ARRAYOBJECT && >>> is_array($data)) { >>> /** @var $ao ArrayObject */ >>> $ao = clone $this->arrayObjectPrototype; >>> if ($ao instanceof ArrayObject || method_exists($ao, >>> 'exchangeArray')) { >>> $ao->exchangeArray($data); >>> } >>> return $ao; >>> } else { >>> return $data; >>> } >>> } >>> </code> >>> something like that >>> <code> >>> public function current() >>> { >>> $data = parent::current(); >>> >>> if ($this->returnType === self::TYPE_ARRAYOBJECT && >>> is_array($data)) { >>> /** @var $ao ArrayObject */ >>> $ao = clone $this->arrayObjectPrototype; >>> >>> if ($ao instanceof ArrayObject || method_exists($ao, >>> 'exchangeArray')) { >>> /*operates transformations on resultset datas*/ >>> //in preprocessDataCallback, I would put a function to >>> remove the prefix 'et_' in my keys >>> if ($this->preprocessDataCallback !== null) { >>> $data = call_user_func($this->preprocessDataCallback, >>> $data); >>> } >>> $ao->exchangeArray($data); >>> } >>> return $ao; >>> } else { >>> return $data; >>> } >>> } >>> </code> >>> so before exchanging data with my entity, I provide to the latter an >>> "understandable" array. >>> >>> is there a better to do that or am I going to the wrong direction ? >> >> I will strongly recommend you to change your DB naming conventions to follow >> more standardized one. >> Something like that will do: >> >> expression_translations >> ----------------------- >> id >> label >> locale >> >> >> And now you got your ZF2 issue solved. >> Otherwise one way or the other you will need to put a small hack in place to >> always deal with your prefix removal\addition. Hope it makes sense. >> >> >> >> ----- >> Cheers, >> -- >> Luke Mierzwa >> -- >> View this message in context: >> http://zend-framework-community.634137.n4.nabble.com/ZF2-exchangeArray-and-db-fields-prefix-tp4657802p4657820.html >> Sent from the Zend DB mailing list archive at Nabble.com. >> >> -- >> List: fw...@lists.zend.com >> Info: http://framework.zend.com/archives >> Unsubscribe: fw-db-unsubscr...@lists.zend.com >> >>
-- List: fw-general@lists.zend.com Info: http://framework.zend.com/archives Unsubscribe: fw-general-unsubscr...@lists.zend.com