We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Validator in 2.1.0 not work

I change old model Users in INVO on new from https://blog.phalcon.io/post/phalcon-2-1-beta-released

Internal Error Something went wrong, if the error continue please contact us

What am I doing wrong?



85.5k

And what you have in logs ?



85.5k

there are quite a few inconsistent changes in 2.1.x, did you check the blog carefully to be sure you fixed all the "things"

https://blog.phalcon.io/post/phalcon-2-1-beta-released

but to make your life easier, go to your apache/nginx log and check whats the error there



14.4k
edited Mar '16

[28-Mar-2016 20:22:24 Europe/Moscow] Wrong number of parameters

0 C:\OpenServer\domains\fm25.loc\app\models\Users.php(35): Phalcon\Mvc\Model->validate()

1 [internal function]: Users->validation()

2 [internal function]: Phalcon\Mvc\Model->fireEventCancel('validation')

3 [internal function]: Phalcon\Mvc\Model->_preSave(Object(Phalcon\Mvc\Model\MetaData\Memory), true, 'id')

4 C:\OpenServer\domains\fm25.loc\app\controllers\InvoicesController.php(43): Phalcon\Mvc\Model->save()

5 [internal function]: InvoicesController->profileAction()

6 [internal function]: Phalcon\Dispatcher->dispatch()

7 C:\OpenServer\domains\fm25.loc\public\index.php(32): Phalcon\Mvc\Application->handle()

8 {main}

here what gave php. Where I can take more info?



85.5k
Accepted
answer
edited Mar '16

this is the new syntax for validation, did you fix it in your project ?


namespace Invo\Models;

use Phalcon\Mvc\Model;
use Phalcon\Validation;
use Phalcon\Validation\Validator\Email as EmailValidator;
use Phalcon\Validation\Validator\Uniqueness as UniquenessValidator;

class Users extends Model
{
    public function validation()
    {
        $validator = new Validation();

        $validator->add(
            'year',
            new Numericality([
                'model' => $this,
                "message" => 'enter year bla bla bla'
            ])
        );

        return $this->validate($validator);
    }
}


14.4k

In https://blog.phalcon.io/post/phalcon-2-1-beta-released return $this->validate(); but you say return $this->validate($validator); I have tried in various ways. It does not work. and further ... whether it is necessary at the beginning to put namespase or not? With namespase refuses to give Page. I have tried to pass the code debugger is not found anything suspicious. It comes to return and throws an exception



85.5k

i am 100% sure in the blog is wrong. if you put directly this code it should work :

$validator = new Validation();

        $validator->add(
            'year',
            new Numericality([
                'model' => $this,
                "message" => 'enter year bla bla bla'
            ])
        );

        return $this->validate($validator);

i find it a bit suspicious, because the exception was saying something about params... i dont know i might be mistaking



14.4k

Izo you're a genius !!! This I did not realize something. 'model' => $ this, - it was not a blog https://blog.phalcon.io/post/phalcon-2-1-beta-released return $this->validate(); - it is not right. return $this->validate($validator); - it is right.

The blog is written the wrong code. It leads to errors.

Iso, thank you!!!



14.4k

But in local server work, in VDS don't work. What's a .........



85.5k

check error log, what's the version in VDS ?



14.4k

local 2.1.0b Version 2.1.0b

in vds 2.1.0 Version 2.0.10

Where find that logs? in apache, in php, ... ? I beginer, sorry



85.5k

but you can't have the same code in 2 different versions, they are inconsistent. You have to row back your local version for now. Make sure 2.1.x works, then you can update your vds.

p.s. actually i dont know what vds is :D



14.4k

)) Thanks ...

git clone --depth=1 git://github.com/phalcon/cphalcon.git cd cphalcon/build sudo ./install

Today I did it and I thought that the new version is put, but to have the old. Tell me, dear Iso how to install 2.1.0b to VDS. 2.0.10 not work ...

edited Mar '16
git clone -b 2.1.x https://github.com/phalcon/cphalcon

Vds is VPS i guess xd



14.4k

Thank you cool professionals. All turned in the best possible way