Welcome Guest, Not a member yet? Register   Sign In
Remove class from url.
#1

[eluser]Girgoo[/eluser]
Hi

I am new to codeigniter and have found it useful.
The URL should be example.com/class/function/ID as it sas in the documentation.
But what if i would like to have a url look like this?

example.com/username/article
example.com/John/dogs

The problem is that John is not a class.
Can i solve this with codeigniter?
#2

[eluser]Dam1an[/eluser]
Hi, welcome to CI
You can acheive what you want using routing
#3

[eluser]Girgoo[/eluser]
Thx! It works perfect.

I use now something like this

$route[':any/:any'] = "blog/lookup_username_and_article/";

And remeber that the url is changed so you will have to edit your uri segment;
$this->db->where('username',$this->uri->segment(1),'article', $this->uri->segment(2));
#4

[eluser]Dam1an[/eluser]
Another solution would be to do
Code:
// Route
// Insert other routes here for pages which exist
$route['(:any)/(:any)'] = 'blog/find/$1/$2';

// Blog controller
function find($username, $article) {
    // This should really be in a model
    $this->db->where('username', $username);
    $this->db->where('article', $article);
    // Rest of DB logic
}
#5

[eluser]Girgoo[/eluser]
That looks much better,thx again!

I have to learn more syntax I see.




Theme © iAndrew 2016 - Forum software by © MyBB