Hi everyone,
I’m trying to make a widget for FlexSlider, but it doesn’t work… Here’s what I got
<?php
/**
* Obtiene todos los enlaces activos
*/
class PublicidadWidget extends CWidget
{
private $_baseAssetsUrl;
public function run()
{
$this->registerClientScript();
$criteria = array('condition'=>'Estado = 1');
$model = Publicidad::model()->findAll($criteria);
$this->render('publicidad',array('model'=>$model));
}
public function registerClientScript()
{
$assets_path = dirname(__FILE__) .DIRECTORY_SEPARATOR. 'FlexSlider'.DIRECTORY_SEPARATOR;
$this->_baseAssetsUrl = Yii::app()->assetManager->publish( $assets_path );
$cs=Yii::app()->getClientScript();
$cs->registerCoreScript('jquery');
// Registrar script, css para flexslider
$this->registerAsset('flexslider.css');
$this->registerAsset('jquery.flexslider.js');
$cs->registerScript(
'publicidad',
'$(window).load(function() {
$("#publicidad").flexslider();
});',
CClientScript::POS_READY
);
}
/**
* generic function to register css or js
*/
protected function registerAsset($file)
{
$asset_path = $this->_baseAssetsUrl . '/' . $file;
if(strpos($file, '.js') !== false)
return Yii::app()->clientScript->registerScriptFile($asset_path);
else if(strpos($file, '.css') !== false)
return Yii::app()->clientScript->registerCssFile($asset_path);
return $asset_path;
}
}
?>
Everything is register, but I cannot make the div “#publicidad” a flexSlider. This code is register but it seems that don’t do anything…
$cs->registerScript(
'publicidad',
'$(window).load(function() {
$("#publicidad").flexslider();
});',
CClientScript::POS_READY
);