Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call to a member function format() on a non-object #99

Closed
lestat1968 opened this issue Jun 26, 2014 · 11 comments
Closed

Call to a member function format() on a non-object #99

lestat1968 opened this issue Jun 26, 2014 · 11 comments
Labels

Comments

@lestat1968
Copy link

Hi,

i've updated your extensions and framework to the latest version available with composer.

Now, in a update action i obtained the following error:

PHP Fatal Error – yii\base\ErrorException
Call to a member function format() on a non-object
in C:\wamp\www2\yii2basic\vendor\kartik-v\yii2-datecontrol\datecontrol\DateControl.php

in my view (_form.php):

    <?php

        // Use a DatePicker input with ActiveForm and model validation enabled.
        echo $form->field($model, 'data_nascita')->widget(DateControl::classname(), [
            'type'=>DateControl::FORMAT_DATE,
            'options'=>[
                'options' => ['placeholder' => 'Seleziona Data di nascita...',
                 ],
                'pluginOptions' => ['language' => 'it',
                                    'autoclose' => true,
                ],
            ],            
        ]);    

    ?>

in my config file (web.php):

...
   'components' => [
        'formatter' => [
            'class' => 'yii\base\Formatter',
            'dateFormat' => 'd/m/Y',
            'datetimeFormat' => 'd/m/Y H:i:s',
            'timeFormat' => 'H:i:s',            
        ],
...
    'modules' => [
        'datecontrol' => [
            'class' => 'kartik\datecontrol\Module',

            // format settings for displaying each date attribute
            'displaySettings' => [
                Module::FORMAT_DATE => 'd/m/Y',
                Module::FORMAT_TIME => 'H:i:s',
                Module::FORMAT_DATETIME => 'd/m/Y H:i:s',
            ],

            // format settings for saving each date attribute
            'saveSettings' => [
                Module::FORMAT_DATE => 'Y-m-d', // saves as unix timestamp
                Module::FORMAT_TIME => 'H:i:s',
                //Module::FORMAT_DATETIME => 'Y-m-d H:i:s',
                Module::FORMAT_DATETIME => 'U',
            ],

            // automatically use kartik\widgets for each of the above formats
            'autoWidget' => true,

        // other settings
        ],

where's the problem in my code?

@kartik-v
Copy link
Owner

It seems the DateControl extension was not properly updated by composer. Can you backup and purge your vendor folder in approot, and run php composer.phar install --prefer-dist and confirm.

@lestat1968
Copy link
Author

I'll try..

@lestat1968
Copy link
Author

i followed your instructions...

no success.. :-(

@kartik-v
Copy link
Owner

It seems there is a small glitch in datetime formatting. Will record this as a bug and provide a fix.

@kartik-v kartik-v added the bug label Jun 26, 2014
@kartik-v
Copy link
Owner

Fixed DateControl bug via this commit. Try to update via composer after 30 minutes.

@lestat1968
Copy link
Author

thanks...

@kartik-v kartik-v removed the question label Jun 26, 2014
@lestat1968
Copy link
Author

ok, Call to a member function format() issue is resolved, but now in update scenario widget don't display data value even if it is setted...

@kartik-v
Copy link
Owner

  • What are your save and display values?
  • What are your save and display formats?
  • What is your widget configuration?

@lestat1968
Copy link
Author

Thanks for your help Kartik,

since some of the settings of the framework and datecontrol class have changed since I wrote the code, I reread the documentation. If I can not find the problem I will ask again.

@lestat1968
Copy link
Author

Ok, Kartik, issue resolved...

my mistake... data_nascita field was a datetime...
changed it to date and it works like a charm....

@kartik-v
Copy link
Owner

In the new widget version, I have set the display to be null (instead of showing the wrongly formatted value) - if the format is mismatched or violated. This will be useful for you to debug your formatting errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants