Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to write a custom row class (extends Zend_Db_Table_Row) for a Db_Table class in Zend Framework
    text
    copied!<p>I have separate db_table classes for <strong>books</strong>, <strong>book_sections</strong> and <strong>users</strong> (system end users). in <strong>book table</strong> has <strong>columns</strong> for <strong>book_title</strong>, <strong>section_id</strong>(book_section) , <strong>data_entered_user_id</strong>(who entered book info). </p> <p>go to this url to see the image(I'm not allow to post images bacause I'm new to stackoverflow) img685.imageshack.us/img685/9978/70932283.png</p> <p>in the backend of the system I added a <strong>form to edit existing book</strong> (get book id from GET param and fill the relevant data to the form). form has elements for <strong>book_title</strong>, <strong>book_section</strong> and <strong>data_entered_user</strong>.</p> <p>to get exciting book data to "edit book form" I <strong>join book_section and user tables with book</strong> table to get <strong>book_section_name and username</strong>(of data_entered_user: read only- display on side bar)</p> <p>go to this url to see the image(I'm not allow to post images bacause I'm new to stackoverflow) img155.imageshack.us/img155/2947/66239915.jpg</p> <p><strong>In class App_Model_Book extends Zend_Db_Table_Abstract</strong></p> <pre><code>public function getBookData($id){ $select = $this-&gt;select(); $select-&gt;setIntegrityCheck(false); $select-&gt;from('book', array('id','section_id','data_entered_user_id',...)); $select-&gt;joinInner('section','book.section_id = section.id',array('section_name' =&gt;'section.name' )); $select-&gt;joinInner(array('date_entered_user' =&gt; 'user'),'book.date_entered_user_id = date_entered_user.id',array('date_entered_user_name' =&gt;'date_entered_user.user_name' )); $select-&gt;where("book.id = ?",$id); return $this-&gt;fetchRow($select); } public function updateBookData($id,$title,$section_id,...) { $existingRow = $this-&gt;fetchRow($this-&gt;select()-&gt;where('id=?',$id)); $existingRow-&gt;title = $title; $existingRow-&gt;section_id = $section_id; //.... $existingRow-&gt;save(); } </code></pre> <p><strong>In Admin_BookController -> editAction()</strong></p> <pre><code>$editForm = new Admin_Form_EditBook(); $id = $this-&gt;_getParam('id', false); $bookTable = new App_Model_Book(); $book_data = $bookTable -&gt;getBookData($id); //set values on form to print on form when edit book $editForm-&gt;book_title-&gt;setValue($book_data-&gt;title); $editForm-&gt;book_section-&gt;setValue($book_data-&gt;section_name); //........ //If form data valid if($this-&gt;getRequest()-&gt;isPost() &amp;&amp; $editForm-&gt;isValid($_POST)){ $bookTable = new App_Model_Book(); $bookTable -&gt;updateBookData( $id, //get data from submitted form $editForm-&gt;getValue('title'), //.... ); </code></pre> <p>when editing an exsiting book</p> <ol> <li>get data from getBookData() method on App_Model_Book class</li> <li>If form data is valid after submiting edited data, save data with updateBookData() method on App_Model_Book class</li> </ol> <blockquote> <p>but I saw that if I created a <strong>custom Db_Table_Row(extends Zend_Db_Table_Row) class for book table</strong> with book_section_name and data_entered_user_name <strong>I can use it for get existing book data and save it after editing</strong> book data <strong>without creating new Book(db_table) class and without calling updateBookData() to save updated data</strong>.But I don't know which <strong>code I should write on custom Db_Table_Row(extends Zend_Db_Table_Row) class</strong>.</p> </blockquote> <p>I think you can understand my problem, in simple </p> <blockquote> <p><strong>how to write a custom db_table_row class to create a custom row with data form 2 joined tables for a perticular db_table class ?</strong></p> </blockquote> <p>I'm new to zend framewok and to stackoverflow. forgive me if you confused with my first question.</p> <p>Thanks again.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload