Skip to content

Instantly share code, notes, and snippets.

@vittore
Created August 3, 2012 07:26
Show Gist options
  • Save vittore/3245377 to your computer and use it in GitHub Desktop.
Save vittore/3245377 to your computer and use it in GitHub Desktop.
Persist ot not persist?
File: Zen\IgBundle\Entity\AdminNotification.php
<?php
namespace Zen\IgBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\EntityManager;
/**
* @ORM\Entity
* @ORM\Table(name="admin_notification")
* @ORM\HasLifecycleCallbacks
*/
class AdminNotification {
private $em;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
[... varie definizioni di elementi ...]
public function __construct($message="")
{
$em = $this->getContainer()->get('doctrine')->getEntityManager();
$this->em = $em;
$this->message=$message;
$em->persist($this);
$em->flush();
}
}
?>
File: services.xml
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="admin_notification.class">Zen\Ig\Entity\AdminNotification</parameter>
</parameters>
<services>
<service id="admin_notification" class="%admin_notification.class%" public="false">
<argument type="service" id="router"></argument>
<!--Inject entity manager-->
<argument type="service" id="doctrine.orm.entity_manager" />
</service>
</services>
</container>
Nel file del controller o del command:
new AdminNotification('CRON: Cron start');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment