i dont retrieve any thing beacuse i gget a server error and i dont
understand why, maybe i have a sintax error somewhere? i'll post my
controller code too.
<?php
> // module/Album/src/Album/Controller/AlbumController.php:
> namespace Album\Controller;
> use Zend\Mvc\Controller\AbstractActionController;
> use Zend\Mvc\Controller\ActionController,
>
> Zend\View\Model\JsonModel;
> use Zend\View\Model\ViewModel;
> use Album\Model\Album; // <-- Add this import
> use Album\Form\AlbumForm; // <-- Add this import
> use Zend\EventManager\Event;
> use Zend\Controller\Request\Http;
> use Doctrine\ORM\EntityManager;
> class AlbumController extends AbstractActionController
> {
>
>
> // $translator = new Translator();
> // $translator->addTranslationFile($type, $filename, $textDomain,
> $locale);
> protected $albumTable;
> protected $em;
> public function setEntityManager(EntityManager $em)
> {
> $this->em = $em;
> }
> public function getEntityManager()
> {
> if (null === $this->em) {
> $this->em =
> $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
> }
> return $this->em;
> }
>
>
> public function indexAction()
> {
>
> var_dump($this->getServiceLocator()->get('doctrine.connection.orm_default'));
> exit;
>
> //-----------------------------------------------------------------
>
> // $lang = $this->params()->fromPost('paramname');
> //$lang = $request->getUserParam(lingua’);
> $lingua = $_GET['lingua'];
> $lang =
> $this->getEvent()->getRouteMatch()->getParam('locale','en');//,'en_US');
> if ($lingua != '')
> $lang = $lingua;
> //echo $lang;
>
> //echo $lang;
>
> //$lang = $lingua;
> $loc = $this->getServiceLocator();
> $translator = $loc->get('translator');
> $translator->addTranslationFile("phparray",
> './module/Album/language/lang.array.'.$lang.'.php');
> //attach
> $loc->get('ViewHelperManager')->get('translate')
> ->setTranslator($translator);
> //--------------------------------------------------------------------
>
> return new ViewModel(array(
> 'albums' =>
> $this->getEntityManager()->getRepository('Album\Entity\Album')->findAll()
> ));
> //'albums' => $this->getAlbumTable()->fetchAll();
>
>
>
>
> // return new JsonModel(array(
>
> // 'json' => $matches,//$this->getAlbumTable()->fetchAll(),
> //'success'=>true,
>
> //));
> // echo $result;
>
>
> // return $result;
>
>
>
>
> }
> public function addAction()
> {
>
> //$lang =
> $this->getEvent()->getRouteMatch()->getParam('locale','it');//,'en_US');
> $lingua = $_GET['lingua'];
> $lang =
> $this->getEvent()->getRouteMatch()->getParam('locale','en');//,'en_US');
> if ($lingua != '')
> $lang = $lingua;
> echo $lang;
> if (strtolower($lang) != 'en' && strtolower($lang) != 'it')
> $lang = 'it_IT';
> //echo $lang;
> $loc = $this->getServiceLocator();
> $translator = $loc->get('translator');
> $translator->addTranslationFile("phparray",
> './module/Album/language/lang.array.'.$lang.'.php');
> //attach
> $loc->get('ViewHelperManager')->get('translate')
> ->setTranslator($translator);
> //--------------------------------------------------------------------
> $form = new AlbumForm();
> $form->get('submit')->setValue('Add');
> $request = $this->getRequest();
> if ($request->isPost()) {
> $album = new Album();
> $form->setInputFilter($album->getInputFilter());
> $form->setData($request->getPost());
> if ($form->isValid()) {
> $album->populate($form->getData());
> $this->getEntityManager()->persist($album);
> $this->getEntityManager()->flush();
> // Redirect to list of albums
> return $this->redirect()->toRoute('album');
> }
> }
> return array('form' => $form);
> $_POST[$lingua];
> }
> public function editAction()
> {
> //-----------------------------------------------------------------
>
> $lingua = $_GET['lingua'];
> $lang =
> $this->getEvent()->getRouteMatch()->getParam('locale','it');//,'en_US');
> if ($lingua != '')
> $lang = $lingua;
> echo $lang;
> if (strtolower($lang) != 'en' && strtolower($lang) != 'it')
> $lang = 'it_IT';
> //echo $lang;
> $loc = $this->getServiceLocator();
> $translator = $loc->get('translator');
> $translator->addTranslationFile("phparray",
> './module/Album/language/lang.array.'.$lang.'.php');
> //attach
> $loc->get('ViewHelperManager')->get('translate')
> ->setTranslator($translator);
> //--------------------------------------------------------------------
> $id = (int)$this->getEvent()->getRouteMatch()->getParam('id');
> if (!$id) {
> return $this->redirect()->toRoute('album',
> array('action'=>'add'));
> }
> $album = $this->getEntityManager()->find('Album\Entity\Album',
> $id);
> $form = new AlbumForm();
> $form->setBindOnValidate(false);
> $form->bind($album);
> $form->get('submit')->setAttribute('label', 'Edit');
>
> $request = $this->getRequest();
> if ($request->isPost()) {
> $form->setData($request->post());
> if ($form->isValid()) {
> $form->bindValues();
> $this->getEntityManager()->flush();
> // Redirect to list of albums
> return $this->redirect()->toRoute('album');
> }
> }
> return array(
> 'id' => $id,
> 'form' => $form,
> );
>
> }
> public function deleteAction()
> {
> //-----------------------------------------------------------------
>
> $lingua = $_GET['lingua'];
> $lang =
> $this->getEvent()->getRouteMatch()->getParam('locale','it');//,'en_US');
> if ($lingua != '')
> $lang = $lingua;
> echo $lang;
> if (strtolower($lang) != 'en' && strtolower($lang) != 'it')
> $lang = 'it_IT';
> //echo $lang;
> $loc = $this->getServiceLocator();
> $translator = $loc->get('translator');
> $translator->addTranslationFile("phparray",
> './module/Album/language/lang.array.'.$lang.'.php');
> //attach
> $loc->get('ViewHelperManager')->get('translate')
> ->setTranslator($translator);
> //--------------------------------------------------------------------
> // $id = (int) $this->params()->fromRoute('id', 0);
> $id =
> (int)$this->getEvent()->getRouteMatch()->getParam('id');
> if (!$id) {
> return $this->redirect()->toRoute('album');
> }
> $request = $this->getRequest();
> if ($request->isPost()) {
> $del = $request->getPost('del', 'No');
> if ($del == 'Yes') {
> $id = (int)$request->post()->get('id');
> //$id = (int) $request->getPost('id');
> // $this->getAlbumTable()->deleteAlbum($id);
> $album =
> $this->getEntityManager()->find('Album\Entity\Album', $id);
> if ($album) {
> $this->getEntityManager()->remove($album);
> $this->getEntityManager()->flush();
> }
> }
> // Redirect to list of albums
> return $this->redirect()->toRoute('album');
> }
> return array(
> 'id' => $id,
> //'album' => $this->getAlbumTable()->getAlbum($id)
> 'album' =>
> $this->getEntityManager()->find('Album\Entity\Album', $id)->getArrayCopy()
>
> );
> $_POST[$lingua];
> }
> public function getAlbumTable()
> {
> if (!$this->albumTable) {
> $sm = $this->getServiceLocator();
> $this->albumTable = $sm->get('Album\Model\AlbumTable');
> }
> return $this->albumTable;
> }
> }
On Mon, Sep 24, 2012 at 10:40 AM, gzamboni [via Zend Framework Community] <
[email protected]> wrote:
> Can you make an example for how can i retrieve this object?
> Mi potresti fare un esempio? Sono veramente scarso attualmente e sto
> cercando di imparare il piu possibile anche se i tutorial scarseggiano sul
> sito ufficiale ancora xD
> grazie
> thx
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://zend-framework-community.634137.n4.nabble.com/Postgres-configuration-with-doctrine-ZF2-tp4657079p4657081.html
> To unsubscribe from Postgres configuration with doctrine ZF2, click
> here<http://zend-framework-community.634137.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4657079&code=Z2lhbmZyYW5jby56YW1ib25pQGdzYW5ldC5pdHw0NjU3MDc5fDE2NTAwMjQxNTE=>
> .
> NAML<http://zend-framework-community.634137.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/Postgres-configuration-with-doctrine-ZF2-tp4657079p4657083.html
Sent from the Zend Framework mailing list archive at Nabble.com.