How to create a wrapper for a js library

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.

next (#2) »

  1. Our example: uploadify
  2. Creating the widget

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

16 1
20 followers
Viewed: 22 804 times
Version: Unknown (update)
Category: How-tos
Written by: zaccaria
Last updated by: Maurizio Domba Cerin
Created on: Jun 8, 2011
Last updated: 12 years ago
Update Article

Revisions

View all history

Related Articles