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

Hi could someone explain the difference between the following

function afunction($id)
      echo $id;
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


if your controller is not under in another folder in a constructor folder. it's the same sir.

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
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.