-1
私の最初のCodeIgniterプロジェクトでアイテムの編集や更新ができません。編集ボタンをクリックすると、最初にデータベース上のその項目の情報が入力されたビューがロードされますが、使用しているブートストラップはロードされません。その後CodeIgniterでのアイテムの編集と更新
、私は「編集」ボタンをクリックして、以下のことを言って、エラーの多くを返します。コントローラ上
私の関数は、引数が不足していると変数が定義されていない、と
私のビューは定義されていないオフセットを持ち、非オブジェクトのプロパティを取得しようとしています。
CRUDの他のコマンドはすべてこれ以外で機能しています。
私が使用しているのCodeIgniterのバージョンである2.2.6
コード:
モデル:
function edit($id) { $this->db->where('id', $id); $query = $this->db->get('products'); return $query->result(); } function update($data) { $this->db->where('id', $data['id']); $this->db->set($data); return $this->db->update('products'); }
コントローラー:
function edit($id) { $data['title'] = "Edit Product"; $data['product_data'] = $this->model->edit($id); $this->load->view('productEdit', $data); } function update() { $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<span>', '</span>'); $validations = array( array( 'field' => 'name', 'label' => 'Name', 'rules' => 'trim|required|max_length[255]' ), array( 'field' => 'price', 'label' => 'Price', 'rules' => 'trim|required|max_length[255]' ), array( 'field' => 'stock_quantity', 'label' => 'In Stock', 'rules' => 'trim|required|max_length[255]' ) ); $this->form_validation->set_rules($validations); if ($this->form_validation->run() === FALSE) { $this->edit($this->input->post('id')); } else { $data['id'] = $this->input->post('id'); $data['name'] = $this->input->post('name'); $data['price'] = $this->input->post('price'); $data['stock_quantity'] = $this->input->post('stock_quantity'); if ($this->model->update($data)) { redirect('products'); } else { log_message('error', 'Error'); } } }
表示:
<?php echo form_open('products/edit/', 'id="form-products"'); ?> <input type="hidden" name="id" value="<?php echo $product_data[0]->id; ?>"/> <label for="nome">Product Name:</label><br/> <input type="text" name="name" value="<?php echo $product_data[0]->name; ?>"/> <div class="error"><?php echo form_error('name'); ?></div> <label for="email">Price:</label><br/> <input type="text" name="price" value="<?php echo $product_data[0]->price; ?>"/> <div class="error"><?php echo form_error('price'); ?></div> <label for="email">In Stock:</label><br/> <input type="text" name="stock_quantity" value="<?php echo $product_data[0]->stock_quantity; ?>"/> <div class="error"><?php echo form_error('stock_quantity'); ?></div> <input type="submit" name="update" value="Update" /> <?php echo form_close(); ?>
はお時間をいただき、ありがとうございます。