我正在使用CodeIgniter在網站上工作,無法弄清楚爲什麼我的函數沒有返回數組,這應該很簡單。PHP不傳遞數據數組?
在返回之前,我在模型中做了一個轉儲,看看它是否已格式化並且有數據(這是否)。這個問題似乎是在控制器中,函數沒有返回數據,並且在視圖屬性中爲null。
可能會導致此問題的CI或PHP發生了什麼?
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');
?>
在該片段中看不到任何錯誤。是否有任何代碼可能影響$ dat(例如稍後您有$ data = array('id'=> 1);或者類似的東西?如果您已編輯代碼,您可以發佈更多控制器嗎? – Robbie
代碼外觀很好 –
你是否在'var_dump($ properties)'視圖中看到任何東西?'' –