I start with doctrine and want to create a db or php class from table with doctrine.
First i try create db. My bootstrap.php:
<?php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
require_once "vendor/autoload.php";
require_once "src/BugRepository.php";
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode);
$conn = array(
'driver' => 'pdo_pgsql',
'user' => 'postgres',
'password' => '123456',
'host' => 'localhost',
'dbname' =>'testdata',
);
$entityManager = EntityManager::create($conn, $config);
and i do:
php vendor/bin/doctrine doctrine:database:create
my output:
SRC_DIR="`pwd`"
cd "`dirname "$0"`"
cd "../doctrine/orm/bin"
BIN_TARGET="`pwd`/doctrine"
cd "$SRC_DIR"
"$BIN_TARGET" "$#"
But db testdatanot created.
Same with creating php class from table:
php vendor/bin/doctrine doctrine:mapping:import YourAppBundle yml --filter="bugs"
But yml file not created.
Whats can be wrong?
There are also a bin folder in vendor/doctrine/orm/bin/ you can use this one like this
php vendor/doctrine/orm/bin/doctrine orm:schema-tool:create
make sure you have root folder and a cli-config.php file is present in root folder.
https://groups.google.com/forum/#!msg/doctrine-user/_ph183Kh-5o/_P_coljB-dcJ
Related
I am trying to use Doctrine 2 in my project, but when I try to access the command line to import the Entities from my database to generate the files, it print the code from vendor/bin/doctrine
dir=$(d=${0%[/\\]*}; cd "$d"; cd '../doctrine/orm/bin' && pwd)
# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
# Cygwin paths start with /cygdrive/ which will break windows PHP,
# so we need to translate the dir path to windows format. However
# we could be using cygwin PHP which does not require this, so we
# test if the path to PHP starts with /cygdrive/ rather than /usr/bin
if [[ $(which php) == /cygdrive/* ]]; then
dir=$(cygpath -m $dir);
fi
fi
dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/doctrine.php" "$#"
My folder structure:
src/
vendor/
bootstrap.php
cli-config.php
composer.json
composer.lock
index.php
bootstrap.php
<?php
require_once "vendor/autoload.php";
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
$paths = array("src/Entity");
$isDevMode = false;
// the connection configuration
$dbParams = array(
'driver' => 'pdo_mysql',
'user' => '',
'password' => '',
'dbname' => '',
);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($dbParams, $config);
cli-config.php
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;
// replace with file to your own project bootstrap
require_once 'bootstrap.php';
// replace with mechanism to retrieve EntityManager in your app
$entityManager = GetEntityManager();
return ConsoleRunner::createHelperSet($entityManager);
I am trying to use in my command line: php vendor/bin/doctrine --help. I am using also Vagrant with Ubuntu 14.01.
I am not using Symfony 2, Just trying to install Doctrine without any framework.
Thank you.
I got the same error when I was in windows setup and this command worked to resolve it:
php vendor/doctrine/orm/bin/doctrine.php orm:schema-tool:create
Source:
http://www.agevaled.com/2013/10/09/doctrine2-getting-started-issues/2147483647/
On Windows, the correct command to run is:
vendor/bin/doctrine.bat
I've installed Doctrine using composer, and when I try to create the database I get the error:
#!/usr/bin/env php
Why am I seeing this error - no database is created. I obtain the same error if I run update --force. I've also tried orm:schema-tool:create, and I've also tried running the doctrine php file directly php ./vendor/bin/doctrine.php orm:schema:create with the same error.
I have an bootstrap file and a cli-config file as such
// bootstrap.php
<?php
require_once 'vendor/autoload.php';
// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = true;
$config = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration(array(__DIR__."/"), $isDevMode);
// database configuration parameters
$conn = array(
'driver' => 'pdo_sqlite',
'path' => __DIR__ . '/db.sqlite',
);
// obtaining the entity manager
$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
// cli-config.php
<?php
require_once "bootstrap.php";
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager);
After much debugging, the path in this line is horribly wrong:
$config = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration(array(__DIR__."/"), $isDevMode);
Fixing it so it points to where the class files with mapping data is stored fixed it.
I am following this tutorial.
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/getting-started.html
I am using mysql instead of sqlite.
Following command should create the database.
php vendor/bin/doctrine orm:schema-tool:create
But it is not creating any. If i manually create the database, following command works fine
php vendor/bin/doctrine orm:schema-tool:update --force
Any idea why that command is not working?
Doctrine version 2.4.1
Try this link:
vendor/bin/doctrine-module orm:schema-tool:create
User doctrine-module instead of doctrine.
I was faced with a similar issue and found that the command below
php vendor/bin/doctrine orm:schema-tool:create
Doesn't create the DB itself, it only creates the schema/tables.
I solved this by doing the following:
<?php
include 'bootstrap.php';
use Doctrine\ORM\Tools\Console\ConsoleRunner,
Doctrine\ORM\EntityManager;
try {
$entityManager->getConnection()->connect();
}
catch(Exception $ex) {
$connection = EntityManager::create([
'driver' => 'pdo_mysql',
'host' => MYSQL_HOST,
'user' => MYSQL_USERNAME,
'password' => MYSQL_PASSWORD,
'charset' => 'UTF8'
], $config)->getConnection();
$connection->executeUpdate('CREATE DATABASE '.MYSQL_DATABASE.' CHARACTER SET utf8 COLLATE utf8_general_ci');
}
return ConsoleRunner::createHelperSet($entityManager);
?>
Basically the script attempts to connect to the specified database, if that fails it attempts to create the database (assuming that the user is allowed to perform database creation that is - might be prudent to delete this file
after deployment).
Source: http://www.cstruter.com/blog/395
My appKernel.php looks like this:
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\DoctrineBundle\DoctrineBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new Blogger\BlogBundle\BloggerBlogBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
}
My autoload.php looks like:
<?php
use Symfony\Component\ClassLoader\UniversalClassLoader;
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
'Symfony' => array(__DIR__.'/../vendor/symfony/src', __DIR__.'/../vendor/bundles'),
'Sensio' => __DIR__.'/../vendor/bundles',
'JMS' => __DIR__.'/../vendor/bundles',
'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib',
'Doctrine\\DBAL' => __DIR__.'/../vendor/doctrine-dbal/lib',
'Doctrine' => __DIR__.'/../vendor/doctrine/lib',
'Monolog' => __DIR__.'/../vendor/monolog/src',
'Assetic' => __DIR__.'/../vendor/assetic/src',
'Metadata' => __DIR__.'/../vendor/metadata/src',
));
$loader->registerPrefixes(array(
'Twig_Extensions_' => __DIR__.'/../vendor/twig-extensions/lib',
'Twig_' => __DIR__.'/../vendor/twig/lib',
));
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->registerPrefixFallbacks(array(__DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs'));
}
$loader->registerNamespaceFallbacks(array(
__DIR__.'/../src',
));
$loader->register();
AnnotationRegistry::registerLoader(function($class) use ($loader) {
$loader->loadClass($class);
return class_exists($class, false);
});
AnnotationRegistry::registerFile(__DIR__.'/../vendor/doctrine/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
// Swiftmailer needs a special autoloader to allow
// the lazy loading of the init file (which is expensive)
require_once __DIR__.'/../vendor/swiftmailer/lib/classes/Swift.php';
Swift::registerAutoload(__DIR__.'/../vendor/swiftmailer/lib/swift_init.php');
When I do:
php app/console assets:install web
I get the following:
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for Acme\DemoBundle into web/bundles/acmedemo
Installing assets for Symfony\Bundle\WebProfilerBundle into web/bundles/webprofiler
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
Why is my BloggerBlogBundle not getting copied over?
Note: As OP's answer is short and doesn't really go into too much detail, here's a more in-depth answer for future readers, so hopefully you don't have to do as much digging as I did! :)
It seems that we're following the exact same tutorial and have the exact same issue, and as the answer above isn't very descriptive and I had to do a little digging myself, here's exactly what's wrong.
Step 1
Your src/Blogger/BlogBundle needs to have, in the /resources folder, a public/css folder. So you need to place your CSS files as follows:
src/Blogger/BlogBundle/resources/public/css/<stylesheet>.css
Create the /public/css folder if it doesn't exist (it didn't exist for me).
Step 2
You need to run the assetic management tool to have a symlink created in /web automatically for you so these can be accessed.
php app/console assets:install web
You now will notice that if you open (using windows explorer / nautilus on linux) your dev directory and find the /web folder, that /web/bundles/bloggerblog/css/<stylesheet>.css has been created automatically for you!
You can now access your CSS files in your code using:
<link href="{{ asset('/bundles/bloggerblog/css/<stylesheet>.css') }}" type="text/css" rel="stylesheet" />
Note: '.css' is replaced with screen 'screen.css' for this tutorial
...and that should be it!
I have the the exact same problem with the original question, where assets are not copied over from Resources folder of bundles to web/bundles after running 'php app/console assets:install web' so what i did was running this command 'php app/console cache:clear --env=prod' and that fixed it. As you can see that you are dealing with prod assets or installing assets to prod environment in web directory, so clear cach for prod is reasonable. So do this:
1) $ php app/console cache:clear --env=prod
2) $ php app/console assets:install web
OR $ php app/console assets:install web --symlink
3) $ php app/console assetic:dump --env=prod (If you use built in Assetic, it will dump/combine css to one big one in /web/css as opposed to /web/bundles)
everything goes in place after that. you get all assets in your /web/bundles and assetic dump in /web/css and all of these are for prod env.
Just had this problem, ensure that the BlahBundle.php is located in the same directory as the Resources directory
I've had this issue today with Symfony3.3.13 and the problem was the public directory was actually capitalised Public, which seems to break the install script. Changing the name and it worked immediately.
Having never touched Doctrine before (either 1 or 2), I am following this tutorial for Doctrine 2.
I'm at the point where I use the command line to generate the database schema. This is the cli-config.php file, as per the tutorial:
<?php
$cliConfig = new Doctrine\Common\Cli\Configuration();
$cliConfig->setAttribute('em', $entityManager);
When I run it though, I just get an error:
Fatal error: require(): Failed opening required 'Doctrine\Common\Cli\Configuration.php'
Because that class referenced by the cli-config.php file doesn't exist. I've also tried blanking the cli-config.php file, which of course doesn't work either - says that "The helper "em" is not defined."
I'm using version 2.0.0BETA3. I know that this is a beta version, so they could have changed some files around, but I can't find that class anywhere.
Any ideas on how to get it working?
The docs in the XML Getting Started are outdated in this regard. Please see the Tools section in the manual on how to configure the CLI Tool:
http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/tools.html
All the rest still works as described. I will update this part asap.
Assuming you installed Doctrine using pear
$ sudo pear install pear.doctrine-project.org/doctrineORM
which will install the three 'Doctrine 2' packages: DoctrineCommon, DoctrineDBAL, and DoctrineORM. On Ubuntu, these packages will be located in /usr/share/php/Doctrine, and the doctrine command line utility, will be installed into /usr/bin.
With this setup, this is a version of cli-config.php you can use (note: DIR should have two underscores before and after it. For some reason they didn't display).
<?php
require ‘Doctrine/ORM/Tools/Setup.php’;
// Setup Autoloader (1)
Doctrine\ORM\Tools\Setup::registerAutoloadPEAR();
require_once 'Doctrine/Common/ClassLoader.php';
$classLoader = new Doctrine\Common\ClassLoader('Entities', __DIR__);
$classLoader->register();
$classLoader = new Doctrine\Common\ClassLoader('Proxies', __DIR__);
$classLoader->register();
$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__."/Entities"));
$config->setMetadataDriverImpl($driverImpl);
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
$connectionOptions = array(
'driver' => 'pdo_mysql',
'dbname' => 'bugs',
'user' => 'bugs',
'password' => 'xyzabc',
'host' => 'localhost' );
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));