Answer the question
In order to leave comments, you need to log in
How to create an Entity in zf3 via command line?
Hello, I decided to learn ZF3. I watch video tutorials, though on ZF2, I found a book on the third zend. Reached creation of entities from a DB. In the video tutorials, entities are created through a .bat file on the command line. I don’t create them like that, in the comments to the video I found a code that does the same from the command line
doctrine-module orm:convert-mapping --namespace="Shop\Entity\\" --force --from-database annotation ./module/Shop/src/and
doctrine-module orm:generate-entities ./module/Shop/src/ --generate-annotations=true
<?php
// bootstrap.php
require_once "../../vendor/autoload.php";
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Shop\Entity;?
$paths = array(Entity);?
$isDevMode = false;
// the connection configuration
$dbParams = array(
'driver' => 'pdo_mysql',
'user' => 'root',
'password' => '1',
'dbname' => 'shop',
);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($dbParams, $config);
<?php
namespace Shop;
use Zend\Router\Http\Segment;
use Zend\ServiceManager\Factory\InvokableFactory;
return [
'doctrine' => [
'driver' => [
'shop_entity' => [
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => [
__DIR__. '/../src/Shop/Entity',
],
],
'orm_default' => [
'drivers' => [
'Shop\Entity' => 'shop_entity'
]
]
]
],
'router' => [
'routes' => [
'shop' => [
'type' => Segment::class,
'options' => [
'route' => '/[:action/][:id/]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
],
],
'controllers' => [
'factories' => [
Controller\IndexController::class => InvokableFactory::class,
],
],
'view_manager' => [
'template_path_stack' => [
__DIR__ . '/../view',
],
],
];
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;
// replace with file to your own project bootstrap
require_once '/autoload/bootstrap.php';
// replace with mechanism to retrieve EntityManager in your app
$entityManager = GetEntityManager();
return ConsoleRunner::createHelperSet($entityManager);
doctrine orm:convert-mapping --namespace="Shop\Entity\\" --force --from-database annotation ./module/Shop/src/
php vendor/bin/doctrinewhy she does not understand, when I run it, she just gives me the contents of the file and that's it. And last question: How to create Entity in zf3 via command line?
Answer the question
In order to leave comments, you need to log in
No need to create any bootstrap.php
In global.php or local.php in the config, write the connection settings for Doctrine The
module is accessed along the path: ./vendor/doctrine/doctrine-module/bin/doctrine-module
In your case, like this:
. /vendor/doctrine/doctrine-module/bin/doctrine-module orm:convert-mapping --namespace="Shop\Entity\\" --force --from-database annotation ./module/Shop/src/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question