0
votes

Questions? How to generate getters and setters in Symfony CMS for documents? Why namespace TaskBundle or Acme\TaskBundle is not recognised by the command doctrine:entities generate?

I have installed the standard-edition of CMS and try to make examples from official documentation: http://symfony.com/doc/master/cmf/book/database_layer.html

I need to generate setters and getters for the Document Task.php

For this i decided to use command "doctrine:generate:entities". Thus created a new folder Entities and copied Task.php file from Document folder: C:\Bitnami\wampstack-5.4.38-0\sym_prog\standard-edition\src\Acme\TaskBundle\Entity\Task.php I hoped to generate setters and getters and than copy them back to the Document\Task.php

Command doctrine:generate:entities was not existing. Thus i updated comsposer.json C:\Bitnami\wampstack-5.4.38-0\sym_prog\standard-edition\composer.json

    "require": {
...
        "doctrine/orm": "^2.4.8",
        "doctrine/doctrine-bundle": "~1.4",

But now i am getting the error about namespace:

c:\Bitnami\wampstack-5.4.38-0\sym_prog\standard-edition>php app/console generate:doctrine:entities TaskBundle:Task
  [Doctrine\ORM\ORMException]
  Unknown Entity namespace alias 'TaskBundle'.

c:\Bitnami\wampstack-5.4.38-0\sym_prog\standard-edition>php app/console generate:doctrine:entity
The Entity shortcut name: Acme/TaskBundle:Task
Bundle "Acme\TaskBundle" does not exist.
The Entity shortcut name: TaskBundle:Task
Bundle "TaskBundle" does not exist.

C:\Bitnami\wampstack-5.4.38-0\sym_prog\standard-edition\src\Acme\TaskBundle\Entity\Task.php

   <?php

    /* If you use annotations, you'll need 
     * to prepend all annotations with @PHPCR\, 
     * which is the name of the imported namespace 
     * (e.g. @PHPCR\Document(..)), 
     * this is not shown in Doctrine's documentation. 
     * You'll also need to include the 
     * use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;
     *  statement to import the PHPCR annotations prefix. */


    // src/Acme/TaskBundle/Entity/Task.php
    namespace Acme\TaskBundle\Entity;

    class Task
    {
         /**
         * @PHPCR\Id()
         */
        protected $id;

        /**
         * @PHPCR\String()
         */
        protected $description;

        /**
         * @PHPCR\Boolean()
         */
        protected $done = false;

        /**
         * @PHPCR\ParentDocument()
         */
        protected $parentDocument;
    }



Questions?
How to generate getters and setters in Symfony CMS for documents?
Why namespace TaskBundle or Acme\TaskBundle is not recognised by the command doctrine:entities generate?
2

2 Answers

1
votes

One more way is to write own script for setters and getters generation.

File example (com.php) is below. In this case one has to input field names to the custom array $avar and also write the correct path to the file where setters and getters will be generated. Than save the file to the directory where console is directed (for example c:\Bitnami\wampstack-5.4.38-0\symfony\project1\com.php) and run command line: c:\Bitnami\wampstack-5.4.38-0\sym_prog\standard-edition>php com.php

<?php
//c:\Bitnami\wampstack-5.4.38-0\symfony\project1\com.php

//write here own field names, for which you need setters and getters
$avar=[ "description", "done", "parentDocument" ];
$sstr="<?php ";

foreach($avar as $item){
    $uitem=ucfirst($item);
        echo($item);

    $sstr=$sstr."

    /**
     * Set $item
     *
     * @param string \$$item
     *
     * @return **ADD**
     */
    public function set$uitem(\$$item)
    {
        \$this->$item = \$$item;

        return \$this;
    }

    /**
     * Get $item
     *
     * @return string
     */
    public function get$uitem()
    {
        return \$this->$item;
    }
    ";
 }   

//write here the path and filenae where setters and getters will be generated
// or you can append the file, where you need setters and getters
    $fcom=fopen("C:\Bitnami\wampstack-5.4.38-0symfony\project1\a.php","w");
    fwrite($fcom,$sstr);
    fclose($fcom);

//copy setter and getters to file, where you need them. 
0
votes

Try this:

php app/console generate:doctrine:entities AcmeTaskBundle:Task