Welcome Guest, Not a member yet? Register   Sign In
Any Advice for Urls for Database contents
#1

[eluser]Unknown[/eluser]
Hi all,

Recently was in search for a program for my first project; and finally opted to go with CodeIgniter. For the first time, I am using MVC Framework.

I am making some kind of directory. Just started working on it. I have some data in my database tables. I have already got the same on the site through Model-Controller-View. and then linked the individual row data to a seperate view page with the help of array.

Now my concern is, if i see my current sites address bar for individual data view page, its as under:
Code:
http://www.domain.com/index.php/page/get/1
Here, I know about the various contents of the above link.

I am confused, what if I call the same data from a different controller page as well (eg.search result, or categories, sub-categories, etc.)

Is there some way in URI Routing, that I can just have the id part for all the contents links; what I mean is as under:

Code:
http://www.domain.com/detail/1

I may have some thousands of entries in my database, each under different categories. Some may even be under two or more categoreis. So just wanted a universal looking link for all the content for this table data.

Any help or advice is appreciated.

With Regards
Jayesh.
#2

[eluser]Twisted1919[/eluser]
You can do it with routing, and more than that, you can have even nicer url's.
For example :
Code:
$routes['page/(:any)'] = "page/index/$1";
Will route any request that comes to /page/everything-i-want-here.html to the index() method from the Page controller.

You can do it without routes .
Code:
class Page extends Controller{

   public function _remap($method)
   {
      if(method_exists($this,$method))
      {
        $this->$method();
      }
      else
      {
        $this->index();
      }
   }


    public function index()
    {
       $url = $this->uri->segment(2);//this is: everything-i-want-here
       // then query the database for the record having that url
    }
}

And because we end up with a url like everything-i-want-here for database lookup, i usually have a "url" field in database of type varchar(250), indexed, and with the help of url_title() function from url helper , i create a friendly url using the title of the post/article and later i can take it from the uri segments and do the database look up.
#3

[eluser]Unknown[/eluser]
Thanks Twisted1919 for the advice,

I tried both, though was bit confusing to understand.
I was recently browsing through hotscripts.com site. Its too made on a MVC framework of CakePHP. I was looking for something like that they have done with their urls.

that site has thousands of datas, when we open an individual data view, the link for the same is like
Code:
http://www.hotscripts.com/listing/title_of_the_script

and when we browse through its categories its like:
Code:
http://www.hotscripts.com/category/topcategory/subcategory/subsubcategory/etc

I am, looking for some same solution. Can any one advice me how can I get it...?

Regards,
Jayesh




Theme © iAndrew 2016 - Forum software by © MyBB