Hi guys,
I have been working on getting jii-crop to work in my design for while a week or two. Please help. I have now made it to the Save button. How am I suppose to save off the cropped image??
Nothing is saving off in my model attributes.
There is my controller:
public function actionSphoto()
{
if(isset($_POST['UserInfo'])){
$userinfo_model->cropX = $_POST['UserInfo']['cropX'];
$userinfo_model->cropY = $_POST['UserInfo']['cropY'];
$userinfo_model->cropW = $_POST['UserInfo']['cropW'];
$userinfo_model->cropH = $_POST['UserInfo']['cropH'];
$userinfo_model->cropID = $_POST['UserInfo']['cropID'];
}
}
I did not now what to put for formElementX, formElementy,formElementWidth,formElementHeight…so I just hard coded. (is that a problem?)
Here is my view:
<?=CHtml::beginForm(array('site/sphoto'),'post',array('id' => 'uploadformc','target' => 'upload_target2'))?>
<? //$form in this example is of type AvatarForm, containing variables for the crop area's x, y, width and height, hence the corresponding widget form element parameters ?>
<?=CHtml::activeHiddenField($userInfo_model, 'cropID');?>
<?=CHtml::activeHiddenField($userInfo_model, 'cropX', array('value' => '0'));?>
<?=CHtml::activeHiddenField($userInfo_model, 'cropY', array('value' => '0'));?>
<?=CHtml::activeHiddenField($userInfo_model, 'cropW', array('value' => '100'));?>
<?=CHtml::activeHiddenField($userInfo_model, 'cropH', array('value' => '100'));?>
<?$previewWidth = 120; $previewHeight = 140;
$imageUrl = Yii::app()->request->baseUrl."/images/".Yii::app()->session['profile_image']; ?>
<?$this->widget('ext.yii-jcrop.jCropWidget',array(
'imageUrl'=>$imageUrl,
'formElementX'=>0,
'formElementY'=>0,
'formElementWidth'=>100,
'formElementHeight'=>100,
'previewId'=>'avatar-preview', //optional preview image ID, see preview div below
'previewWidth'=>$previewWidth,
'previewHeight'=>$previewHeight, //'id'=>'yii-jcrop',
'jCropOptions'=>array(
'aspectRatio'=>1,
'boxWidth'=>275,
'boxHeight'=>275,
'setSelect'=>array(0, 0, 100, 100),
),
));
?>
<iframe id="upload_target2" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>
<div id="avatar-previewd" style="position:relative; overflow:hidden; width:<?=$previewWidth?>px; height:<?=$previewHeight?>px; margin-top: 10px; margin-bottom: 10px;">
<img id="avatar-preview" src="<?=$imageUrl?>" style="width:100px; height:120px; margin-left:10px; margin-top:10px; margin-bottom:10px; margin-right: 10px;">
</div>
<?=CHtml::submitButton('Save',array('id'=>'cropButton','name' => 'submitBtn', 'value' => 'Save')); ?>
<?=CHtml::endForm()?>
And I have my attributes declared in my model:
public $cropID;
public $cropX;
public $cropY;
public $cropW;
public $cropH;