Is there any complete example of how to use the behavior(configuration in model,view,controller) and what are requirements to use the extension(which libraries are need). I am confused I don’t know what to do things that I am trying are not working:
In my model:
public $photo;//The file attributes
public function behaviors(){
return [
[
"class" => "sjaakp\illustrated\Illustrated",
"attributes"=>[
'img'=>[
'aspectRatio'=>1.0,
'cropSize'=>90,]
]
],
];
}
//rules : $rules[] = ['photo','file'];
Thanks; I went through the extension files to understand how it works and then I got how to correct it. In the model the behavior must be configure as follow:
Incorrect Configuration:
public function behaviors(){
return [
[
"class" => "sjaakp\illustrated\Illustrated",
"attributes"=>[
'img'=>[
'aspectRatio'=>1.0,
'cropSize'=>90,]
]
],
];
}
Correct Configuration:
public function behaviors(){
return [
[
"class" => "sjaakp\illustrated\Illustrated",
"attributes"=>[
'photo'//Important to put the attribute of fileinput,
'img'=>[
'aspectRatio'=>1.0,
'cropSize'=>90,]
]
],
];
}
So it is being rendered but the when I click the submit button it is sending an ajax request to the server but it not saving the file here is my code in the controller(what am I missing in the action so that it saves the image) :
Ok; I thought the behaviour was going to save automatically after calling the save method of the model since I set ‘directory’=>’@webroot’,‘illustrationDirectory’=>‘media’ when configuring the behavior.
I read My link yesterday when you suggested it to me while looking for altenartives but I tried and did’nt go for it since the kartik-extension is not working properly for me after so many acrobatics tried(problem post in My link).
I runned to illustrated after the failure making kartik to work.
I put;
In controller:
public function actionphoto(){
$model = Profile::findOne(Yii::$app->user->identity->getId());
$model->scenario='photo';
if(\Yii::$app->request->post()){
$model->photo = UploadedFile::getInstances($model, 'photo');
if ($model->upload()) {
var_dump('Image Enregistrer');
}
}
if(\Yii::$app->request->isAjax){
var_dump('ajax request');
\yii::$app->end();
return $this->renderAjax('photo',array('model'=>$model));
}else{
return $this->render('photo',array('model'=>$model));
}
}
In model :
public function upload()
{
if ($this->validate()) {
$this->photo->saveAs('uploads/' . $this->photo->baseName . '.' . $this->photo->extension);
return true;
} else {
var_dump('NOT VALID');
}
When I click on the submit button I get this:
string ‘NOT VALID’ (length=9)
string ‘ajax request’ (length=12)
as response
And if I remove
$this->validate()
condition I receive “PHP Notice ‘yii\base\ErrorException’ with message ‘Trying to get property of non-object’” error message on the line