CodeIgniter Forums
Creating a form dropdown from db - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Creating a form dropdown from db (/showthread.php?tid=27637)

Pages: 1 2


Creating a form dropdown from db - El Forum - 02-17-2010

[eluser]laytone[/eluser]
What Template parser are you using? How / where do you send data to your views? that drop down options array needs to be include in your load->view like this:

Code:
$pagedata['dropdownoptions'] = $this->your_model->your_get_list_function();
$pagedata['examplevar'] = "hello world";
$this->load->view('view_name', $pagedata);

After this is done there is a variable called $dropdownoptions and a variable called $examplevar in your view.


Creating a form dropdown from db - El Forum - 02-17-2010

[eluser]Bionicjoe[/eluser]
Got all my template stuff from Simple Template

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Template {
        var $template_data = array();
        
        function set($name, $value)
        {
            $this->template_data[$name] = $value;
        }
    
        function load($template = '', $view = '' , $view_data = array(), $return = FALSE)
        {              
            $this->CI =& get_instance();
            $this->set('contents', $this->CI->load->view($view, $view_data, TRUE));            
            return $this->CI->load->view($template, $this->template_data, $return);
        }
}

/* End of file Template.php */
/* Location: ./system/application/libraries/Template.php */



Creating a form dropdown from db - El Forum - 02-17-2010

[eluser]laytone[/eluser]
Everything looks good then.. make sure there is a $ in front of dropdownoptions

Quote:Added code. Same issue.

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: dropdownoptions

Filename: views/addticket_view.php

Line Number: 2



Creating a form dropdown from db - El Forum - 02-17-2010

[eluser]laytone[/eluser]
Ok, here we go, I think I got it:

Code:
function addticket()
    {
        $this->template->set('title', 'Add ticket');
        $this->template->set('heading', 'Add Ticket');
        
        $this->load->model('outage_model');
        $viewdata['dropdownoptions'] = $this->outage_model->sitedropdown();
            
        $this->template->load('template', 'addticket_view', $viewdata);
    }

I bet that works


Creating a form dropdown from db - El Forum - 02-17-2010

[eluser]Bionicjoe[/eluser]
Beautiful!

You got it!!