-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[BUG] PHP Error after \Phalcon\Mvc\Model\MetaData::reset() #1801
Comments
Worked for me in 1.2.5:
However, could you please try this: -$di->get('modelsMetadata')->reset();
+$di->getShared('modelsMetadata')->reset(); ? |
I have tried with getShared() and that made no difference. I have also now tried both options using 1.2.5 and continue to get the same error. Please note I am using the following to see the error;
|
Could you please show more code? With this: <?php
error_reporting(E_ALL | E_STRICT);
require __DIR__ . '/models/Robots.php';
$di = new Phalcon\DI();
$di->set('modelsManager', function(){
return new Phalcon\Mvc\Model\Manager();
});
$di->set('modelsMetadata', function(){
return new Phalcon\Mvc\Model\Metadata\Memory();
});
$di->set('db', function(){
require __DIR__ . '/config.db.php';
return new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
});
$robot = Models\Robots::findFirst(1);
print_r($robot->toArray());
$di->get('modelsMetadata')->reset();
$robot = Models\Robots::findFirst(1);
print_r($robot->toArray());
?> I am unable to reproduce the issue. |
Ok that works by itself for me as well, so after digging deeper here is how to alter it slightly to trigger the notice. <?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', '1');
Phalcon\Mvc\Model::setup(array(
'columnRenaming' => false,
));
require __DIR__ . '/models/Robots.php';
$di = new Phalcon\DI\FactoryDefault();
$di->set('db', function(){
require __DIR__ . '/config.db.php';
return new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
});
$robot = Models\Robots::findFirst(1);
print_r($robot->toArray());
$di->get('modelsMetadata')->reset();
$robot = Models\Robots::findFirst(1);
print_r($robot->toArray());
?> Please note the use of BOTH of the following is required to trigger the notice; $di = new Phalcon\DI\FactoryDefault(); and; Phalcon\Mvc\Model::setup(array(
'columnRenaming' => false,
)); |
Fix submitted (#1952) |
Using Phalcon 1.2.4 I am getting PHP errors after making use of the MetaData::reset() call to force metadata to be reloaded.
The above works fine and the current robot is displayed
Now if I need to connect to another database (for the sake of argument lets say there are thousands of databases to iterate through, so setting up a seperate $di service and seperate models for each is not practical so I want to reuse the the same models and so the same connection service and table names
The table structures could be slightly out of sync with new fields etc so I need to ensure the corrent metadata is loaded again
Now when I run the following it works and the new structure is displayed.
But both the findFirst() and toArray() methods now generate a PHP error;
Notice: Undefined index: models\robots in ...
Please note that within the Robots.php class file I make use of the following to ensure that any changes to the connection service are picked up
I can also generate the same PHP error without changing database connections if the Metadata reset option is used between method calls.
The text was updated successfully, but these errors were encountered: