nemec Posted August 27, 2007 Report Posted August 27, 2007 $components[0]->id=$components[0]->name='text'; $components[1]->id=$components[1]->name='gallery'; $components[2]->id=$components[2]->name='category'; kaa var shito uzrakstiit vienkaarshaak? apmeeram kaut kaa taa: $components = array(0=>Object0, 1=>Object1, 2=>Object2) kur Object0 ir Object0->id=Object0->name='text'
nemec Posted August 28, 2007 Author Report Posted August 28, 2007 man vajag izveidot taadu mainiigo array(3) { [0]=> object(stdClass)#3 (2) { ["name"]=> string(4) "text" ["id"]=> string(4) "text" } [1]=> object(stdClass)#4 (2) { ["name"]=> string(7) "gallery" ["id"]=> string(7) "gallery" } [2]=> object(stdClass)#5 (2) { ["name"]=> string(8) "category" ["id"]=> string(8) "category" } } kaa es varu to izveidot iznjemot $components[0]->id=$components[0]->name='text'; $components[1]->id=$components[1]->name='gallery'; $components[2]->id=$components[2]->name='category'; ja objektu vietaa buutu masiivs, tad dariitu taa $components = array( array('id'=>'text', 'name'=>'text'), array('id'=>'gallery', 'name'=>'gallery'), array('id'=>'category', 'name'=>'catogory') ); vajag taadu pashu pierakstu apmeeram.
Delfins Posted August 28, 2007 Report Posted August 28, 2007 (edited) Tev taču visu pateica priekšā! $c = Array('text','gallery','whatever'); foreach ($c AS $k => $v) { $components[$k]->name = $components[$k]->id = $v; } Edited August 28, 2007 by Delfins
nemec Posted August 28, 2007 Author Report Posted August 28, 2007 ok. kaa es varu shito uzrakstiit, neizmantojot $components mainiigo $components[0]->id=$components[0]->name='text'; $components[1]->id=$components[1]->name='gallery'; $components[2]->id=$components[2]->name='category'; $editingFields = array( array('type'=>'display', 'name' => 'id'), array('type'=>'display', 'name' => 'type'), array('type'=>'display', 'name' => 'name'), array('type'=>'text', 'name' => 'friend_url', 'check'=>'check_url'), array('type'=>'', 'name' => 'description'), array('type'=>'', 'name' => 'parent_id'), array('type'=>'text', 'name' => 'ordering'), array('type'=>'select', 'name' => 'component', 'posible'=>$components), array('type'=>'', 'name' => 'component_id'), array('type'=>'truefalse', 'name' => 'published') );
Delfins Posted August 28, 2007 Report Posted August 28, 2007 es domāju 99% no klātesošajiem tevi nesaprot ko tev vajag un kas tev nesanāk (ieskaitot mani)
Delfins Posted August 28, 2007 Report Posted August 28, 2007 (edited) A nafig tev vispār tur objektu jābāž? Liec masīvu ... $components['gallery'] = 'mana ūūūūber-krutā galerija'; Tas, ka tu kautkur dzirdēji, ka OOP ir ļoti kruta, nenozīmē, ka to visur ir jābāz.. un it īpaši, ka tas kalpo tikai kā `storage` mainīgajiem bez jebkādām f-jām. Bet, ja vajag Uztaisi klasi class SelectOptionItem { __construct($value,$title) { .... } } un tad: ... 'posible' (kas par debīlu nosaukumu key-am) => Array(new SelectOptionItem('gallery','mana ūūūūber-krutā galerija'), new SelectOptionItem('text','mans ūūūber-krutais teksts'), ... un t.t.) ... Edited August 28, 2007 by Delfins
nemec Posted August 29, 2007 Author Report Posted August 29, 2007 A nafig tev vispār tur objektu jābāž? Liec masīvu ... ja, jau gribeetu, tad taa arii dariitu. tu pats savu piedaavaato perverso variantu izmantotu?
v3rb0 Posted August 29, 2007 Report Posted August 29, 2007 (edited) ja vajag veikt vienādas darbības ar vairāk kā 2 viena objecta vai hashmapa propertijiem, tad izmantoju to "perverso" variantu un neko sliktu tur nesaskatu. pie tam, pierakstu vēl pervērsāk foreach (array('text','gallery','whatever') as $k => $v) $components[$k]->name = $components[$k]->id = $v; Edited August 29, 2007 by v3rb0
Delfins Posted August 29, 2007 Report Posted August 29, 2007 tu pats savu piedaavaato perverso variantu izmantotu? Tās perversās prasības izvirzīji TU!... Turklāt tā ir vienīgā iespēja, kā to izdarīt, neizmantojot papildus mainīgo ($components šajā gadījumā) Turklāt tas nemaz nav perversi, ja grib padod parametros objektu, ar kuru vairs netiek darītas tekošajā līmenī.
Recommended Posts