0
votes

Client Entity

<?php

namespace Application\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Client
 *
 * @ORM\Table(name="client", uniqueConstraints={@ORM\UniqueConstraint(name="mail", columns=    
 * {"mail"}), @ORM\UniqueConstraint(name="pseudo", columns={"pseudo"})}, indexes=
 * {@ORM\Index(name="FK_client_situation", columns={"situation"}),   
 *@ORM\Index(name="FK_client_city", columns={"ville"})})
 * @ORM\Entity
 */
class Client
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="firstname", type="string", length=255, nullable=true)
     */
    private $firstname;

    /**
     * @var string
     *
     * @ORM\Column(name="lastname", type="string", length=255, nullable=true)
     */
    private $lastname;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="birthay", type="datetime", nullable=true)
     */
    private $birthay;

    /**
     * @var string
     *
     * @ORM\Column(name="mail", type="string", length=255, nullable=true)
     */
    private $mail;

    /**
     * @var string
     *
     * @ORM\Column(name="phone", type="text", nullable=true)
     */
    private $phone;

    /**
     * @var string
     *
     * @ORM\Column(name="pseudo", type="string", length=255, nullable=true)
     */
    private $pseudo;

    /**
     * @var string
     *
     * @ORM\Column(name="password", type="string", length=255, nullable=true)
     */
    private $password;

    /**
     * @var integer
     *
     * @ORM\Column(name="situation", type="integer", nullable=true)
     */
    private $situation;

    /**
     * @var integer
     *
     * @ORM\Column(name="ville", type="integer", nullable=true)
     */
    private $ville;

    /**
     * @var string
     *
     * @ORM\Column(name="facebook", type="string", length=255, nullable=true)
     */
    private $facebook;

    /**
     * @var string
     *
     * @ORM\Column(name="picture", type="string", length=255, nullable=true)
     */
    private $picture;

    /**
     * @var integer
     *
     * @ORM\Column(name="newseltter", type="integer", nullable=true)
     */
    private $newseltter;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="dateinscription", type="datetime", nullable=true)
     */
    private $dateinscription;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="datedelete", type="datetime", nullable=true)
     */
    private $datedelete;

    /**
     * @var string
     *
     * @ORM\Column(name="statut", type="string", length=50, nullable=true)
     */
    private $statut;

    /**
     * @var string
     *
     * @ORM\Column(name="contenu", type="text", nullable=true)
     */
    private $contenu;



    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set firstname
     *
     * @param string $firstname
     * @return Client
     */
    public function setFirstname($firstname)
    {
        $this->firstname = $firstname;

        return $this;
    }

    /**
     * Get firstname
     *
     * @return string 
     */
    public function getFirstname()
    {
        return $this->firstname;
    }

    /**
     * Set lastname
     *
     * @param string $lastname
     * @return Client
     */
    public function setLastname($lastname)
    {
        $this->lastname = $lastname;

        return $this;
    }

    /**
     * Get lastname
     *
     * @return string 
     */
    public function getLastname()
    {
        return $this->lastname;
    }

    /**
     * Set birthay
     *
     * @param \DateTime $birthay
     * @return Client
     */
    public function setBirthay($birthay)
    {
        $this->birthay = $birthay;

        return $this;
    }

    /**
     * Get birthay
     *
     * @return \DateTime 
     */
    public function getBirthay()
    {
        return $this->birthay;
    }

    /**
     * Set mail
     *
     * @param string $mail
     * @return Client
     */
    public function setMail($mail)
    {
        $this->mail = $mail;

        return $this;
    }

    /**
     * Get mail
     *
     * @return string 
     */
    public function getMail()
    {
        return $this->mail;
    }

    /**
     * Set phone
     *
     * @param string $phone
     * @return Client
     */
    public function setPhone($phone)
    {
        $this->phone = $phone;

        return $this;
    }

    /**
     * Get phone
     *
     * @return string 
     */
    public function getPhone()
    {
        return $this->phone;
    }

    /**
     * Set pseudo
     *
     * @param string $pseudo
     * @return Client
     */
    public function setPseudo($pseudo)
    {
        $this->pseudo = $pseudo;

        return $this;
    }

    /**
     * Get pseudo
     *
     * @return string 
     */
    public function getPseudo()
    {
        return $this->pseudo;
    }

    /**
     * Set password
     *
     * @param string $password
     * @return Client
     */
    public function setPassword($password)
    {
        $this->password = $password;

        return $this;
    }

    /**
     * Get password
     *
     * @return string 
     */
    public function getPassword()
    {
        return $this->password;
    }

    /**
     * Set situation
     *
     * @param integer $situation
     * @return Client
     */
    public function setSituation($situation)
    {
        $this->situation = $situation;

        return $this;
    }

    /**
     * Get situation
     *
     * @return integer 
     */
    public function getSituation()
    {
        return $this->situation;
    }

    /**
     * Set ville
     *
     * @param integer $ville
     * @return Client
     */
    public function setVille($ville)
    {
        $this->ville = $ville;

        return $this;
    }

    /**
     * Get ville
     *
     * @return integer 
     */
    public function getVille()
    {
        return $this->ville;
    }

    /**
     * Set facebook
     *
     * @param string $facebook
     * @return Client
     */
    public function setFacebook($facebook)
    {
        $this->facebook = $facebook;

        return $this;
    }

    /**
     * Get facebook
     *
     * @return string 
     */
    public function getFacebook()
    {
        return $this->facebook;
    }

    /**
     * Set picture
     *
     * @param string $picture
     * @return Client
     */
    public function setPicture($picture)
    {
        $this->picture = $picture;

        return $this;
    }

    /**
     * Get picture
     *
     * @return string 
     */
    public function getPicture()
    {
        return $this->picture;
    }

    /**
     * Set newseltter
     *
     * @param integer $newseltter
     * @return Client
     */
    public function setNewseltter($newseltter)
    {
        $this->newseltter = $newseltter;

        return $this;
    }

    /**
     * Get newseltter
     *
     * @return integer 
     */
    public function getNewseltter()
    {
        return $this->newseltter;
    }

    /**
     * Set dateinscription
     *
     * @param \DateTime $dateinscription
     * @return Client
     */
    public function setDateinscription($dateinscription)
    {
        $this->dateinscription = $dateinscription;

        return $this;
    }

    /**
     * Get dateinscription
     *
     * @return \DateTime 
     */
    public function getDateinscription()
    {
        return $this->dateinscription;
    }

    /**
     * Set datedelete
     *
     * @param \DateTime $datedelete
     * @return Client
     */
    public function setDatedelete($datedelete)
    {
        $this->datedelete = $datedelete;

        return $this;
    }

    /**
     * Get datedelete
     *
     * @return \DateTime 
     */
    public function getDatedelete()
    {
        return $this->datedelete;
    }

    /**
     * Set statut
     *
     * @param string $statut
     * @return Client
     */
    public function setStatut($statut)
    {
        $this->statut = $statut;

        return $this;
    }

    /**
     * Get statut
     *
     * @return string 
     */
    public function getStatut()
    {
        return $this->statut;
    }

    /**
     * Set contenu
     *
     * @param string $contenu
     * @return Client
     */
    public function setContenu($contenu)
    {
        $this->contenu = $contenu;

        return $this;
    }

    /**
     * Get contenu
     *
     * @return string 
     */
    public function getContenu()
    {
        return $this->contenu;
    }
}

?>

ClienFieldset

<?php
namespace Application\Form;


use Application\Entity\Client;


use Doctrine\Common\Persistence\ObjectManager;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
use Zend\Form\Fieldset;
use Zend\InputFilter\InputFilterProviderInterface;



class ClientFieldset extends Fieldset implements InputFilterProviderInterface
{
    public function __construct(ObjectManager $objectManager)
    {
        parent::__construct('post');


        //$em = Registry::get('entityManager');

        $this->setHydrator(new DoctrineHydrator($objectManager,'Application\Entity\Client'))
            ->setObject(new Client());

        $this->setLabel('Post');

        $this->add(array(
            'name' => 'id',
            'attributes' => array(
                'type' => 'hidden'
            )
        ));

        $this->add(array(
            'name' => 'mail',
            'options' => array(
                'label' => 'Title for this Post'
            ),
            'attributes' => array(
                'type' => 'text'
            )
        ));

        $this->add(array(
            'name' => 'password',
            'options' => array(
                'label' => 'Text-Content for this post'
            ),
            'attributes' => array(
                'type' => 'text'
            )
        ));
    }

    /**
     * Define InputFilterSpecifications
     *
     * @access public
     * @return array
     */
    public function getInputFilterSpecification()
    {
        return array(
            'mail' => array(
                'required' => true,
                'filters' => array(
                    array('name' => 'StringTrim'),
                    array('name' => 'StripTags')
                ),
                'properties' => array(
                    'required' => true
                )
            ),
            'password' => array(
                'required' => true,
                'filters' => array(
                    array('name' => 'StringTrim'),
                    array('name' => 'StripTags')
                ),
                'properties' => array(
                    'required' => true
                )
            )
        );
    }
}

?>

Client Form

<?php
namespace Application\Form;

use Doctrine\Common\Persistence\ObjectManager;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
use Zend\Form\Form;

class ClientForm extends Form
{

        public function __construct(ObjectManager $objectManager)
    {
        parent::__construct('post');

        // The form will hydrate an object of type "BlogPost"
        $this->setHydrator(new DoctrineHydrator($objectManager));

        // Add the user fieldset, and set it as the base fieldset
        $clientFieldset = new ClientFieldset($objectManager);
        $clientFieldset->setUseAsBaseFieldset(true);
        $this->add($clientFieldset);




        $this->add(array(
            'name' => 'security',
            'type' => 'Zend\Form\Element\Csrf'
        ));

        $this->add(array(
            'name' => 'submit',
            'attributes' => array(
                'type'  => 'submit',
                'value' => 'Go',
                'id'    => 'submitbutton'
            )
        ));

        $this->setValidationGroup(array(
            'security',
            'post' => array(
                'title',
                'text'
            )
        ));
    }
}

?>

Index Action

<?php

 public function indexAction()
    {
        $objectManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');

        // Create the form and inject the ObjectManager
        $form = new ClientForm($objectManager);

        // Create a new, empty entity and bind it to the form
        $Client = new Client();
        $form->bind($Client);


        if ($this->request->isPost()) {
            $form->setData($this->request->getPost());

            if ($form->isValid()) {
                $objectManager->persist($Client);
                $objectManager->flush();
            }
        }
        return array('form' => $form);


    }
?>
#index View

<table class="table">
    <?php
    if($this->form){
        echo $this->form()->openTag($form);
        echo $this->formRow($form->get('id'));

        echo $this->formRow($form->get('mail'));

        echo $this->form()->closeTag();
    }

</table> ?>

When i execute My Code i get this Error..

Warning: include(/var/www/Colocation/Colocation/module/Visitor/config/../view/error/index.phtml): failed to open stream: No such file or directory in /var/www/Colocation/Colocation/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php on line 506

Warning: include(): Failed opening '/var/www/Colocation/Colocation/module/Visitor/config/../view/error/index.phtml' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/Colocation/Colocation/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php on line 506

Pleaz Help me!

1

1 Answers

0
votes

The php warning says that it cannot find the file error/index.phtml.

It is looking for this file because somewhere in your code there is an error, which would lead to the error page.

Default error page files are located in the Application module (module/Application/view/error/), but in your case, it is trying to find these files in the 'Visitor' module.

Perhaps in the 'Visitor' module you overwritten the Application's module 'view_manager' configs, so you can try ONE of the follow:

  • Open the 'Visitor' module config file and comment or remove all error related configs, using this config for the 'view_manager' should be enough

    'view_manager' => array( 'template_path_stack' => array( 'visitor' => __DIR__ . '/../view', ), ),

  • Create error page templates in your 'Visitor' module like the ones you can find in the Application module. Do this only if you want to customize your error page template, keeping unchanged the Application error template, otherwise use the first solution.

After you finish you should be able to see another error but this time related to your code!