urls

This is probably so simple but I haven’t been able to work it out in the last few hours

So here’s what I’m trying to do I have a URL where id like to pass a id in to

 eg www.somedomain.com/test/index.php/random/12

Now with the following code i can get the "random" part of the URL but cant work out how to get the "12" part of the URL




<?php


class randomController extends Controller

{

        public function actionIndex()

        {

                $this->render('index');

        }


        public function actionView()

        {

                $this->render('view', array('id'=>$this->get));

        }


}

?>



the view page looks like




<H1>View</H1>

<?php

        print "data is " . $id  . "<BR>";


?>



Any suggestions would be much appreciated

id is stored in the $_GET array, so you can retrieve it anywhere this way: $_GET[‘id’].


id is stored in the $_GET array, so you can retrieve it anywhere this way: $_GET['id']

if I’m not wrong, this $_GET[‘id’] is numeric type.

so the preg_match just receive number only.

the value like :‘www.somedomain.com/test/index.php/random/1202R’, will not work, although the value is primary key.

A little off-topic note: If register_globals is turned on in PHP configuration then he can also use $id in place of $_GET[‘id’]. But AFAIK there aren’t many people (servers, hostings, admins) that allow of register_globals in PHP this days, due to security manners.

How is your URL Manager configured?

Do you have this line in your rules:

‘<controller:\w+>/<id:\d+>’=>’<controller>/view’

Also, as of Yii 1.1.4 you can access the data this way:




public function actionView($id)

{

   $this->render('view', array('id'=>(int)$id));

}



See: http://www.yiiframework.com/doc/guide/1.1/en/basics.controller#action-parameter-binding