Created
September 23, 2010 11:57
-
-
Save loicfrering/593514 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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