sjaakp / yii2-illustrated-behavior

Adds image to ActiveRecord
http://www.sjaakpriester.nl/software/illustrated
MIT License
43 stars 17 forks source link

I am getting error;Undefined index: photo #15

Closed aidonsnous closed 8 years ago

aidonsnous commented 8 years ago

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'];

In my view use sjaakp\illustrated\Uploader;

    <div id="partiechargee" class="panel panel-default center-block">
        <?php if($titre==true){
         echo '<p class="well-sm">';
       $this->render('/_alert', ['module' => $module,]);
        echo '</p>';}?>

        <h3 class="panel-title panel-heading text-center" style="margin-bottom:5px;"><strong><?= Html::encode($this->title)?></strong></h3>
            <?php $form = ActiveForm::begin([
                 'id'=> 'form-registration',
                'enableAjaxValidation'   => true,
                'enableClientValidation' => false,
                'method'=>'post',
                'action'=>\Yii::$app->urlManager->createUrl(['settings/profilephoto']),
            'options'=>['class'=>'well-sm text-center',
                'enctype'=>'multipart/form-data']]); ?>

<?= $form->field($model, 'photo')->widget(Uploader::className([ 'deleteOptions' => [ 'label' => '', // Font Awesome icon 'title' => 'Delete image' ] ])) ?>

'btn btn-danger cancel btn-block']) ?>

            <?php ActiveForm::end(); ?>
</div>

With that I am getting errror : Undefined index: photo

aidonsnous commented 8 years ago

Here is the solution;

This :

public function behaviors(){ return [ [ "class" => "sjaakp\illustrated\Illustrated", "attributes"=>[ 'img'=>[ 'aspectRatio'=>1.0, 'cropSize'=>90,] ] ], ]; }

Should be:

public function behaviors(){ return [ [ "class" => "sjaakp\illustrated\Illustrated", "attributes"=>[ 'photo'//Important to put the attribute of fileinput, 'img'=>[ 'aspectRatio'=>1.0, 'cropSize'=>90,] ] ], ]; }

sjaakp commented 8 years ago

In fact you created a model with two Illustrations: one called ‘photo’, having the default options (aspectRatio = 1.0, cropSize =240), and the other called ‘img’ with aspectRatio = 1.0 and cropSize = 90.

Please, first try the simplest case, one illustration without any options:

class NicePlace extends ActiveRecord {

            public function behaviors()         {

                           return [

                                           ‘class’ => ‘sjaakp\illustrated\Illustrated’,

                                           ‘attributes’ => [

                                                           ‘photo’

                                           ]

                           ];

            }

}

In the view:

use sjaakp\illustrated\Uploader;

...

        <?= $form->field($model, 'photo')->widget(Uploader::className())  ?>

...

That’s really all.


Sjaak Priester

mailto:sjaak@sjaakpriester.nl sjaak@sjaakpriester.nl

From: MagSag [mailto:notifications@github.com] Sent: Friday, December 4, 2015 9:56 AM To: sjaakp/yii2-illustrated-behavior yii2-illustrated-behavior@noreply.github.com Subject: Re: [yii2-illustrated-behavior] I am getting error; Is there any complete example of how to use the behavior(configuration in model,view,controller) practically (#15)

Here is the solution;

This :

public function behaviors(){ return [ [ "class" => "sjaakp\illustrated\Illustrated", "attributes"=>[ 'img'=>[ 'aspectRatio'=>1.0, 'cropSize'=>90,] ] ], ]; }

Should be:

public function behaviors(){ return [ [ "class" => "sjaakp\illustrated\Illustrated", "attributes"=>[ 'photo'//Important to put the attribute of fileinput, 'img'=>[ 'aspectRatio'=>1.0, 'cropSize'=>90,] ] ], ]; }

— Reply to this email directly or view it on GitHub https://github.com/sjaakp/yii2-illustrated-behavior/issues/15#issuecomment-161911550 . https://github.com/notifications/beacon/AFU71uj1aX7VEd9XE50kNLr8W84w75Idks5pMUyXgaJpZM4Gs4VU.gif

aidonsnous commented 8 years ago

Thanks dear but I've solved that problem my preoccupations are the issue 16 and 14 for now.