Yii-Redactor

Hi!

Anyone got the imageUpload from the Yii-Redactor-extension to work?

I have a few questions regarding it, first off: What is the ‘attribute’=>$attribute supposed to be? I just dont understand what string it would need there.

Secondly, when i just define ‘attribute’ => ‘text’ (that is the attribute for the entry in the table im using redactor for) it loads allright, but when i try to upload the image, it thinks for a short while, but no image is uploaded.

The Controller:


	public function actions()

    {

        return array(

            'imageUpload'=>array(

                'class'=>'ext.redactor.actions.ImageUpload',

                'uploadCreate'=>true,

            ),

            'imageList'=>array(

                'class'=>'ext.redactor.actions.ImageList',

            ),

        );

    }

The view:




$this->widget('bootstrap.widgets.TbBox', array(

    'title' => 'Opprett nyhet',

    'headerIcon' => 'icon-home',

    'content' => $this->renderPartial('_form', array('model'=>$model), true) // $this->renderPartial('_view')

));

The _form:


<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(

	'id'=>'news-form',

	'enableAjaxValidation'=>false,

)); ?>


	<?php echo $form->errorSummary($model); ?>


	<?php echo $form->textFieldRow($model,'headline',array('class'=>'span5','maxlength'=>255,'labelOptions' => array('label' => false), 'placeholder' => 'Overskrift')); ?>

	

	<?php 

	$this->widget('ext.redactor.ERedactorWidget',array(

	    'model'=>$model,

	    'attribute'=>$attribute,

	    'options'=>array(

	        'imageUpload'=>Yii::app()->createUrl('news/imageUpload',array(

	            'attr'=>$attribute

	        )),

	        'imageGetJson'=>Yii::app()->createUrl('news/imageList',array(

	            'attr'=>$attribute

	        )),

	        'imageUploadErrorCallback'=>new CJavaScriptExpression(

	            'function(obj,json) { alert(json.error); }'

	        ),

	    	'lang'=>'no_NB',	 

	    ),

	));

	?>

	

	<p><?php echo $form->textFieldRow($model,'author',array('prepend'=>'Av', 'class'=>'small','maxlength'=>255,'labelOptions' => array('label' => false), 'value'=> Yii::app()->user->name)); ?>

	

	<?php echo $form->checkBox($model,'published'); ?>

		<?php $this->widget('bootstrap.widgets.TbButton', array(

			'buttonType'=>'submit',

			'type'=>'primary',

			'label'=>'Lagre',

		)); ?>


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

Could it be the bootstrap fudging with it?

Appriciate all help :) thx

Define $attribute before the widget (db field). I was using it there so that I don’t have to write it many times when using upload actions.




$attribute='text';

$this->widget('ext.redactor.ERedactorWidget',array(

...



You can also use the attribute name in the widget, if you like (change CONTROLLER_ID & MYATTRIBUTE):




        <?php 

        $this->widget('ext.redactor.ERedactorWidget',array(

            'model'=>$model,

            'attribute'=>'MYATTRIBUTE',

            'options'=>array(

                'imageUpload'=>Yii::app()->createUrl('CONTROLLER_ID/imageUpload',array(

                    'attr'=>'MYATTRIBUTE'

                )),

                'imageGetJson'=>Yii::app()->createUrl('CONTROLLER_ID/imageList',array(

                    'attr'=>'MYATTRIBUTE'

                )),

                'imageUploadErrorCallback'=>new CJavaScriptExpression(

                    'function(obj,json) { alert(json.error); }'

                ),

                'lang'=>'no_NB',         

            ),

        ));

        ?>



Okey, here we go again :)

Thx for your reply Janisto, and thank you for taking time to create extensions for new yii-users like my self.

Its a steep learningcurve.

So, after a break from the Redactor widget, as i got frustrated over the image uploadthingie. Im now trying again, but i do not get much closer to a working upload.

Im gonna try to explain my problem as precise as i can:

All files in ext.redactor is where they are supposed to, i’ve quadruplechecked it.

The editor loads fine, and the insert image window opens fine.

But when i click "Choose File" and select a image, nothing happens exept the window closes. If i press "Choose File" again, it does show the filename instead of the "no file choosen"-text. When i click insert im sendt back to the editor, but nothing shows in the text-area.

No folder is created, no errormessage is displayed.

I’ve allso experimented with filling the folder with images myself, following the pattern /CONTROLLER_ID_NOCAPITALLETTERS/ATTR/

My attr and controller is set in the widget-config, and should be correct.


$attribute='info';

$this->widget('ext.redactor.ERedactorWidget',array(

    'model'=>$model,

    'attribute'=>$attribute,

    'options'=>array(

        'fileUpload'=>Yii::app()->createUrl('wine/fileUpload',array(

            'attr'=>$attribute

        )),

        'fileUploadErrorCallback'=>new CJavaScriptExpression(

            'function(obj,json) { alert(json.error); }'

        ),

        'imageUpload'=>Yii::app()->createUrl('wine/imageUpload',array(

            'attr'=>$attribute

        )),

        'imageGetJson'=>Yii::app()->createUrl('wine/imageList',array(

            'attr'=>$attribute

        )),

        'imageUploadErrorCallback'=>new CJavaScriptExpression(

            'function(obj,json) { alert(json.error); }'

        ),

    ),

));

(Attribute = info, Controller= WineController)

Anyone know where i’ve stepped wrong? Thx

Start by checking what that dialog returns with Firebug (Net/XHR). See if the images are created at the right place and that they have the proper permissions.

Also check if there are errors in your logs.

BTW, files should be generated to uploads/MODEL/FIELD/filename.ext, so try adding files to "uploads/wine/info/"-folder.

The model has the same name, wine, so thats not the problem.

Im gonna need some time to learn alittle about firebug, thx for the help so far.

Appriciated.

I got the same problem, the image upload didn’t work.

I got the following error on firefox’s web console when clicking the insert image icon:


../../imageList.html?attr=isi [HTTP/1.0 403 Forbidden 125ms]

Folder permission is Ok, any suggestions?

Note:

I’m using the latest Yii (Yii-1.1.13).