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

Files ModelsMetadata not working

I'm trying to implement models metadata. It's working in memory \Phalcon\Mvc\Model\Metadata\Memory() but it's not working with \Phalcon\Mvc\Model\Metadata\Files( ).

The metaDataDir is writable (777) but no files are being written.

    $modelsMetadata = new \Phalcon\Mvc\Model\Metadata\Files([
                    'metaDataDir' => APPLICATION_PATH . "/cache/Metadata/",
                ]);
    $di->setShared('modelsMetadata', $modelsMetadata)

Models cahce is working properly.

    $frontCache = new \Phalcon\Cache\Frontend\Data([
        "lifetime" => $config->metadata->lifetime * 30
    ]);

    $modelsCache = new \Phalcon\Cache\Backend\File(
        $frontCache,
        [
            "cacheDir" => APPLICATION_PATH . "/cache/Data/",
            "prefix"   => $config->metadata->prefix
        ]
    );
    $di->setShared('modelsCache', $modelsCache);

And models manager is also declared.

    $modelsManager = new \Phalcon\Mvc\Model\Manager();

    $di->setShared('modelsManager', $modelsManager);
$di->setShared('modelsMetadata', function () use ($config) {
    return new \Phalcon\Mvc\Model\MetaData\Files(array(
        'metaDataDir' => $config->application->cacheDir . 'metaData/',
        "lifetime" => 86400,
        "prefix" => "tMeta"
    ));
});
edited Jan '16

Still not working...

$di->setShared('modelsMetadata', function () use ($config) {
    return new \Phalcon\Mvc\Model\MetaData\Files(array(
        'metaDataDir' => $config->application->cacheDir . 'metaData/',
        "lifetime" => 86400,
        "prefix" => "tMeta"
    ));
});


1.3k

A had the same issue. Look at your

$modelsMetadata = new \Phalcon\Mvc\Model\Metadata\Files([ ...

there is a typing error in "Metadata". Use "MetaData"



15.3k
Accepted
answer

I forgot to put the answer.

Just start Cache service BEFORE Database service.