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

Exception not work

I update php to 5.6.17 and exception stopped working.

Who know what happened?

example

try
{
    if ($Model->create($params->toArray()))
    {
        ...
    }
    else
    {
        throw new \Exception(implode('<br>', $Model->getMessages()));
    }
}
catch (\Exception $e)
{
    $this->flash->error($e->getMessage());
}

os centos 6

on 1.3.4 work

on 2.0.9 not work



1.4k

Hi,

have you tried this, to isolate the problem :

try
{
    throw new \Exception("error testing");
}
catch (\Exception $e)
{
    $this->flash->error($e->getMessage());
}


25.0k

this work

Hi,

have you tried this, to isolate the problem :

try
{
   throw new \Exception("error testing");
}
catch (\Exception $e)
{
   $this->flash->error($e->getMessage());
}


1.4k

then the problem is in the other part : create returns always true...

  if ($Model->create($params->toArray()))
    {
    }


25.0k

why always?

https://docs.phalcon.io/en/latest/reference/models.html#create-update-with-confidence

if ($robot->create() == false) {
    echo "Umh, We can't store robots right now: \n";
    foreach ($robot->getMessages() as $message) {
        echo $message, "\n";
    }
} else {
    echo "Great, a new robot was created successfully!";
}

then the problem is in the other part : create returns always true...

 if ($Model->create($params->toArray()))
   {
   }


1.4k

"Always" in your example...

What is the implementation of the class of $model, what are the values of $params



25.0k
edited Feb '16

model with not null fields

and now all models can be saved, wtf?

if ($form->isValid())
{
$params = $form->getEntity();
}

"Always" in your example...

What is the implementation of the class of $model, what are the values of $params



1.4k
edited Feb '16

how are declared "not null" constraints ?

Are nulls replaced by an empty string at the insertion?



25.0k
CREATE TABLE `settings` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `is_active` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1',
    `key` VARCHAR(24) NOT NULL DEFAULT '',
    `key_value` VARCHAR(24) NOT NULL DEFAULT '',
    `name` VARCHAR(48) NOT NULL DEFAULT '',
    `description` VARCHAR(512) NULL DEFAULT NULL,
    PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;

how are declared "not null" constraints ?

Are nulls replaced by an empty string at the insertion?



1.4k
edited Feb '16

if the fields "not null" have a default value in the database, it is normal, insertion is always possible, and create returns always true...\

remove a DEFAULT value and try again, you will see.



25.0k

but why in 1.3.4 its work?

if the fields "not null" have a default value in the database, it is normal, insertion is always possible, and create returns always true...



1.4k
edited Feb '16

I dont know,

Are you really sure that the only change is the transition to Phalcon2...



25.0k

i have two lxc containers: 1 php 5.5 phalcon1 2 php 5.6 with phalcon2

first work second none

I dont know too

I dont know,

Are you really sure that the only change is the transition to Phalcon2...



1.4k

have you tried (php 5.5 + phalcon1 2) and (php 5.6 + phalcon2) with the same Mysql server ?



25.0k

yes

have you tried (php 5.5 + phalcon1 2) and (php 5.6 + phalcon2) with the same Mysql server ?



1.4k

Strange, but the normal behavior is with Phalcon 2 and php 5.6

Not null fields with default values do not generate errors if the field is null