Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony2 listener class not loading?
    primarykey
    data
    text
    <p>I am struggling with something that may sound stupid but : </p> <p>I created a listener class that add content to Lucene Search Index after an entity is persisted.</p> <p>My config.yml : </p> <pre><code>services: searchindexer.listener: class: ripr\WfBundle\Listener\SearchIndexer tags: - { name: doctrine.event_listener, event: postPersist } </code></pre> <p>My file is in src/ripr/WfBundle/Listener</p> <p>Filename is SearchIndexer.php</p> <p>Class name is SearchIndexer</p> <p>Namespace is ripr\WfBundle\Listener</p> <p>I get an error on this line</p> <pre><code>$index = $this-&gt;get('ivory_lucene_search')-&gt;getIndex('identifier1'); </code></pre> <p>error :</p> <pre><code>Fatal error: Call to a member function get() on a non-object </code></pre> <p>This sounds to me that class is not loaded. I can't get where I am wrong.</p> <p>I flush dev cache multiples times.</p> <p>This precise line works perfectly when I call it inside a classic Controller.</p> <p>--------Edited--------</p> <p>My class code to help</p> <pre><code> &lt;?php namespace ripr\WfBundle\Listener; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Doctrine\ORM\Event\LifecycleEventArgs; use ripr\WfBundle\Entity\Item; use Ivory\LuceneSearchBundle\Model\Document; use Ivory\LuceneSearchBundle\Model\Field; /** * Search indexer. * * */ class SearchIndexer extends Controller { /** * Index content * */ public function postPersist (LifeCycleEventArgs $args) { // $luceneSearch = $this-&gt;get('ivory_lucene_search'); // $luceneSearch-&gt;eraseIndex('identifier1'); $entity = $args-&gt;getEntity(); $entityManager = $args-&gt;getEntityManager(); // perhaps you only want to act on some "Product" entity $index = $this-&gt;get('ivory_lucene_search')-&gt;getIndex('identifier1'); $document = new Document(); $document-&gt;addField(Field::text('titre', 'bille')); $document-&gt;addField(Field::text('texte', 'billou')); // Add your document to the index $index-&gt;addDocument($document); $index-&gt;commit(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload