Viewing 2 replies - 1 through 2 (of 2 total)
  • AS far as I know you have to provide the list yourself to the belongs_to_dropdown() function.

    The way to do it is to override the add and the edit functions in your admin controller and to query it there then use set_object to make it available in the view (where the belongs_to_dropdown call is).

    Have a look at the event-calendar-example for an example:
    \plugins\events-calendar-example\app\controllers\admin\admin_events_controller.php

    Thread Starter kevcpu

    (@kevcpu)

    I am trying this and to shed some additional light, here is my set_post method:

    private function set_post() {
    		$this->load_model('Post');
    		$posts = $this->Post->find(array('selects' => array('id', 'post_title')));
    		$this->set('posts', $posts);
    
    	}

    In the dropdown I want to use the id field and the post_title as the text. Also, here is the call I am making to the belongs_to_dropdown:

    echo $this->form->belongs_to_dropdown('Post', $posts, array('style' => 'width: 200px;', 'empty' => true, 'id' => 'drpPost', 'label' => 'Post connected to entry'));

    The dropdown populates and the text field is empty, but the id field is populated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: WP MVC] belongs_to_dropdown does not populate’ is closed to new replies.