1

I am using Yii framework 1.1.14. All I want is to pass variable (for example $var) from View to specific action(for example index) in Controller (for example VideoController). I want my code to look as following:

<a href="<?php /* Here will be route to specific controllers 
                  action with variable $var which will be 
                  passing by this way */ 
         ?>"></a>

So after click on this link, user will be redirected to url of this specific action and inside this action, there will be accessible variable $var. Is there simple way to do it by using Yii syntax? Or how it will looks like if I will want to pass multiple parameters?

1 Answer 1

2

In your view:

<a href="
    <?php
        echo $this->createUrl('controller/action', array(
            'var' => $var,
            'var2' => $var2
        ));
     ?>">
</a>

Or

<?php 
    echo CHtml::link('link text', array(
        'controller/action', 
         'var' => $var,
         'var2' => $var2
    )); 
?>

In your controller:

public function actionAction($var, $var2)
{
    //Since the createUrl as generated a $_GET parameter
    // $var will be automatically set here if you put it
    // In the method parameters
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.