ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Get value of "Last " URI / URL segment with total_segments

April 11, 2008 5:41am

Subscribe [3]
  • #1 / Apr 11, 2008 5:41am

    geshan's avatar

    geshan

    54 posts

    A code like below:

    //in library
    $ts=$this->CI->uri->total_segments();
    $offset= $this->CI->uri->segment($ts);    
    
    //in controller
    $ts=$this->uri->total_segments();
    $offset= $this->uri->segment($ts);

    This gives you the value of the last segment of your URL, it is very useful when you paginate and need the value of the offset.

    Geshan

  • #2 / Apr 11, 2008 5:54am

    xwero

    4145 posts

    I was looking for the same thing today but for another purpose. I came up with this solution

    $last = end($this->uri->segments);

    segments is a class variable.

  • #3 / Apr 11, 2008 6:09am

    geshan's avatar

    geshan

    54 posts

    I didn’t know about end well I’ll see what it does as well, thanks.

    Geshan

  • #4 / Aug 12, 2013 12:53pm

    seotags's avatar

    seotags

    1 posts

    <?=(end($this->uri->segments)=="<IF_STATEMENT>"?"<IF_TRUE>":"<IF_NOT_TRUE>");?>


    You could use something like this to query the last part of an url.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases