loicfrering / losolib

Collection of components for Zend Framework applications and integration of Symfony Components.
http://losohome.wordpress.com/
MIT License
48 stars 6 forks source link

Dependance Inject doesn't work in PostController #1

Closed anardil closed 13 years ago

anardil commented 13 years ago

Hi,

Congratulations for your job. But I've a got a bug in PostController when the service is not called with getContainer().

protected $postService;

public function setPostService($postService)
{
    $this->postService = $postService;
    return $this;
}

when I do : Zend_Debug::dump($this->postService), thats returns NULL.

How can I resolve this bug ? Thx.

loicfrering commented 13 years ago

Hello,

Thanks for your feedback !

In order to let your controller be managed by the Dependency Injection Container, you have to:

  1. Annotate your controller with @Controller
  2. Make your controller extend LoSo_Zend_Controller_Action
  3. Then you have to annotate your dependencies with @Inject

Here is what you should have:

<?php
/** @Controller */
class PostController extends LoSo_Zend_Controller_Action
{
    /** @Inject */
    protected $postService;

    public function setPostService($postService)
    {
        $this->postService = $postService;
        return $this;
    }

    // ...
}

Let me know if it resolves your problem.

anardil commented 13 years ago

Ok that's works.

In your source is written

<?php /**

You have to replace the annotation above the class definition.

<?php /**

by

<?php /**

Thanks

loicfrering commented 13 years ago

I pushed a correction for that, thanks! See: bf5ee019a1b4e0e24df8fb8be7e67d968e9a157e.