Alex Tech Adventures The webs best tutorials!

Welcome, Guest
Please Login or Register.    Lost Password?

Populate DB-row into CRUD form
(1 viewing) (1) Guest
Go to bottomPage: 1
TOPIC: Populate DB-row into CRUD form
#302
Populate DB-row into CRUD form 2 Years, 1 Month ago Karma: 1
I searched and tested different solutions the whole Sunday and can't find any that works propartly. And in my eyes I have really follow the solution sources.

I have a CRUD form - this one is for update.
And I want to populate the row value from that ID into the form, but keep get error:

Catchable fatal error: Argument 1 passed to Zend_Form::populate() must be an array, object given


The MVC structures is like the quickstart guestbook, with Datamapper and DBTable-files.

Code:

    public function find($id)
    {
        $this->getMapper()->find($id, $this);
        return $this;
    }


Code:


public function find($id, Admin_Model_NewsArchive $NewsArchive) {

$table = $this->getDbTable();

$row = $table->fetchRow($table->id);


  $NewsArchive->setId($row->id)
                        ->setTitle($row->title)
                        ->setIntro($row->intro)
           ->setMainContent($row->maincontent)
           ->setMetatitle($row->meta_title)
                        ->setDatepub($row->date_pub);

// Get the column/value associative array from the Row object
return $rowArray = $row->toArray();
}



Code:


$model =  new Admin_Model_NewsArchive();

print_r($model->find($id));
$form->populate($model->find($id));



When I print_r the value I acctually get the first row
"Admin_Model_NewsArchive Object ( [_intro:protected] => test [_datepub:protected] => 2010-01-03 12:19:06 [_pubstatus:protected] => [_title:protected] => Nyhet [_maincontent:protected] =>sds
[_metatitle:protected] => [_metakeys:protected] => [_metadesc:protected] => [_mainimage:protected] => [_mainimagetype:protected] => [_lang:protected] => [_id:protected] => 364"

But after that it also write alot of other array-data, like the mysql username, password and everything from the config file?
Skatan
Fresh Boarder
Posts: 11
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#353
Re:Populate DB-row into CRUD form 2 Years ago Karma: 16
I think your logic flow is not fully correct.
Mapper return an array as expected and needed by the form. But you are not actually picking that value up anywhere.
Code:


$this->getMapper()->find($id, $this); 
        return $this; 


You just ran the query without saving the result and returned an instance of the NewsArchive object rather than its data. Well, actually I cannot tell whether you are saving the data in some private property in getMapper() method but either way you need
Code:


public function find($id) 
    { 
        return $this->getMapper()->find($id, $this); 
    }

alexanderrv
Administrator
Posts: 279
graph
User Offline Click here to see the profile of this user
Gender: Male tmthv2 alexchatonly@hotmail.com Location: Freeport, Bahamas Birthdate: 1989-04-14
The administrator has disabled public write access.
 
Go to topPage: 1
Moderators: alexanderrv
You are here: Home Forum

Statistics

Members : 1388
Content : 42
Web Links : 1
Content View Hits : 190530

Poll

Interested in TinyBrowser and TinyMce plugin for ZF?
 

Who's Online

We have 31 guests online