system
June 10, 2011, 10:29am
1
hello all
Question about CodeIgniter:
to routes for change url of http://localhost/blog/index?id=16/ to http://localhost/blog/16/ add $route[‘blog’] = “index?id=”; but not work address http://localhost/blog/16 and have error:
404 Page Not Found
The page you requested was not found.
why?
You cannot use the query string by default in CodeIgniter; check this manual page for more.
system
June 10, 2011, 11:00am
3
thanks
i checked URI Class but don’t understand.
Please tell me where is the problem to post #1 ?
You need to understand how the controllers work, unless you configure it differently, you will normally have a 2 segment URI.
So, your URI to view a blog post would be /blog /view /16 for example. Blog being the controller and view being a method inside the Blog controller.
system
June 10, 2011, 12:38pm
5
i want remowe
?id=
of this url:
http://localhost/blog?id=16
this change to:
http://localhost/blog/16
my .htaccess is:
RewriteEngine on
RewriteCond $1 !^(index\\.php|resources|robots\\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
did must use of routes or .htaccess? what do i do?
Read the section called “Enabling Query Strings” in the first link I posted.
Stop using the .htaccess altogether for now, then enable query string support in CodeIgniter.
Once you have ?c=blog&id=16 routing to your Blog controller, you can look to tweak your .htaccess to suit.
system
June 10, 2011, 1:11pm
8
thanks, i test _remap and work.
function _remap( $method )
{
// $method contains the second segment of your URI
switch( $method )
{
case 'hello':
$this->index();
break;
}
}
with this code, change url
http://localhost/blog
to
http://localhost/blog/hello
how change this code for any dynamic id? and replace $row->subject with hello?
my CI_Controller is:
<?php
class Blog extends CI_Controller {
function __construct()
{
parent::__construct();
}
function _remap( $method )
{
// $method contains the second segment of your URI
switch( $method )
{
case 'hello':
$this->index();
break;
}
}
/**/
function index()
{
$g_subject = $this->input->get('id', TRUE);
$query = $this->db->get_where('miniblog', array('id' => $g_subject));
foreach ($query->result() as $row)
{
$data = array(
'subject' => $row->subject,
'title' => $row->title,
'image_path' => $row->image_path,
'alt' => $row->alt,
'text' => $row->text,
'date' => $row->date,
);
}
$this->load->view('miniblog/blog', $data);
//add customer size to databe on customer
//$this->customer_size_model->show();
}
function ipv6()
{
$this->load->view('miniblog/ipv6');
}
}
?>
system
June 10, 2011, 3:02pm
9
I sorry,I surmise not true top code (post #7 ) because you not answer.
i TRUE enable_query_strings to config and go to address http://localhost/?c=blog&id=16 that work.
1)TRUE enable_query_strings to config not problem security?
2)did must remove with .htaccess this segment of url: ?c=blog&id=?
3)what do i do? how removing this segment?
{afterwards i want add subject news to url for that page.
lik:
subject: this is CodeIgniter
url: www.mysite.com/news/this is CodeIgniter }