当我点击链接编辑销售http://domain/admin/editsale/index/21/sale-name
时出现问题我似乎加载了空白页面,所以我觉得它没有得到$id
但我无法发现我的问题。
控制器:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Editsale extends CI_Controller {
function __construct() {
parent::__construct();
}
function index($id) {
if(!$this->session->userdata('logged_in'))redirect('admin/home');
if($this->input->post('submit')) {
#Set The Validation Rules
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('location', 'Location', 'trim|required');
$this->form_validation->set_rules('bedrooms', 'Bedrooms', 'trim|is_natural');
$this->form_validation->set_rules('bathrooms', 'Bathrooms', 'trim');
$this->form_validation->set_rules('condition', 'Condition', 'trim');
$this->form_validation->set_rules('description', 'Description', 'trim');
$this->form_validation->set_rules('price', 'Price', 'trim');
if($this->form_validation->run() == FALSE) {
#Set the $data for the view if FALSE
$data['cms_pages'] = $this->navigation_model->getCMSPages($id);
$data['sales_pages'] = $this->sales_model->getSalesPages($id);
$data['sale'] = $this->sales_model->getSalesContent($id);
$data['content'] = $this->load->view('admin/editsale', $data, TRUE); #Loads the "content"
$this->load->view('admintemplate', $data); #Loads the given template and passes the $data['content'] into it
}
#Form Validation Was Correct So Lets Continue
#Lets Set What We Are Sending To The DB
$content = array(
'name' => $this->input->post('name', TRUE),
'location' => $this->input->post('location', TRUE),
'bedrooms' => $this->input->post('bedrooms', TRUE),
'bathrooms' => $this->input->post('bathrooms', TRUE),
'condition' => $this->input->post('condition', TRUE),
'description' => $this->input->post('description', TRUE),
'price' => $this->input->post('price', TRUE)
);
if($this->sales_model->updateSale($id, $content)) {
$data['success'] = TRUE; #displays sale updated
$data['cms_pages'] = $this->navigation_model->getCMSPages($id);
$data['sales_pages'] = $this->sales_model->getSalesPages($id);
$data['sale'] = $this->sales_model->getSalesContent($id);
$data['content'] = $this->load->view('admin/editsale', $data, TRUE); #Loads the "content"
} // Sale Update End
}else{
$data['cms_pages'] = $this->navigation_model->getCMSPages($id);
$data['sales_pages'] = $this->sales_model->getSalesPages($id);
$data['sale'] = $this->sales_model->getSalesContent($id);
$data['content'] = $this->load->view('admin/editsale', $data, TRUE); #Loads the "content"
}#Submit End
} #Index End
}
型号:
function getSalesPages($id = NULL) {
$query = $this->db->get('sales');
if($query->num_rows() > 0) return $query->result();
}
function getSalesContent($id = NULL) {
$this->db->where('id', $id);
$query = $this->db->get('sales', 1);
if($query->num_rows() > 0) {
$row = $query->result_array();
return $row;
}else{
return FALSE;
}
}
查看:
<?php
//Setting form attributes
$formEditSale = array('id' => 'editSale', 'name' => 'editSale');
$formName = array('id' => 'name', 'name' => 'name');
$formLocation = array('id' => 'location', 'name' => 'location');
$formBedrooms = array('id' => 'bedrooms','name' => 'bedrooms');
$formBathrooms = array('id' => 'bathrooms','name' => 'bathrooms');
$formCondition = array('id' => 'condition','name' => 'condition');
$formDescription = array('id' => 'description','name' => 'description');
$formPrice = array('id' => 'price','name' => 'price');
if($success == TRUE) {
echo '<section id = "validation">Sale Updated</section>';
}
?>
?>
<section id = "validation"><?php echo validation_errors();?></section>
<?php
echo form_open_multipart('admin/editsale/index/'.$sale[0]['id'].'/'.url_title($sale[0]['name'],'dash', TRUE),$formEditSale);
echo form_fieldset();
echo form_label('Name:', 'name');
echo form_input($formName, $sale[0]['name']);
echo form_label ('Location', 'location');
echo form_input($formLocation, $sale[0]['location']);
echo form_label ('Bedrooms', 'bedrooms');
echo form_input($formBedrooms, $sale[0]['bedrooms']);
echo form_label ('Bathrooms', 'bathrooms');
echo form_input($formBathrooms, $sale[0]['bathrooms']);
echo form_label ('Condition', 'condition');
echo form_input($formCondition, $sale[0]['condition']);
echo form_label ('Price', 'price');
echo form_input($formPrice, $sale[0]['sale']);
echo form_label ('Description', 'description');
echo form_textarea($formDescription, $sale[0]['description']);
echo form_submit('submit','Submit');
echo form_fieldset_close();
echo form_close();
答案 0 :(得分:0)
修正了,我在数据
之前加载了视图