• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
URI sesgment

#1
[eluser]anis2505[/eluser]
Hi could someone explain the difference between the following

Code:
function afunction($id)
{
      echo $id;
}
And
Code:
function afunction()
{
     $id = $this->uri->segment(3);
      echo $id;
}

should I use $this->uri->segment(3) or it's the same
As I see all people use the uri->segment way

Hope it's clear

regards

#2
[eluser]jairoh_[/eluser]
if your controller is not under in another folder in a constructor folder. it's the same sir.

#3
[eluser]Pert[/eluser]
In first example following URL would fail <b>/controller/afunction/</b> because $id is required by method statement.

If you assign default value you can easily work around it
Code:
function afunction($id = null)
{
   ...
}

You might think if you do keep generating links, people won't see pages without $id set, but as they can delete id easily from browser location bar or search engines might want to try break up URLs, so it's always good to prepare for everything.

But other than that, it really is more personal preference how you want to deal with URLs and what makes sense in your application.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.