It will not be possible to access the url, or any other attribute of an extension, when the extension is being initialized. But we can access the attribute after the widget has been initialized.
When you call $this->widget('extension', array( ... ));
the widget is being initialized, so the options passed in the array can't be immediately used within another option. In your case you are trying to access the property url
within the property options
.
To use the property we have to:
Store a reference to the widget after it has been initialized, like:
$xwidget = $this->widget('extension', array( ... ));
Then use/access a property :
$xwidget->propertyname;
For your exact scenario when you want to pass the property to a js function, you will additionally have to do the following:
Instead of passing an anonymous function to the submit
option, pass a function reference:
'options' => array('submit' => 'submitHandler')
Then either register a script with registerScript
or use direct html <script>
tag, and access the widget's property in it:
Yii::app()->clientScript->registerScript('script-id','
function submitHandler() {
var url = "'. $xwidget->url .'"; // this is how we can insert the property into js
// ... more code ...
}',
CClientScript::POS_END// the position of the script
);
${url}
to put into yourjs:function...
string? And to make it into actual url value by Yii?