Forums / Developer / setContent() does not work as expected
Áncor González
Friday 30 April 2004 12:33:38 pm
I'm using ezPublish 3.3-3. I'm trying to write a module and I need to alter existing content object attributes. I'm using setContent function, but it doesn't work as I expected. My code:
$objectver =& $object->currentVersion(); $attributes =& $objectver->dataMap(); $my_attrib =& $attributes["attribname"]; $my_string = "foo"; $my_attrib->setContent($my_string); //Here, my_attrib->content() returns "foo" //but data_text still containts the old value $my_attrib->store(); //This update de DB with the content of data_text, so my //changes are ignored
What is the right way to do what I'm trying?
In addition, can anybody write an small working example of a full new content object creation from scratch (settings the attributes, etc)?
Paul Forsyth
Saturday 01 May 2004 6:34:43 am
Have a look on this thread for the examples you need:
http://ez.no/community/forum/developer/importing_update_entry_if_it_already_exists
paul
--http://www.visionwt.com
Sunday 02 May 2004 5:21:05 am
I already supossed that using setAttribute("data_text",$my_string) should work but... It's not a job that should be done by setContent() itself?I see the use of setAttribute("data_text",$my_string) as a workaround, a temporary solution, a patch because setContent() does not work as it should. But maybe I'm wrong and I have not understood the real meaning of setContent().
Anyway, thank you very much for your help, you saved my life.
Sunday 02 May 2004 3:10:25 pm
I think setContent actually retreives values from the db, ready for the template to use, and setAttribute goes in the other direction and enters values into the right variables for the store() command to actually commit the change to the db.
It is subtle difference and needs to be better documented.