我正在应用程序升级从symfony 3.4到4.4。
但是我有一个问题与查询选择,我不知道为什么结果总是空的:
return $this
->_em
->createQuery('SELECT u FROM AppEntityInternalUsers u')
->getResult();
Result: Array ( )
与getRepository一起使用:
$user = $this
->getDoctrine()
->getRepository(InternalUsers::class)
->validate($this->_getFilterParams(), $this->getParameter('ENCRYPTION_KEY'));
print_r($user);
Result: Array ( )
Validate function is inside InternalUserRepository
<?php
namespace AppRepository;
use CoreBundleDoctrineExtensionsPaginatePaginate;
use CoreBundleUtilsValidate;
use AppRepositoryBaseRepository;
use AppEntityInternalUsers;
use DoctrinePersistenceManagerRegistry;
use DoctrineBundleDoctrineBundleRepositoryServiceEntityRepository;
/**
* Internal Users
* Controls DB operations of internal users.
*/
class InternalUserRepository extends ServiceEntityRepository {
/**
*
* @var type
*/
protected $InternalUsers;
public function __construct(ManagerRegistry $registry) {
parent::__construct($registry, InternalUsers::class);
}
/**
* Validate credentias.
*
* @param array $userData User creteria.
* @param string $encryptionKey Entrypt key.
*
* @return type
*/
public function validate(array $userData, string $encryptionKey) {
$criteria = [
'username' => $userData['username'],
'password' => sha1($encryptionKey . $userData['password'])
];
$user = $this->findOneBy($criteria);
var_dump($user); // NULL
if ($user) {
return $user;
}
}
它正在使用我的命令行:
$ php bin/console doctrine:query:dql "SELECT cat FROM AppEntityInternalUsers cat"
array(0) {
}
我对手动调整的ORM有一个假设:
orm:
auto_generate_proxy_classes: '%kernel.debug%'
default_entity_manager: default
entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
# alias: App
# AppBundle:
# is_bundle: false
# type: annotation
# dir: '%kernel.project_dir%/src/AppBundle/Entity'
# prefix: 'AppBundleEntity'
# alias: AppBundle
AppEntity:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/'
prefix: 'AppEntity'
alias: AppEntity
但是我仍然没有得到结果,我已经在这个问题上工作了将近2天,在调查和阅读文档后没有答案。
我又试了一次,但同样没有结果。
orm:
auto_generate_proxy_classes: '%kernel.debug%'
default_entity_manager: default
entity_managers:
default:
auto_mapping: true
metadata_cache_driver:
type: 'service'
id: doctrine.cache.memcached
query_cache_driver:
type: 'service'
id: doctrine.cache.memcached
result_cache_driver:
type: 'service'
id: doctrine.cache.memcached
dql:
string_functions:
STRING_AGG: GalleryCoreCoreBundleDoctrineExtensionsDQLStringAgg
最新消息!
看起来与实体映射的类型有关。
配置完doctrine.orm.
orm:
auto_generate_proxy_classes: '%kernel.debug%'
#default_entity_manager: default
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
#entity_managers:
#default:
#metadata_cache_driver:
# type: 'service'
# id: doctrine.cache.memcached
#query_cache_driver:
# type: 'service'
# id: doctrine.cache.memcached
#dql:
# string_functions:
# STRING_AGG: GalleryCoreCoreBundleDoctrineExtensionsDQLStringAgg
#connection: default
#naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
# alias: App
# AppBundle:
# is_bundle: false
# type: annotation
# dir: '%kernel.project_dir%/src/AppBundle/Entity'
# prefix: 'AppBundleEntity'
# alias: AppBundle
#AppEntity:
#is_bundle: false
#type: annotation
#dir: '%kernel.project_dir%/src/Entity'
#prefix: 'AppEntity'
#alias: App
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/'
prefix: 'AppEntity'
alias: App
我运行了这个命令:
php bin/console doctrine:mapping:import "AppEntity" annotation --path=src/Entity
在我的src/Entity文件夹中正确生成实体输出:
$ php bin/console doctrine:mapping:import "AppEntity" annotation --path=src/Entity
Importing mapping information from "default" entity manager
> writing src/Entity/Bonsai.trackSites.php
> writing src/Entity/Gallery.adTagTypes.php
> writing src/Entity/Gallery.albumAssets.php
> writing src/Entity/Gallery.appUrls.php
> writing src/Entity/Gallery.adTags.php
> writing src/Entity/Bonsai.trackAssettypes.php
> writing src/Entity/Bonsai.trackViews.php
> writing src/Entity/Bonsai.trackVisitors.php
> writing src/Entity/Gallery.apps.php
> writing src/Entity/Gallery.adGptTags.php
> writing src/Entity/Gallery.appConfigurations.php
> writing src/Entity/Gallery.appFeatures.php
> writing src/Entity/Gallery.appUrlTypes.php
> writing src/Entity/Gallery.assetFlags.php
> writing src/Entity/Gallery.assetTypes.php
> writing src/Entity/Gallery.assetVotes.php
> writing src/Entity/Gallery.assets.php
> writing src/Entity/Gallery.assetsKeywords.php
> writing src/Entity/Gallery.exifValues.php
> writing src/Entity/Gallery.comments.php
> writing src/Entity/Gallery.exifFields.php
> writing src/Entity/Gallery.domains.php
> writing src/Entity/Gallery.countries.php
> writing src/Entity/Gallery.featuredAssetsData.php
> writing src/Entity/Gallery.fieldValues.php
> writing src/Entity/Gallery.jobsQueue.php
> writing src/Entity/Gallery.regions.php
> writing src/Entity/Gallery.indexJobs.php
> writing src/Entity/Gallery.keywords.php
> writing src/Entity/Gallery.externalValues.php
> writing src/Entity/Gallery.releaseDates.php
> writing src/Entity/Gallery.requestTypes.php
> writing src/Entity/Gallery.responseLogs.php
> writing src/Entity/Gallery.userRoles.php
> writing src/Entity/Gallery.trendingConfiguration.php
> writing src/Entity/Gallery.votesConfiguration.php
> writing src/Entity/Bonsai.trackAssets.php
> writing src/Entity/Gallery.internalUsers.php
> writing src/Entity/Gallery.commentFlags.php
> writing src/Entity/Gallery.verticals.php
> writing src/Entity/Gallery.fields.php
> writing src/Entity/Gallery.fieldTypes.php
> writing src/Entity/Gallery.imageTags.php
> writing src/Entity/Gallery.internalCategories.php
> writing src/Entity/Gallery.sitesConnections.php
> writing src/Entity/Gallery.threadAssets.php
> writing src/Entity/Gallery.trendingCriterias.php
> writing src/Entity/Gallery.trendingFormulaDetails.php
> writing src/Entity/Gallery.trendingFormulas.php
> writing src/Entity/Gallery.userSettings.php
> writing src/Entity/Gallery.userVariables.php
> writing src/Entity/AdGptTags.php
在做了一些调整后:
$user = $this
->getDoctrine()
->getRepository(InternalUsers::class)
->findOneBy(
$criteria = [
'username' => $this->_getFilterParams()['username'],
'password' => sha1($this->getParameter('ENCRYPTION_KEY') . $this->_getFilterParams()['password'])
]
);
// validate($this->_getFilterParams(), $this->getParameter('ENCRYPTION_KEY'));
var_dump($user->getUsername());
exit;
这是我的输出:
string(10) "superadmin"