2012-08-22 96 views
2

我正在使用CI框架開發基本應用程序。您請求的頁面未找到 - CodeIgniter

我有以下錯誤:

404 Page Not Found

The page you requested was not found.

貼在下面是我的代碼文件。

我的控制器代碼:

class Contact extends CI_Controller{ 

    function _Contact(){ 
    parent::CI_Controller(); 
    } 

    /*function main(){ 
    $this->load->model('contact_model'); 
    $data = $this->books_model->general(); 

    $this->load->view('books_main',$data); 
    }*/ 

    function input(){ 

    $this->load->helper('form'); 
    $this->load->helper('html');  
    $this->load->model('contact_model'); 

    if($this->input->post('mysubmit')==true){ 
     $this->contact_model->entry_insert(); 
    } 

    $data = $this->contact_model->general(); 

    $this->load->view('contact_input',$data); 
    } 

} 

然後在模型我有以下代碼:

class contact_model extends CI_Model{ 

    function _contact_model(){ 
    parent::Model(); 
    $this->load->helper('url');    
    } 

    function entry_insert(){ 
    $this->load->database(); 
    $data = array(
       'name'=>$this->input->post('title'), 
      'address'=>$this->input->post('author'), 

       'year'=>$this->input->post('year'), 

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

    function general(){ 

    $data['base']  = $this->config->item('base_url'); 

    $data['name']  = 'Name'; 
    $data['address']  = 'Address'; 

    $data['year']  = 'Year'; 
    $data['years']  = array('2007'=>'2007', 
           '2008'=>'2008', 
           '2009'=>'2009'); 

    $data['forminput'] = 'Student Registration'; 

    $data['fname']  = array('name'=>'name', 
           'size'=>30 
         ); 
    $data['faddress'] = array('name'=>'address', 
           'size'=>30 
         ); 

    return $data; 
    } 
} 

最後,我的看法:

<html> 
<head> 

</head> 
<body> 
<div id="header"> 
<?php $this->load->view('contact_header'); ?> 
</div> 

<?php echo heading($forminput,3) ?> 
<?php echo form_open('books/input'); ?> 
<?php echo $name  .' : '. 
     form_input($fname).br(); ?> 
<?php echo $address  .' : '. 
     form_input($faddress).br(); ?> 

<?php echo $year  .' : '. 
     form_dropdown('year',$years).br(); ?> 

<?php echo form_submit('mysubmit','Submit!'); ?> 
<?php echo form_close(); ?> 

<div id="footer"> 
<?php $this->load->view('contact_footer'); ?> 
</div> 

</body> 
</html> 

任何一個可以幫我嗎?在您的聯繫控制器

+2

什麼是您試圖訪問的URL? – Matt

+2

你的'.htaccess'看起來像什麼? – Malachi

+0

通常我們在配置項中使用index()或_remap()方法,因爲您的配置文件缺失,我們沒有您要調用的url,我們需要更多信息 – qwertzman

回答

1

刪除此:

function _Contact(){ 
    parent::CI_Controller(); 
} 

這種替換:

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

而在你接觸模型刪除此:

function _contact_model(){ 
    parent::Model(); 
    $this->load->helper('url');    
} 

這種替換:

function __construct(){ 
    parent::__construct(); 
    $this->load->helper('url'); 
} 
0

Hey,

I often had similar Problems. Usually I check the following:

  1. Check the Config file if the correct siteroot is set. I often had live server stuff in there.
  2. Check in the .htaccess if the RewriteBase is set to the correct directory.
  3. to make sure its reading the correct value an echo base_url(); (if this works its usually the .htaccess rewrite base).

Hope it helps.

r n8m [enter link description here][1]

[1]: http://ellislab.com/forums/viewthread/105880/

HMC

0

如果您開發的Windows應用程序,你可能還沒有設置的控制器和模型名稱的第一個字符作爲資本字符。

像/controllers/home.php到/controllers/Home.php

在Linux的文件名是區分大小寫。

注意: - 這是解決可能的問題。可能存在錯誤配置,服務器和路徑變量的問題。

可能重複:CodeIgniter "The page you requested was not found." error?

相關問題