Yii Framework Forum: Need Help On How To Pass Multiple Parameters To An Action - Yii Framework Forum

Jump to content

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

Need Help On How To Pass Multiple Parameters To An Action Rate Topic: -----

#1 User is offline   Ruben E. 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 30-November 12

Posted 20 December 2012 - 04:35 PM

Hi there,
could anybody give some advice on how to configure the action to accept multiple parameters? let's say, the URL is something like this:

www.domain.com/index.php/FooController/SomeAction/params

where params could be something like

cat/id

or

cat=3/id=5

or

cat=5&id=6&foo=something

I realized that my actual configuration only accepts one numeric parameter to be handled by

public function actionFoo ($int)
{
...
}

I appreciate your help
1

#2 User is offline   kokomo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 289
  • Joined: 23-July 10

Posted 21 December 2012 - 03:49 AM

Found it in this comment of the controller section (action parameter binding) of the guide:

// $int is needed
// $cat is optional with default value
// $foo is optional with no default value
public function actionFoo ($int, $cat='default value if you need it', $foo=null)
{
...
}

0

#3 User is offline   Ruben E. 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 30-November 12

Posted 21 December 2012 - 12:16 PM

Oks,
but, how you build the url so the function accepts both paramaters?

i tried

/index.php/NameController/Foo/3/4

and it dont works

many thanks for your help



View Postkokomo, on 21 December 2012 - 03:49 AM, said:

Found it in this comment of the controller section (action parameter binding) of the guide:

// $int is needed
// $cat is optional with default value
// $foo is optional with no default value
public function actionFoo ($int, $cat='default value if you need it', $foo=null)
{
...
}


0

#4 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 21 December 2012 - 02:12 PM

Dear Friend

You have to create url in the following way

Yii::app()->createUrl("fooController/someAction",array("int"=>"someNumber","cat"=>"someString","foo"=>"something"));


Regards
0

#5 User is offline   Ruben E. 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 30-November 12

Posted 22 December 2012 - 06:10 PM

I will try this

many thanks for your help

View Postseenivasan, on 21 December 2012 - 02:12 PM, said:

Dear Friend

You have to create url in the following way

Yii::app()->createUrl("fooController/someAction",array("int"=>"someNumber","cat"=>"someString","foo"=>"something"));


Regards

0

#6 User is offline   Ruben E. 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 30-November 12

Posted 07 January 2013 - 07:25 PM

Dear friend,

after chritsmas holidays we're now working.

Could you please tellme whats wrong on this:

public function actionFoo ($int, $cmf='0')
{
...
}

I build the link using

Yii::app()->createUrl("fooController/foo",array("int"=>"1","cfm"=>"8"));

then the builded link is

http://.../fooContro...t=1&cfm=%228%22

when you click on this link you receive this error from yii

Error 400
Your request is invalid.

Could you please help me on what im doing wrong?

thanks in advance


View Postseenivasan, on 21 December 2012 - 02:12 PM, said:

Dear Friend

You have to create url in the following way

Yii::app()->createUrl("fooController/someAction",array("int"=>"someNumber","cat"=>"someString","foo"=>"something"));


Regards

0

#7 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 682
  • Joined: 12-September 10
  • Location:Austria

Posted 08 January 2013 - 02:20 AM

- do you use the controllerId (foo not fooController)?

     //wrong: Yii::app()->createUrl("fooController/foo",array("int"=>"1","cfm"=>"8")); 
     Yii::app()->createUrl("foo/foo",array("int"=>"1","cfm"=>"8"));


- you should find more information in the application.log file.

- debug the request.
0

#8 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 08 January 2013 - 08:36 AM

Dear Friend

Let us consider an example.

We have one controller TrialController.php in controller folder.

Then we have two views one.php and two.php in views/trial folder.

TrialController.php
<?php
class TrialController extends Controller
{
	
       // action one renders view one and displays the link.
	public function actionOne()
        {
		$this->render("one");
	}   

	public function actionTwo($id,$name)
       { 
             //$id and $name are available inside the method.You can do whatever logic you can do with them
             //Here we are just passing them to the view.	
	        $this->render("two",array("id"=>$id,"name"=>$name));
	}      
}



views/trial/one.php
<?php
$id=1;
$name="someValue";

//You can also pass dynamic variable from form submission or database tables.

echo CHtml::link("click",array("trial/two","id"=>$id,"name"=>$name));

//Here CHtml::link calls CHtml::normalizeUrl and creates url from the second parameter.
?>


views/trial/two.php
<?php
echo "your id is :".$id;
echo "</br>";
echo "your name is :".$name;
?>


I hope I helped a bit.

Regards.
0

Share this topic:


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

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