Issue
I have an anchor link where the data-url has a value of a yii create url like this
<a href="#" id="download-button" data-url="<?php echo Yii::app()->createUrl('controllerName/actionName',array('var1'=>'var1_value', 'var2' => 'var2_value', 'var3' => '?')); ?>" data-chosen-type="">CLICK ME</a>
so the situation is like this, you see the data-chosen-type="" attribute?, the value is actually being set by a javascript. Now what I want to happen is, grab the value of data-chosen-type attribute and place it to 'var3' value, within the array inside that createUrl thing. So the output should be like this
<a href="#" id="download-button" data-url="<?php echo Yii::app()->createUrl('controllerName/actionName',array('var1'=>'var1_value', 'var2' => 'var2_value', 'var3' => 'value of data-chosen-type')); ?>" data-chosen-type="">CLICK ME</a>
is that possible to do? I tried doing this
'var3' => "js:$('#download-button').attr('data-chosen-type')"
it didn't work, but in a view file especially in CGridView, putting javascript in a value of a key pair does work...how come in createUrl I wasn't able to do the same thing? am I doing it wrongly?
Solution
No, that is not possible, because PHP is long done before anything JavaScripty happens on the client.
If you can not determine the value on the server-side at all - then make an AJAX request to the server, so that you can call the createUrl method there with the correct parameters, and then set the link data-url attribute with the returned URL.
Answered By - CBroe
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.