2011-03-30 12 views
0

私が午前問題は、私はhttp://domain/admin/editpage/"id"に行くとき、私は404見つからないとidをフォームに渡されていない理由私は理解することはできません取得することです。

コントローラを

if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Editsale extends CI_Controller { 

function __construct() { 
parent::__construct(); 

} 

function index() { 
    if(!$this->session->userdata('logged_in')) { 
     redirect('admin/home'); 
    } 

     $data['title'] = "Edit Sale Name"; 
     $data['sales_pages'] = $this->sales_model->getSalesPages(); 
     $data['cms_pages'] = $this->navigation_model->getCMSPages(); 
     $id = $this->uri->segment(3); 
        $data['id'] = $id; 
     $this->load->library('form_validation'); 
     $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() === TRUE) { 
      $data = 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) 
      ); 

      $this->sales_model->updateSale($data); 

      $data['sales'] = $this->sales_model->getSalesPages(); 

      redirect('admin/addsale' , $data); 

      $this->session->set_flashdata('success', 'Page Saved'); 
     }else{ 
      $data['content'] = $this->load->view('admin/editsale', NULL, TRUE); 
      $this->load->view('template', $data); 
     } 


} 

} 

モデル

class Sales_model extends CI_Model 
{ 

function __construct() { 
     parent::__construct(); 
} 

function getSalesPages() { 

     $query = $this->db->get('sales'); 
     if($query->num_rows() > 0) return $query->result(); 

    } 

function addSale($data) { 

$this->db->insert('sales', $data); 
return; 
} 

function updateSale($id, $data) { 

    $this ->db->where('id', $id); 
    $this->db->update('sales', $data); 
} 
} 

ビュー

<?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'); 
?> 
<section id = "validation"><?php echo validation_errors();?></section> 

<?php 
echo form_open('admin/editsale/'.$id, $formEditsale); 
echo form_fieldset(); 
echo form_label('Name:', 'name'); 
echo form_input($formName); 
echo form_label ('Location', 'location'); 
echo form_input($formLocation); 
echo form_label ('Bedrooms', 'bedrooms'); 
echo form_input($formBedrooms); 
echo form_label ('Bathrooms', 'bathrooms'); 
echo form_input($formBathrooms); 
echo form_label ('Condition', 'condition'); 
echo form_input($formCondition); 
echo form_label ('Price', 'price'); 
echo form_input($formPrice); 
echo form_label ('Description', 'description'); 
echo form_textarea($formDescription); 
echo form_submit('submit','Submit'); 
echo form_fieldset_close(); 
echo form_close(); 

.htaccessをあなたはそれがビューで働いて得るためにあなたのコントローラに

$data['id']=$id; 

を追加する必要が

# Customized error messages. 
ErrorDocument 404 /index.php 

# Set the default handler. 
DirectoryIndex index.php 

# Various rewrite rules. 
<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond $1 !^(index\.php|css|js|images|files|scripts|robots\.txt) 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
</IfModule> 

# Set timezone 
SetEnv TZ Pacific/Auckland 
+1

これは私にとっては書き換えの問題に似ています – mauris

+0

私は@thephpdeveloperが正しいと思います。 CIルートを確認してください。 –

+0

/index.phpを使用すると動作しますが、動作している場合は、書き換えの問題があります... – Vamsi

答えて

1

、あなたはどちらかあなたのURIに含める必要がある

$route['admin/editsale/(:num)'] = 'admin/editsale/index/$1';

を、または別の方法を使用します:

http://domain/admin/editsale/edit/$id

indexセグメントは、uriを介してパラメータを渡していない場合、デフォルトでのみオプションです。運のベスト

http://domain/admin/editsale

0

http://domain/admin/editsale/index/$id

または設定ルート:デフォルトindexメソッドを使用しているので

+0

Arun、didnt work –

関連する問題