0

I have a table *sitepage_manageadmins* which contain: " user_id, page_id ". There is another table *sitepage_pages* which contain " page_id, title ".

Im trying to render as dropdown ( select list ) in Zend_Form the user which is admin to relevant page_id .

Here is my code:

$this->view->owner_id = $viewer_id = $viewer->getIdentity();  // get $viewer
$adminpages = Engine_Api::_()->getDbtable('manageadmins', 'sitepage')->getManageAdminPages($viewer_id); // get viewer page_id's where is admin

Getting the page_id as dropdown list:

$ids = array ( 0 => '-- Select --');
    foreach ($adminpages as $adminpage) {
        $ids[] = $adminpage->page_id;
    }

Rendering the dropdown

$this->addElement('select', 'page_id', array (
                'label' => 'Page where I'm Admin',
                'multioptions' => $ids,
)); 

For now, im only render the Page_ID numbers as dropdown. I want from Specific Page_ID to render the Title.

Any ideas are welcome? Thanks

Seik
  • 41
  • 5

1 Answers1

0

This is because you are putting only the ids to the $ids[] array The multioption array should be key-value pair in this case page_id as key & page_title as value.
foreach ($adminpages as $adminpage) {
$ids[$adminpage->page_id] = $adminpage->page_title;
}

Nandakumar V
  • 4,317
  • 4
  • 27
  • 47
  • Regarding to my connection from database, my table dosen't have field page_title, so if i connect on this way, im getting error. The solution i think is to join where sitepage_pages have Page ID from manageadmins viewer ID, and from that ID To get the Page Title. – Seik Oct 22 '12 at 10:05
  • sorry for that.. i thought you had joined it already in `getManageAdminPages()`. Got confused with `page_id` from the two tables – Nandakumar V Oct 22 '12 at 12:16
  • `$select = $this->select() ->from('sitepage_manageadmins') ->joinLeft(array('page'=>'sitepage_pages''),'page.page_id ='sitepage_manageadmins.page_id', array('page.page_id AS pageid','title AS page_title')) ->where('user_id = ?', $viewer_id); ` – Nandakumar V Oct 22 '12 at 12:17
  • Im getting PHP Error on : 'page.page_id ='sitepage_manageadmins.page_id' – Seik Oct 22 '12 at 17:20
  • can you specify the error. you can see the query by `die($select)` – Nandakumar V Oct 22 '12 at 19:01
  • This is the error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' – Seik Oct 22 '12 at 19:52
  • this error occurs when there is a syntax issues due to missing quotes, brackets .. you should paste the code in some editor and check if the syntax is proper – Nandakumar V Oct 25 '12 at 07:28
  • $select = $this->select() ->from('sitepage_manageadmins') ->joinLeft(array('page'=>'sitepage_pages'),'page.page_id = sitepage_manageadmins.page_id', array('page.page_id AS pageid','title AS page_title')) ->where('user_id = ?', $viewer_id); – Nandakumar V Oct 25 '12 at 07:31