V
V
Victoria Kabishova2020-10-30 12:14:22
PHP
Victoria Kabishova, 2020-10-30 12:14:22

Have I connected Doctrine correctly?

Hello, I would like to know if I configured Doctrine correctly.
First I created a composer.json file

{
  "require": {
    "doctrine/orm": "^2.6.2",
    "symfony/yaml": "2.*"
  },
  "autoload": {
    "psr-0": { "": "src/" }
  }
}

then I downloaded Doctrine via the command line using the command - $ composer install. Then I created the files
bootstrap.php
// bootstrap.php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;

require_once "vendor/autoload.php";

// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = true;
$proxyDir = null;
$cache = null;
$useSimpleAnnotationReader = false;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode, $proxyDir, $cache, $useSimpleAnnotationReader);
// or if you prefer yaml or XML
//$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode);
//$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode);

// database configuration parameters
$conn = array(
    'dbname' => 'desktop-e7l10uh.my-dream-app.dbo',
    'user' => 'root',
    'password' => '',
    'host' => 'localhost',
    'driver' => 'pdo_sqlite',
    'path' => __DIR__ . '/db.sqlite'
    );

// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);

Если у вас возник вопрос откуда я взяла dbname, то вот
5f9bd8fb1398f504614487.png

и cli-config.php
// cli-config.php
require_once "bootstrap.php";

return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager);


Then I created the table creation files.
user.php
// src/User.php
class User
{
  /**
   * @Entityy @Table (name="users")*/

  /**
   * @ID @Column (type="integer") @GeneratedValue*/
  protected $id;
  /**
   * @Column (type="string")*/
  protected $name;
  /**
   * @Column (type="string")*/
  protected $email;

  /**
   * @Column (type="string")*/
  protected $password;

  public function getId()
  {
    return $this->id;
  }

  public function getName()
  {
    return $this->name;
  }

  public function setName($name)
  {
    $this->name = $name;
  }

  public function getEmail()
  {
    return $this->email;
  }

  public function setEmail($email)
  {
    $this->email = $email;
  }

  public function getPassword()
  {
    return $this->password;
  }

  public function setPassword($password)
  {
    $this->password = $password;
  }
}


Company.php
// src/Company.php
class Company
{
  /**
   * @Entityy @Table (name="company")*/

  /**
   * @ID @Column (type="integer") @GeneratedValue*/
  protected $id;
  /**
   * @Column (type="string")*/
  protected $name;
  /**
   * @Column (type="string")*/
  protected $news;

  /**
   * @Column (type="string")*/
  protected $video;
  /**
   * @Column (type="string")*/
  protected $description;
  /**
   * @Column (type="string")*/
  protected $tags;


  public function getId()
  {
    return $this->id;
  }

  public function getName()
  {
    return $this->name;
  }

  public function setName($name)
  {
    $this->name = $name;
  }

  public function getNews()
  {
    return $this->news;
  }

  public function setNews($news)
  {
    $this->news = $news;
  }

  public function getVideo()
  {
    return $this->video;
  }

  public function setVideo($video)
  {
    $this->news = $video;
  }

  public function getDescription()
  {
    return $this->description;
  }

  public function setDescription($description)
  {
    $this->description = $description;
  }

  public function getTags()
  {
    return $this->tags;
  }

  public function setTags($tags)
  {
    $this->tags = $tags;
  }
}


Admin.php
// src/Admin.php
class Company
{
  /**
   * @Entityy @Table (name="admin")*/

  /**
   * @ID @Column (type="integer") @GeneratedValue*/
  protected $id;
  /**
   * @Column (type="string")*/
  protected $name;
  /**
   * @Column (type="string")*/
  protected $thematics;
  /**
   * @Column (type="string")*/
  protected $bonus;
  /**
   * @Column (type="string")*/
  protected $medals;


  public function getId()
  {
    return $this->id;
  }

  public function getName()
  {
    return $this->name;
  }

  public function setName($name)
  {
    $this->name = $name;
  }

  public function getThematics()
  {
    return $this->thematics;
  }

  public function setThematics($thematics)
  {
    $this->thematics = $thematics;
  }

  public function getBonus()
  {
    return $this->bonus;
  }

  public function setBonus($bonus)
  {
    $this->bonus = $bonus;
  }

  public function getMedals()
  {
    return $this->medals;
  }

  public function setMedals($medals)
  {
    $this->medals = $medals;
  }
}


Then I entered the command on the command line to create tables in the database - $ vendor/bin/doctrine orm:schema-tool:update --force --dump-sql
And at this point I got an error
5f9bd86f1b0fd809465578.png
Why? What I did wrong? Or didn't?
The server is SQL Server. The application was created using the Angular CLI.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sl0, 2020-10-30
@Parsifal31017

array(__DIR__."/src"),
Windows and Linux have different slashes. You can use DIRECTORY_SEPARATOR instead of "/", but for the future I would strongly advise you to work in a Linux environment (wsl, vagrant, virtual machine, the second system - there are a lot of options). Believe me, this is not the last plug that you will have to face when developing the web under Windows.

F
FanatPHP, 2020-10-30
@FanatPHP

First, the doctrine is connected incorrectly.
It was not necessary to create a new folder and a new composer jason - there are already composer files in the root of the project, it was necessary to edit them,
or better without any editing - just composer require doctrine/orm
Secondly, regarding the error. I myself never set the doctrine - I always used the symphony that was already ready - but by googling the word createAnnotationMetadataConfiguration I clearly saw that the parameter is passed in the first parameter, which translates as the path to the folder with the entities . And not some kind of magic spell , which apparently should mean "guess which path is needed here and substitute it yourself."
$paths = array("/path/to/entity-files");
Unfortunately, programming spells don't work and you have to pass the existing path. In this case, to the folder that contains User.php, Admin.php, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question