i need to create an url like this: http://www.example.com/index.php/scheda/name-surname-id.html
so i create the Scheda controller, this is the code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Scheda extends CI_Controller{
function __construct(){
parent::__construct();
}
function index(){
$name_scheda = $this->uri->segment(2);
//i need only the id for the search into db
$id = substr($name_scheda, strripos($name_scheda,'-')+1, strlen($name_scheda));
echo "name:".$id;
}
}
but when i write the url in the address bar i get an 404 error…can someone help me to understand why?
Your url:
Should be:
index()is the default method, but theindexsegment can only be missing from the URL if there are no arguments, otherwise Codeigniter will think you are trying to call the methodname-surname-id.html().You can use
routes.phpor_remap()to clean up the URL and remove theindexsegment.OR: