05-22-2011, 07:35 AM
[eluser]Dennizzz[/eluser]
Sorry for the maybe confusing title, but had to come up with something describing the situation right? :p
So i just started learning CI and like everyone i started making a blog looking at the tutorial and than adjusting it too how i code. I like my urls clean and starting with the id first so thats what im going for, something like http://example.com/blog/3434/this-is-my-...this-blog/ so started using the htacces, got it working, and started using the routes wich is working. Now whenever i call the blog using blog/3434/ it works fine, but whenever the url has the title in it, it gives me a 404 page.
Controller
The specific model
And the route
Tried all sorts of different searching terms on the forums and wiki but could not find anything, hope someone can help me with this.
edit: Sorry posted in the wrong forums, tought i was in the right one.
Sorry for the maybe confusing title, but had to come up with something describing the situation right? :p
So i just started learning CI and like everyone i started making a blog looking at the tutorial and than adjusting it too how i code. I like my urls clean and starting with the id first so thats what im going for, something like http://example.com/blog/3434/this-is-my-...this-blog/ so started using the htacces, got it working, and started using the routes wich is working. Now whenever i call the blog using blog/3434/ it works fine, but whenever the url has the title in it, it gives me a 404 page.
Controller
Code:
class Blog extends CI_Controller {
function index() {
$this->load->model('blog_model');
$this->load->helper('url');
$this->load->helper('text');
$data['rows'] = $this->blog_model->showBlogs();
$this->load->view('blogs/blog_view', $data);
}
function view() {
$this->load->model('blog_model');
$data['rows'] = $this->blog_model->showSingleblog();
$this->load->view('blogs/blog_singleview', $data);
}
}
The specific model
Code:
function showSingleblog() {
$query = 'SELECT title, author, date, content FROM blog WHERE id = ?';
$blogid = $this->uri->segment(2);
$q = $this->db->query($query, $blogid);
if ($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
And the route
Code:
$route['blog/:num'] = "blog/view";
Tried all sorts of different searching terms on the forums and wiki but could not find anything, hope someone can help me with this.
edit: Sorry posted in the wrong forums, tought i was in the right one.