Skip to content

Instantly share code, notes, and snippets.

@loicfrering
Created September 23, 2010 11:57
Show Gist options
  • Save loicfrering/593514 to your computer and use it in GitHub Desktop.
Save loicfrering/593514 to your computer and use it in GitHub Desktop.
<?php
namespace Application\HelloBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
/** @Controller */
class HelloController extends Controller
{
protected $userRepository;
/** @Inject */
public function setUserRepository($userRepository)
{
$this->userRepository = $userRepository;
return $this;
}
public function indexAction($name)
{
$user = $this->userRepository->findOneByName($name);
return $this->render('HelloBundle:Hello:index', array('user' => $user));
}
}
<?php
namespace Application\HelloBundle\Repository;
use Doctrine\ORM\EntityRepository;
/** @Service */
class UserRepository extends EntityRepository
{
protected $logger;
/** @Inject("zend.logger") */
public function setLogger($logger)
{
$this->logger = $logger;
return $this;
}
public function createUser($user)
{
$this->_em->persist($user);
$this->logger->info('User ' . $user->getName() . ' successfully persisted.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment