You are viewing revision #1 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.
In this wiki will be explained how to include a javascript library in a widget.
We will use as example uploadify, a flash/javascript plugin for file uploading.
Our example: uploadify ¶
Let's imagine we have a page with a file field, and we want to exchange with a uploadify.
The first step is to create a widget that will replace this file field.
Creating the widget ¶
Let's create a file in components named ZUploadify:
<?php
class ZUploadify extends CInputWidget
{
public function run()
{
$this->render('ZUploadify', array('model'=>$this->model, 'attribute'=>$this->attribute));
}
}
We extend CInputWidget, the base widget for input field. This masterclass give use the attributes 'model' and 'attribute'.
In components/views we can add:
<?php echo CHtml::activeFileField($model, $attribute);?>
And instead of the file field in our form we can place:
<?php $this->widget('ZUploadify', array('model'=>$model, 'attribute'=>'file')); ?>
Excellent! Now we have a widget wich works exactly how worked CHtml::activeFileField(), we can move forward for use uploadify
Import uploadify
note
The aim of the widget is not using effectively uploadify (for this there is already the documentation of uploadify), but explain the technique and the functions needed for create a wrappar for a js library
How can I access to the value of the field?
The component use:
$id= CHtml::activeId($this->model, $this->attribute);
but i want use the value of field.
$this->model->value_of_field
How can I do?
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.