public function behaviors(): array
{
return ArrayHelper::merge(parent::behaviors(), [
[
'class' => SluggableBehavior::class,
'attribute' => 'title_en',
'ensureUnique' => true,
'skipUpdateOnClean' => false, // false также попробовал
]
]);
}
<?php
// bootstrap.php
//use Doctrine\Common\ClassLoader;
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
require_once "vendor/autoload.php";
require_once "vendor/doctrine/common/lib/Doctrine/Common/ClassLoader.php";
//$classLoader = new ClassLoader('');
// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = true;
$proxyDir = null;
$cache = null;
$useSimpleAnnotationReader = false;
$config = Setup::createAnnotationMetadataConfiguration(
array("src/Entity/"),
$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(
.......
);
// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\Table(name="users")
*/
class User
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
private int $id;
/**
* @ORM\Column(type="string", length=40)
*/
private $name;
/**
* @ORM\Column(type="string", name="last_name", length=40)
*/
private string $lastName;
/**
* @ORM\Column(type="string", length=40, unique=true)
*/
private $email;
/**
* @ORM\Column(type="string", name="mobile_number", length=50)
*/
private string $mobileNumber;
/**
* @ORM\Column(type="string", length=100)
*/
private string $password;
/**
* @ORM\Column(type="datetime", name="date_time", length=20)
*/
private string $dateTime;
public function getName(): string
{
return $this->name;
}
public function setName(string $name): void
{
$this->name = $name;
}
public function getLastName(): string
{
return $this->lastName;
}
public function setLastName(string $lastName): void
{
$this->lastName = $lastName;
}
public function getEmail()
{
return $this->email;
}
public function setEmail(string $email): void
{
$this->email = $email;
}
public function getMobileNumber(): string
{
return $this->mobileNumber;
}
public function setMobileNumber(string $mobileNumber): void
{
$this->mobileNumber = $mobileNumber;
}
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): void
{
$this->password = $password;
}
public function getDateTime(): string
{
return $this->dateTime;
}
public function setDateTime(string $dateTime): void
{
$this->dateTime = $dateTime;
}
}
<?php
namespace App\Repository;
use Doctrine\ORM\EntityRepository;
use App\Entity\User;
class UserRepository extends EntityRepository
{
public function getUserData(): array
{
$user = new User();
return $this->_em->getRepository(User::class)->findOneBy($user->getEmail());
}
}
<?php
namespace App\Helpers;
use App\Components\Employee;
use App\Entity\User;
class DataHelper
{
public function getCurrentUserData(string $email): array
{
$user = $entityManager....
return $user;
}