Cphalcon: Accessing service by property

Created on 24 Sep 2016  路  4Comments  路  Source: phalcon/cphalcon

In 3.0.0 blog post there are example like:

$config = new \Phalcon\Config([
    'foo' => 'bar',
]);

$di->setShared('config', $config);

$di->setShared('view', function() {
    $config = $this->config; // you have to access the previously set config by the magic property
                             // the declaration order doesnt matter, thanks to lazy loading
    $view = new View();
    return $view;
});

But i added test for this - https://github.com/phalcon/cphalcon/pull/12249 and it obviously doesn't work because there is no magic __get in Phalcon\Di

stale

Most helpful comment

@sergeyklay You mean instead of: $config = $this->setShared('config'); to use: $config = $this->getShared('config'); (get instead of set)

All 4 comments

This is blog post misspelling. Correct example:

$config = new \Phalcon\Config([
    'foo' => 'bar',
]);

$di->setShared('config', $config);

$di->setShared('view', function() {
    $config = $this->getShared('config');

    // ...

    $view = new View();
    return $view;
});

@sergeyklay You mean instead of: $config = $this->setShared('config'); to use: $config = $this->getShared('config'); (get instead of set)

@stamster Yes

Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues

Was this page helpful?
0 / 5 - 0 ratings