Customer Portal

Get Involved. Join the Conversation.

Topic

    PGP_Monty
    $this->uri->segment_array(); gives an error...Answered
    Topic posted September 2, 2009 by PGP_Monty Green Ribbon: 100+ Points, last edited October 29, 2011 
    2004 Views, 2 Comments
    Title:
    $this->uri->segment_array(); gives an error instead of an array
    Content:

    I pretty much added the following to your sample widget in the controller:

     

    $segs = $this->uri->segment_array();

    foreach ($segs as $segment)

    {

    echo $segment;

    echo '<br/>'

    }

     

    and I get a 500 internal server error when I call the widget in a page.  Can I not use that?

    I

    Best Comment

    Leif Wickland
    In many places in CP, the $this variable refers to the CodeIgniter object. However, in widgets, that's not the case. The CodeIgniter object is stored as the CI member of the widget object.

    The following should work.


    $segs = $this->CI->uri->segment_array();
    foreach ($segs as $segment)
    {
    echo $segment;
    echo '<br/>'
    }

    Comment

     

    • Leif Wickland
      In many places in CP, the $this variable refers to the CodeIgniter object. However, in widgets, that's not the case. The CodeIgniter object is stored as the CI member of the widget object.

      The following should work.


      $segs = $this->CI->uri->segment_array();
      foreach ($segs as $segment)
      {
      echo $segment;
      echo '<br/>'
      }
    • Leif Wickland
      Also, there should've been a semicolon after the second echo:

      $segs = $this->CI->uri->segment_array();
      foreach ($segs as $segment)
      {
      echo $segment;
      echo '<br/>';
      }