在我的项目 symfony 4 中,我想对 Composer 进行更新,这是他所做的。
但是因为,当我在构造函数中使用 ObjectManager 时,它会在我的所有控制器上显示一个错误,如下所示:
use Doctrine\Common\Persistence\ObjectManager;
/**
* Manager
*
* @var ObjectManager
*/
private $manager;
public function __construct(ObjectManager $manager)
{
$this->manager = $manager;
}
Run Code Online (Sandbox Code Playgroud)
我有这种错误:
无法自动装配服务“App\Controller\OrdreMissionController”:方法“__construct()”的参数“$manager”引用接口“Doctrine\Common\Persistence\ObjectManager”,但不存在这样的服务。您可能应该将此接口别名为现有的“doctrine.orm.default_entity_manager”服务。
它适用于我所有的控制器,因为它们都有 ObjectManager,我不明白发生了什么
我正在尝试登录 API。我按照教程进行操作,然后,我必须运行以下命令:
\nexport ID1=`curl -k --tlsv1.2 -b cookie.txt -c cookie.txt -v \'https://api-gateway.inpi.fr/auth/login\' -H \'Accept: application/json, text/plain, */*\' -H "X-XSRF-TOKEN: $TOKEN" -H \'Content-Type: application/json\' -H \'Connection: keep-alive\' -H "Cookie: XSRF-TOKEN= $TOKEN" --data \'{"username":"[email address]","password":"[account password]","rememberMe":true}\'`\nRun Code Online (Sandbox Code Playgroud)\n但它返回:
\n 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 81.252.220.43:443...\n* Connected to api-gateway.inpi.fr (81.252.220.43) port 443 (#0)\n* ALPN, offering h2\n* ALPN, offering http/1.1\n} [5 bytes data]\n* TLSv1.3 (OUT), TLS handshake, Client hello (1):\n} [512 bytes data]\n* TLSv1.3 (IN), …Run Code Online (Sandbox Code Playgroud) 我遇到了一个给我这个错误的问题:
序列化类“App\Entity\User”的对象时检测到循环引用(配置限制:1)
我有一个企业实体,其中包含任务订单、车辆和用户。
与用户、公司和车辆有关系的订单实体。
和一个与订单和公司有关系的用户实体。
所以我有这个: Entreprise.php
class Entreprise
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity="App\Entity\User", mappedBy="entreprise", orphanRemoval=true)
*/
private $users;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Vehicule", mappedBy="entreprise", orphanRemoval=true)
*/
private $vehicules;
/**
* @ORM\OneToMany(targetEntity="App\Entity\OrdreMission", mappedBy="entreprise", orphanRemoval=true)
*/
private $ordreMissions;
Run Code Online (Sandbox Code Playgroud)
OrdreMission.php:
class OrdreMission
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* Agent qui réalisera la mission
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="ordreMissions")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* Immatriculation de la voiture de …Run Code Online (Sandbox Code Playgroud) 在我的 CRUD 控制器中,我有一个 CollectionField,它有一个引用 formType 的 entryType 选项
\nyield CollectionField::new(\'drinks\', \'Boissons\')\n ->setFormTypeOption(\'by_reference\', false)\n ->setEntryType(CommandProductItemType::class);\nRun Code Online (Sandbox Code Playgroud)\n命令产品项目类型
\n public function buildForm(FormBuilderInterface $builder, array $options)\n {\n\n $builder\n ->add(\'product\', EntityType::class, [\n \'label\' => \'Produit\',\n \'class\' => Product::class,\n \'choice_label\' => \'namePrice\',\n ])\n ->add(\'quantity\', IntegerType::class, [\n \'label\' => \'Quantit\xc3\xa9\',\n \'attr\' => [\n \'min\' => 1\n ]\n ])\n ;\n }\n\n public function configureOptions(OptionsResolver $resolver)\n {\n $resolver->setDefaults([\n \'data_class\' => CommandProductItem::class,\n \'category\' => Category::class\n ]);\n }\nRun Code Online (Sandbox Code Playgroud)\n如何将类别选项从CollectionField项传递到CommandProductItemType?
\n我正在尝试在我的 Symfony 5 应用程序中使用 Panther 进行 PhpUnit 测试。
当我尝试登录用户时,如下所示:
$client = static::createPantherClient();
/** @var User $user */
$user = $this->getSuperAdminAccount();
$session = self::$container->get('session');
$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
$session->set('_security_main', serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$client->getCookieJar()->set($cookie);
Run Code Online (Sandbox Code Playgroud)
当我运行测试时,我得到:
Panther Facebook\WebDriver\Exception\InvalidCookieDomainException :无效的 cookie 域
有人能帮助我吗 ?
我已经实现了全新的 Symfony 身份验证系统:https : //symfony.com/doc/current/security/experimental_authenticators.html
我添加了新的登录限制:https : //symfony.com/blog/new-in-symfony-5-2-login-throttling
一切都已正确配置。
我还安装了 RateLimiter 组件,它创建了一个环境变量:
LOCK_DSN=semaphore
Run Code Online (Sandbox Code Playgroud)
但我有一个问题。首先,登录限制似乎被忽略了一半。一旦超出限制,我就没有错误消息。另一方面,如果我尝试使用良好的凭据进行连接,则会出现以下错误:
需要信号量扩展 (sysvsem)。
我尝试安装信号量组件(https://symfony.com/doc/current/components/semaphore.html)
但同样的问题。
这是我的security.yaml
LOCK_DSN=semaphore
Run Code Online (Sandbox Code Playgroud)
我搜索了是否有要添加到 PHP 的扩展,但找不到任何内容。所以我不知道该怎么办。我在 Windows 10 上
在我的 Symfony 应用程序中,我有一个User序列化的实体。在该unserialize()方法中,我这样做了:
public function unserialize($serialized)
{
[
$this->id,
$this->email,
$this->password,
$this->enabled
] = unserialize($serialized);
}
Run Code Online (Sandbox Code Playgroud)
但 PhpStorm 用红色下划线unserialize($serialized)显示以下消息:
请在第二个参数中指定允许反序列化的类。
我不知道应该用什么作为第二个参数。经过一番研究,我发现我们可以这样写:
unserialize($serializeObj, ["allowed_classes" => true]);
Run Code Online (Sandbox Code Playgroud)
但我也发现了这一点:
unserialize($serializeObj, ["allowed_classes" => true]);
Run Code Online (Sandbox Code Playgroud)
我有点困惑,我不知道我应该在我的案例中放入什么,这样 PhpStorm 就不会抱怨这一点。
我有点失落。我参与了一个项目,该项目与 github 相结合。但我让项目不断发展,因此我在 github 上创建了一个我希望使用的新存储库(同时将旧存储库与旧文件放在一边)。
因此,在我的项目中,我想确保它不再与旧存储库耦合,并且我可以从新存储库正常工作。
我点击了一些链接,所以我这样做了:
git remote rm origingit remote add origin [newGithubURL]git init, git add .,git commit -m "first commit"git push origin master但我有这个错误:
我尝试在我的 Symfony 4 项目中将 FosJsRouting 与 Webpack-encore 一起使用。
我做了:
1.
composer require friendsofsymfony/jsrouting-bundle
Run Code Online (Sandbox Code Playgroud)
2.
php bin/console assets:install --symlink public
Run Code Online (Sandbox Code Playgroud)
3.
php bin/console fos:js-routing:dump --format=json --target=public/js/fos_js_routes.json
Run Code Online (Sandbox Code Playgroud)
在我的app.js中:
// FosJsRouting
const routes = require('../../public/js/fos_js_routes.json');
import Routing from '../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js';
Routing.setRoutingData(routes);
Run Code Online (Sandbox Code Playgroud)
现在,如果在app.js中执行 a,console.log(Routing);我会在控制台中获取该对象。
另一方面,不可能在我的模板中使用它。
我有以下错误:
未捕获的引用错误:未定义路由
我不明白,因为我的其他包工作得很好,但路由不行
我不明白,我在 Symfony 3 下工作,当我想转到我的用户管理页面时,我刚刚收到错误:
注意:unserialize():28 字节偏移量 11 处出错
Symfony\Component\Debug\Exception\ ContextErrorException
in vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/ArrayType.php (line 58)
Run Code Online (Sandbox Code Playgroud)
然而,在效果很好之前,却很奇怪。其他几个人已经遇到了同样的问题,但原因绝非相同。
我记得在项目的无用文件中做了一些空处理,但我删除了未使用的文件以及我未使用的注释块。
如果它有助于解决我的问题,这是我的 user.php
谢谢 !
编辑:好吧,我只是很愚蠢。我的 User 实体继承自 FOSUserBundle。在我的数据库中,我有一个具有 SUPER_ADMIN 角色的用户。与此同时,Suaf 在我的代码中删除了这个角色,只留下 ADMIN 角色,并且我在数据库中修改了自己,删除了太多的“SUPER”。如果有人能向我解释为什么,对于我的文化来说,我不认为它会产生这种错误。
但无论如何问题还是解决了!
我有一个包含 collectionType 的 formBuilder。我希望能够对电子邮件字段施加限制,以确保当用户验证时,表单中不会多次出现相同的电子邮件地址
我有 :
RegistrationCollectionType.php
$builder
->add('utilisateurs', CollectionType::class, [
'entry_type' => RegistrationType::class,
'entry_options' => [
'label' => false,
'entreprise' => $entreprise,
],
'allow_add' => true,
'allow_delete' => true,
'delete_empty' => true,
'by_reference' => true,
'prototype' => true,
'label' => false,
'attr' => [
'class' => 'my-selector',
'label' => false,
],
'by_reference' => false,
])
;
Run Code Online (Sandbox Code Playgroud)
与他的班级:
注册集合.php
class RegistrationCollection
{
private $utilisateurs = [];
public function getUtilisateurs(): ?array
{
return $this->utilisateurs;
}
public function setUtilisateurs(?array $utilisateurs): self
{ …Run Code Online (Sandbox Code Playgroud) 我有一个实现UserInterface的UserCas实体。
我的用户具有以下角色:
但是,当我根据角色限制对某些页面的访问时,它不起作用。
因此,在控制器中,我与具有ROLE_ADMIN的用户进行了检查:
$user = $this->getUser();
if($this->container->get('security.authorization_checker')->isGranted('ROLE_ADMIN'))
{
dump("yes");
}
else
{
dump("no");
}
Run Code Online (Sandbox Code Playgroud)
并且转储返回“否”。
如果我转储$ user-getRoles(),我将:
那么,请问是什么问题?
我的UserCas实体:
<?php
namespace Site\PagesBundle\Entity;
use Serializable;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Site\PagesBundle\Security\Traits\traitUser;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Site\PagesBundle\Entity\PaquetDDLCas;
/**
* UserCas
*
* @ORM\Table(name="user_cas")
* @ORM\Entity(repositoryClass="Site\PagesBundle\Repository\UserCasRepository")
* @UniqueEntity("mail")
*/
class UserCas implements \Serializable, UserInterface
{
use traitUser;
// Some attributes and methods
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* …Run Code Online (Sandbox Code Playgroud) symfony ×10
php ×6
collections ×2
bash ×1
button ×1
components ×1
composer-php ×1
constraints ×1
cookies ×1
curl ×1
defined ×1
depth ×1
easyadmin ×1
forms ×1
fullcalendar ×1
git ×1
git-push ×1
header ×1
mobile ×1
object ×1
php-7.3 ×1
phpunit ×1
reference ×1
responsive ×1
roles ×1
routes ×1
service ×1
tls1.2 ×1
unique ×1
validation ×1