Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

why models cant uses DI which i inject in services

my controller can usr my di ,but model can not use , whats wrong with it, hel-p pleace. thanks very much


You should be able to call any service defined in DI from your model. For someone to help you, will need at least this information:

  • code snippet
  • phalcon version

edited Sep '15

follow is my services di code:

   $di->set('manager', function() {
 return new modelManager();

follow is my Model Cars in namespace Model

public function test(){
  $phql="select * from Model\Cart";
  $rows = $this->manager->excuteQuery($phql);

at last Notice: Access to undefined property Models\Cars::manager in C:\wamp\www\front\app\models\Cars.php on line 29


Can you rename "manger" with something else like "modelsManager" and try again ? I am not sure but I think "manager" is a reserved word.


what a f*&k thing, thanks a lot , i have find almost a day follow its session in model

class Robots extends Phalcon\Mvc\Model

{ public function beforeCreate() { $this->userId = $this->getDI()->getSession()->get('user-id'); } }