Problem With My Widget

Hi everyone,

I developed my own widget in order to display a simple link… nothing more basic, however it doesn’t work =( and I cannot see where to be honest. I’ve looked for many hours but no solution has been found until there. Which is “normal” but surprising me, it’s when page loads, the html content is well loaded until reaching my the widget div. So I can see a piece of page, elle html above the widget but nothing more.

here is the code, if you can help me =D :


<?php

class ActionButton extends CWidget {


    public $title='My title';

    public $directToLink='';

    public $csrf='';

    public $id='';

    public $src='/myApp/images/myImage.gif';

    public $style='height:10px; width:10px; padding:0px 2px 2px 0px;';

 

    public function run() {

        $this->render('actionButton');

    }

 

}

?>

widget’s view :


<div id="actionButton">   

<?php

  Yii::app()->getClientScript()->registerScriptFile(Yii::app()->baseUrl."/js/functions.js");


    echo CHtml::link('<button type="button"><img id="'.$this->id.'" src="'.$this->src.'" style="'.$this->style.'"/>'.$this->title.'</button>',

                   "",

                   array('onclick'=>"{addElement('".$this->directToLink."','#dialogBox','".$this->csrf."'); $('#dialogBox').dialog('open');}",'id'=>'addElement')

                  );

?> 


  <?php  $this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog

    'id'=>'dialogBox',

    'options'=>array(

        'title'=>'Create Element',

        'autoOpen'=>false,

        'modal'=>true,

        'width'=>350,

        'height'=>340,

    ),

));?>


<div class="divForForm"></div>

 

<?php $this->endWidget();?>

</div>

in my view :


<?php  $csrf=Yii::app()->request->csrfTokenName.'='.Yii::app()->request->csrfToken;

        $this->widget('application.components.widgets.ActionButton', array(

        'directToLink'=>$this->createUrl(''),

        'csrf'=>$csrf,

        'src'=>'/myNewApp/images/add.gif',

        'id'=>'Add2Img',

        ));

  

  ?>

I could use simple php function to do it, with another file but I would like to use yii widget.

Si if you can point out me my mistakes that would help me. Thanks :)

I think trouble is in this piece of code




 echo CHtml::link('<button type="button"><img id="'.$this->id.'" src="'.$this->src.'" style="'.$this->style.'"/>'.$this->title.'</button>',

                   "",

                   array('onclick'=>"{addElement('".$this->directToLink."','#dialogBox','".$this->csrf."'); $('#dialogBox').dialog('open');}",'id'=>'addElement')

                  );



try change it to simple


echo CHtml::link('Link Text',array('controller/action')); 

But it works if put it directly in my view, in changing variables by those I noticed in the widget call

Any further ideas ?

Ok I found it, it was just a php syntax problem, have a look in /var/log/apache2/error.log pointed me where I was wrong…