CodeIgniter Forums

Full Version: Creating a form dropdown from db
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[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.

El Forum

[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 */

El Forum

[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

El Forum

[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

El Forum

[eluser]Bionicjoe[/eluser]
Beautiful!

You got it!!
Pages: 1 2