1

I'm working on a site with CodeIgniter and can't figure out why my function is not returning the array, this should be simple.

I did a dump in the model before returning just to see if it was formatted and had the data (which is does). The issue seems to be in the controller the function is not returning the data and in the view properties is null.

What is happening with CI or PHP that might cause this?

Controller: 
function galleryManagement()
{
    if (! $this->session->userdata('is_admin'))
    {
        redirect('admin/index');
    }
    else
    {
        /*
        $selectedProperty = $this->input->post('selectedProperty');
        switch ($selectedProperty)
        {
            case "westgate":
                $selectedID = '1';
                break;
            case "prospector436":
                $selectedID = '2';
                break;
            case "prospector437":
                $selectedID = '3';
                break;
            case "prospectorcombo":
                $selectedID = '4';
                break;
            default:
                $selectedID = '-1';
        }
        if ($selectedID != '-1')
        {
        */
            $this->load->model('admin_model');
            $propertyObj = $this->admin_model->getProperties();
            $data['properties'] = $propertyObj;
            $data['propertyID'] = $selectedID;
            $data['galleryObj'] = $this->admin_model->getGallery($selectedProperty);
            //$data['textarea'] = array ( 'name' => 'altText', 'style' => "width: 320px; height: 36px;" );
            $this->load->view('db_site/admin_gallery_view', $data);
        /*
        }
        else
        {
            $this->load->model('admin_model');
            $data['propertiesObj'] = $this->admin_model->getProperties();
            $data['propertyID'] = $selectedID;
            $this->load->view('db_site/admin_gallery_view', $data);
        }
        */
    }
}

Model:
function getProperties()
{
    $this->db->select('property_id, name');
    $this->db->from('property');
    $q = $this->db->get();

    if ($q->num_rows != 0)
    {
        $propertiesObj = $q->result();
        foreach ($propertiesObj as $property)
        {
            $properties[$property->name] = $property->property_id;
        }
        echo "Model Dump: ";
        var_dump($properties);
        return $properties;
    }
    else
    {
        return false;
    }
}

View:
<?php
    var_dump($properties);
    echo form_open('admin/galleryManagement');
    echo "<p>Property: " . form_dropdown('selectedProperty', $properties) . "</p>";        
    echo form_submit('select', 'Select');
?>
4

1 回答 1

2

在您看来,您使用$properties的不是$data控制器的 else 块数组中传递的。如果您如下更改控制器的 else 块,它将起作用。

    else
    {
        $this->load->model('admin_model');
        $data['properties'] = $this->admin_model->getProperties();
        $data['propertyID'] = $selectedID;
        $this->load->view('db_site/admin_gallery_view', $data);
    }

编辑

从您最近的编辑来看,您似乎已经评论了else我正在谈论的块。你还有问题吗??

于 2012-09-03T01:54:11.550 回答