Page 1 of 1
Need Help On How To Pass Multiple Parameters To An Action
#1
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
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
#2
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)
{
...
}
#3
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
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
kokomo, 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)
{
...
}
#4
Posted 21 December 2012 - 02:12 PM
Dear Friend
You have to create url in the following way
Regards
You have to create url in the following way
Yii::app()->createUrl("fooController/someAction",array("int"=>"someNumber","cat"=>"someString","foo"=>"something"));
Regards
#6
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
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
seenivasan, on 21 December 2012 - 02:12 PM, said:
Dear Friend
You have to create url in the following way
Regards
You have to create url in the following way
Yii::app()->createUrl("fooController/someAction",array("int"=>"someNumber","cat"=>"someString","foo"=>"something"));
Regards
#7
Posted 08 January 2013 - 02:20 AM
- do you use the controllerId (foo not fooController)?
- you should find more information in the application.log file.
- debug the request.
//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.
#8
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
views/trial/one.php
views/trial/two.php
I hope I helped a bit.
Regards.
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.
Share this topic:
Page 1 of 1

Help














