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

Create a new product in the invo tutorial

Hi Everyone, I'm having a problem with the ProductController line 101 of the Invo test application https://github.com/phalcon/invo/blob/master/app/controllers/ProductsController.php

...
if (!$form->isValid($data, $product)) {
...

For some reasons this is throwing an exception with message 'Wrong number of parameters'.

POST data is correctly received.

Someone has an idea of why I get this error?

Thanks!

Ok, got it. To get rid of the error

Fatal error: Class 'Phalcon\Validation\Validator\Numericality' not found in /mypath/app/forms/ProductsForm.php on line 54

that is in the product add page, I edited the path of the class Numericality to

use Phalcon\Mvc\Model\Validator\Numericality;

but apparently something is still wrong. So I commented the adding of this validator for the 'price' field and saving is now working.

So what is the correct path for the Numericality validator?

I use Phalcon version 1.3.2 with PHP version 5.4.34

Thanks

edited Nov '14

I did not see Numericality validation in documentation, Phalcon\Validation\Validator\Numericality . You can see all rules here https://docs.phalcon.io/en/latest/reference/validation.html#validators

Hi vitaliykoziy, exactly. But I've found this https://docs.phalcon.io/en/latest/api/Phalcon_Mvc_Model_Validator_Numericality.html

so I thought that changing the path will do the work, but unfortunatelly this break the creation of a new product (also see this discussion https://github.com/phalcon/invo/issues/30 ), clearly not the same class.

The use of this validator exists within the Productform class of the Invo application

https://github.com/phalcon/invo/blob/master/app/forms/ProductsForm.php on line 9

Only totally removing this validator will make the creation of a new product work.

edited Nov '14

In https://github.com/phalcon/invo/blob/master/app/forms/ProductsForm.php Try add new namespace

use Phalcon\Forms\Element\Numeric;

and write this

$price = new Numeric("price");
    $price->setLabel("Price");
    $price->setFilters(array('float'));
    $price->addValidators(array(
        new PresenceOf(array(
            'message' => 'Price is required'
        )),
    ));
    $this->add($price);

I think this will do that you want.

P.S. I don't use model validation rules for form validation.

Thank you, I'll try this.

However I don't understand how that part of the Invo code is supposed to work, I really would like to know this...



98.9k

That INVO tutorial is adapted to Phalcon 2.0, that's why you find that missing class

Thanks Phalcon, so shouldn't the README of the Github repo be updated showing

Required version: >= 2.0.0

instead of the current

Required version: >= 1.0.0 ?

Is really a good idea to start develop an application using Phalcon 1.3.x?

Cheers