Yii Framework Forum: Need help get URI Segment - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Need help get URI Segment Rate Topic: -----

#1 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 16 February 2010 - 10:38 PM

I using smarty for template renderer.
it is the views

<ul class="tabs">
        {section name="id" loop=$this->dataArray.menu}
            {if $this->currentAction == $this->dataArray.menu[id].action} // $this->currentAction is still null and need help to resolved
                <li><a href="{$this->dataArray.menu[id].url}" class="current"><span>{$this->dataArray.menu[id].label}</span></a></li>
            {else}
                <li><a href="{$this->dataArray.menu[id].url}"><span>{$this->dataArray.menu[id].label}</span></a></li>
            {/if}
        {/section}
</ul>


I want to diff between two of <LI>, if the menu (<li>) is clicked then change class to "current", and it will marking the current menu.

the problem is. how to know the URI segment example :

http://myblog.com/in...site/about&id=5

how to get "site/about&id=5"

of if I using pathURL. eg:
http://myblog.com/site/about/id/5

how to get "site/about/id/5"

I need help. please..

thanks before and after....
Thanks and Kind Regards
------
DanDinDun
0

#2 User is offline   dimis283 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 277
  • Joined: 24-January 09

Posted 17 February 2010 - 02:41 AM

Did you try $_GET['ID'] ?
Posted Image
0

#3 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 17 February 2010 - 03:09 AM

View Postdimis283, on 17 February 2010 - 02:41 AM, said:

Did you try $_GET['ID'] ?


Oh ya.. as you said. I have tried $_GET['ID']. but there are no result.

so I trying add this method in CSmartyViewRenderer.php

        public static function getCurrentUrl(){
            $resUri = $newUri = $url   = array();
            $url[] = Yii::app()->controller->id;
            $url[] = Yii::app()->controller->action->id;
            $finalUrl = join('/',$url);
            $replacement = 'r='.$finalUrl;
            if (Yii::app()->urlManager->urlFormat == 'get'){
                $uri = explode('&',$_SERVER['QUERY_STRING']);
                foreach($uri as $v){
                    if($v != $replacement){
                        $newUri[] = $v;
                    }
                }

                if(count($newUri) > 0){
                    foreach($newUri as $kv){
                        $nn = explode('=',$kv);
                        $resUri[$nn[0]] = $nn[1];
                    }
                }
                return Yii::app()->urlManager->createUrl($finalUrl,$resUri);

            }else{
                return $_SERVER['REQUEST_URI'];
            }
        }


and works :-) Alhamdulillah..

thanks dimis283 for your attention :-)
Thanks and Kind Regards
------
DanDinDun
0

#4 User is offline   Hasan Demir 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 13-May 13

Posted 11 October 2014 - 05:45 PM

Here is the solution , you can uri component use like this ; Yii::app()->uri->segment(2);

for details follow url

www.hasandemir.com/how-to-get-contoller-action-segments-like-codeigniter
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users