Oops, I've forgot to put this after the "$where = $m->getAdapter()....."
$row = $m->fetchRow($where);
--
Xavier Vidal Piera
Enginyer Tècnic Informàtic de Gestió
Tècnic Especialista Informàtic d'equips
xavividal@gmail.com
xvidal@lavanguardia.es
http://web.xaviervidal.net
610.68.41.78
$row = $m->fetchRow($where);
On Mon, Aug 4, 2008 at 21:47, Xavier Vidal Piera <xavividal@gmail.com> wrote:
The decision of inserting/updating is your responsability too. If you have a form and this form can create or edit data, you will know it thanks to a hidden field with the PK ID.
So, in your code you can do the following (this example could be more secure...)
$m = new Model_Whatever();
$id = $this->_request->getParam('id', '');
if(is_numeric($id)) {
$where = $m->getAdapter()->quoteInto('id = ?', $id);
$row = $m->fetchRow();
} else {
$row = $m->createRow();
}
// fill your data here
$row->bla = 'bla'
...
// and finally, the $row knows what to do nex
$row->save();
P.D. "ITHO" means In The Other Hand :P
On Mon, Aug 4, 2008 at 21:40, maxarbos <maxarbos@yahoo.com> wrote:
ok, i see what you are saying. What about if i receive an array of info and
want to update/insert it?
Would/could I run fetchRow and be returned an empty object, use the info
submitted from a form and then save() it? Would it then be able to check if
row exisits and if not, insert it?
Thanks.
... what does ITOH mean?
thanks.
--
Xavier Vidal Piera wrote:
>
> Zend_Db_Table_Row behaves that way already. If you load the row from db it
> will have a primary key field filled inside, so if you save it later this
> object will update that data.
>
> ITOH, if you create a row with "$table->createRow()", the primary key
> fields
> will be null and a later "save" will do an insert.
>
> So, if you look at the internals of Zend_Db_Table_Row you will see two
> arrays: the first one is for storing the fresh data and the other one
> holds
> the 'dirty data', so comparing both you can know which fields have changed
> and if the primary keys fields are filled up.
>
> Hope it helps.
>
> On Mon, Aug 4, 2008 at 21:16, maxarbos <maxarbos@yahoo.com> wrote:
>
>>
>> Hello,
>>
>> I am looking through the docs and see the save() method associated with
>> Zend_Db_Table_Row and Rowset, is there a method that will check for a
>> primry
>> key val of XX and update it, otherwise insert it, automatically?
>>
>> I want to be able to update a row in a table that may or may not be in
>> the
>> table.
>> i would like to be able to just set my array to contain the record id i
>> want
>> to update and execute save().
>> If that ID doesnt exisit, then insert instead of update.
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Zend_Db_Table---Row---Rowset-tp18817752p18817752.html
>> Sent from the Zend DB mailing list archive at Nabble.com.
>>
>>
>
>
> --
> Xavier Vidal Piera
> Enginyer Tècnic Informàtic de Gestió
> Tècnic Especialista Informàtic d'equips
> xavividal@gmail.com
> xvidal@lavanguardia.es
> http://web.xaviervidal.net
> 610.68.41.78
>
>
View this message in context: http://www.nabble.com/Zend_Db_Table---Row---Rowset-tp18817752p18818145.html
Sent from the Zend DB mailing list archive at Nabble.com.
--
Xavier Vidal Piera
Enginyer Tècnic Informàtic de Gestió
Tècnic Especialista Informàtic d'equips
xavividal@gmail.com
xvidal@lavanguardia.es
http://web.xaviervidal.net
610.68.41.78
--
Xavier Vidal Piera
Enginyer Tècnic Informàtic de Gestió
Tècnic Especialista Informàtic d'equips
xavividal@gmail.com
xvidal@lavanguardia.es
http://web.xaviervidal.net
610.68.41.78
没有评论:
发表评论