Jump to content

codeigniter routing error


colap

Recommended Posts

http://mysite/products/create

 

    Not Found

   

    The requested URL /products/create was not found on this server.
    Apache/2.2.16 (Debian) Server at site5.example.com Port 80

 

 

routes.php =>

 

    $route['default_controller'] = 'products';

    $route['404_override'] = '';

 

 

model =>


    <?php
    class Products_model extends CI_Model {
    
    	function __construct()
    	{
    		$this->load->database();
    
    	}
    	
    	function get_products($slug = FALSE)
    	{
    		if ($slug === FALSE)
    		{
    			$query = $this->db->get('products');
    			return $query->result_array();
    
    		}
    	
    		$query = $this->db->get_where('products', array('slug' => $slug));
    		return $query->row_array();
    	}
    	
    	function set_products()
    	{
    		$this->load->helper('url');
    	
    		$slug = url_title($this->input->post('title'), 'dash', TRUE);
    	
    		$data = array(
    			'title' => $this->input->post('title'),
    			'slug' => $slug,
    			'text' => $this->input->post('text')
    		);
    	
    		return $this->db->insert('products', $data);
    	
    	}
    
    }

 

 

 

 

controller =>

 

    <?php
    class Products extends CI_Controller {
    
    	function __construct()
    	{
    		parent::__construct();
    		$this->load->model('products_model');
    
    	}
    
    	function index()
    	{
    		$data['products'] = $this->products_model->get_products();
    		$data['title'] = 'Products archive';
    		$this->load->view('products/index', $data);
    	}
    
    	function view($slug)
    	{
    		$data['products'] = $this->news_model->get_news($slug);
    	}
    	
    	function create()
    	{
    		$this->load->helper('form');
    		$this->load->library('form_validation');
    	
    		$data['title'] = 'Create a products item';
    	
    		$this->form_validation->set_rules('title', 'Title', 'required');
    		$this->form_validation->set_rules('text', 'text', 'required');
    	
    		if ($this->form_validation->run() === FALSE)
    		{
    			//$this->load->view('templates/header', $data);	
    			$this->load->view('products/create');
    			//$this->load->view('templates/footer');
    		
    		}
    		else
    		{
    			$this->news_model->set_news();
    			$this->load->view('products/success');
    		}	
    	}
    	
    }
    ?>

 

 

view =>

    <h2>Create a news item</h2>
    
    <?php echo validation_errors(); ?>
    
    <?php echo form_open('products/create') ?>
    
    	<label for="title">Title</label> 
    	<input type="input" name="title" /><br />
    
    	<label for="text">Text</label>
    	<textarea name="text"></textarea><br />
    	
    	<input type="submit" name="submit" value="Create news item" /> 
    
    </form>

 

 

Why did i get this error ? Where is the error ?

Link to comment
Share on other sites

I tested similar code in my local CI playground, and it works fine, so as thorpe said, check mod_rewrite, and also check your .htaccess file. For reference, here is mine:

 

RewriteEngine On
RewriteBase /
RewriteRule ^(system|application|cgi-bin) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

Link to comment
Share on other sites

  • 2 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.