我试图嵌入一个具有集合类型(一对一关系)的表单,但是我得到了错误:
在属性路径"patiPatientsSafeData“处给出的参数类型应为"App\Entity\PatientsSafeData”、"array“。
在实体患者中
<?php
namespace App\Entity;
use App\Repository\PatientsRepository;
use Doctrine\ORM\Mapping as ORM;
class Patients
{
private $id;
private $patiLabel;
这里的想法是向用户或其他实体添加一个文件(照片)。我决定这个文件可以有自己的实体媒体。
正如symfony书中所解释的,我在entity中创建了add文件函数:
<?php
namespace AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Media
*
* @ORM\Table(nam
如何在Symfony2中创建用于将实体转换为字符串的FormType?
我已经用做了所有这些事情,但是有一个错误:
Expected argument of type "string", "<Vendor>\<Bundle>\Entity\User" given
如何创建将文本字段转换为用户对象的表单?
我有一个名为DynamicForm的实体,它看起来如下:
<?php
namespace App\Entity\Product\DynamicForm;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Entity;
/**
* Class DynamicForm
* @package App\Entity\Product
*
* @Entity
* @ORM\Table(name="product_dynam
我的代码有问题。我有一个错误:
The property "users" in class "Wiki\AdminBundle\Entity\Post" can be defined with the methods "addUser()", "removeUser()" but the new value must be an array or an instance of \Traversable, "Wiki\AdminBundle\Entity\User" given.
我不明白我的代码怎么了。
这是我的
我已经创建了一个表单类型,它为实体添加了一个自动完成功能,但是它需要对每个实体进行一些配置,即:我必须将配置传递给options数组,所以我决定为每个实体创建一个新的FormType,使用我创建的AutoCompleteType并重用我想要的这些FormType,即:为每个特定实体创建的表单,在调用getData()时返回实体,现在发生的情况是,我必须首先检索包含AutoCompleteType的ParentForm字段,然后调用getData()检索Entity.How,我能直接在ParentForm上映射这些信息吗?
//the FormType of Some Entity using
当我将UserInterface添加到事件侦听器时,会出现以下错误:
Cannot autowire service "App\EventListener\ControllerListener": argument "$user" of method "__construct()" references interface "Symfony\Component\Security\Core\User\UserInterface" but no such service exists. It cannot be auto-regist
我试图弄清楚如何使用Symfony2表单动态地修改html属性。
在这种情况下,大多数时候都使用默认占位符,但有时开发人员需要编写自定义消息。
我的表单类型如下:
<?php
namespace My\AwesomeBundle\FormType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterfa
我有一个大(简单)问题。
我有一个具有地理位置属性的用户实体作为manyToOne关系
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
/**
* Use
我想知道如何恢复FormType (EntityType)中的当前用户?
目前,我只能检索已注册用户的列表,而不能检索当前(已连接)用户的列表。
我现在的FormType
<?php
namespace App\Form;
use App\Entity\User;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class OneNewCarType e
我正在尝试创建一个任务管理器,我需要能够获得当前登录的用户的用户id,以便在创建任务时,用户id也被输入到数据库中。我无法让它工作,它一直告诉我,call to undefined function getUser()我认为我没有必要定义它,我认为它是内置的。
有人能帮我解决这个问题吗?会很感激的!
下面是创建任务的函数
<?php
namespace Starnes\TaskBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Contr
我正在为我的Symfony3应用程序和FOSUserBundle开发一个简单的控制器,以更新用户的电子邮件地址。
$user = $this->getUser();
$user->setEmail($email);
在第二行返回此错误。
Error: Cannot use object of type AppBundle\Entity\User as array
考虑到我使用的是BaseUser类的一种方法,我显然没有使用对象作为数组,所以我不知道它为什么要抛出这个错误。
编辑:
控制器
/**
* @Route("/portfolio/settings", na
我正在尝试让Symfony的UniqueEntity验证器为我的信条实体工作。Symfony验证器已经连接并正常工作,但是Symfony\Bridge的UniqueEntity更具挑战性,显示以下错误:
PHP Fatal error: Class 'doctrine.orm.validator.unique' not found in /app/vendor/symfony/validator/Symfony/Component/Validator/ConstraintValidatorFactory.php on line 46
看起来好像ValidatorFactory
在我的情况下,实体类中的验证约束被忽略.
这个程序不工作(它是ActivityField实体的一个子实体):
<?php
namespace XXX\ActivityFieldsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use XXX\DatabaseBundle\Entity\AbstractEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="XXX\ActivityField
我正在编写一个控制器来处理基本的CRUD功能,我想知道,我是否做对了。
Symfony本身和有很多很好的功能--我想知道,在这种情况下,我是否正在重新发明轮子。我有大约20个将由CRUDController扩展的类,我希望尽早使用最佳实践。
提前感谢!
CRUDController.php
namespace myApp\MyBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\BrowserKit\Response;
use Symfony\Com
我创建了一个表单,以便当用户被选中时,他的角色从"ROLE_USER“变为"ROLE_ADMIN”。当表单提交时,我有以下错误:Can't get a way to read the property "user" in class "App\Entity\User".
我知道在User类中肯定没有这样的字段名为user,但我不知道可以用哪个字段替换用户。我已经尝试过name或,但这两种角色都不起作用。
我如何选择一个用户并简单地改变他的角色?
AdminType.php
<?php
namespace App\Form\Admi
我正在使用Symfony2,当我尝试附加FOSUserBundle时,我得到了一个错误(bin/console规则:模式:更新--强制)
//---------------------------------------------------------------Appkernel.php
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Symfony\Bundle\FrameworkBundl
我对我的存储库模式有问题,它今早起作用了,所以我不明白下面是我的代码:
IRepository:
public interface IRepository<T> where T : class
{
List<T> GetAll();
List<T> GetSome(int index, int pageSize);
T GetOne(int id);
T Add(T entity);
void Update(T entity);
void Delete(T entity);
}
IUse
<?php
declare(strict_types=1);
namespace App\Controller\User;
use App\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use
为了编辑用户配置文件,我做了以下FormType:
namespace AppUserBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
class UserProfileFormType extends
问题是表单是嵌入的,属性邮政编码在嵌入的表单中。
我用OneToOne关系在我的symfony项目中创建了两个实体。
用户实体:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEn
在symfony中,我被困在如何通过表单提交来更改密码上--而且我不知道如何解决它,因为它的行为似乎不同。
所以首先-我正在构建一个自定义表单,其中用户输入他们的旧密码,和一个新的两次。这是我的FormType:
UserPasswordType.php
<?php
namespace App\Form;
use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Compon
我有两个实体, have 和Theme。一个主题可以有多个格式,Theme可以属于多个主题。在添加格式内,我想显示一个主题的选择,这些主题看起来像下面的图像
我创建了一个名为SearchableEntityType的自定义FormType,但在后者中,我无法获得主题。当我dd($form->getdata())时,它是空的。我错过了什么?谢谢你的帮助。
以下是实体/Formation.php的代码
<?php
namespace App\Form;
use App\Entity\Formation;
use Symfony\Component\Form\AbstractT
我正在用Symfony做一个应用。我得到了相关的实体答案和问题。我想让用户添加问题的答案,但我在将question_id转到AnswerEntity时遇到了问题。这就是我想到的: Answer Controller <?php
/**
* Answer Controller
*/
namespace App\Controller;
use App\Entity\Answer;
use App\Entity\Question;
use App\Form\AnswerType;
use App\Repository\AnswerRepository;
use App\Reposit
例如,在我的模型中有两个简单的字符串属性:
public class Model
{
public string BaseString {get;set;}
public string MyValue {get;set;}
}
在我的OnModelCreating中:
modelBuilder
.Entity<Model>()
.Property(f => f.MyValue)
.ValueGeneratedOnAdd()
.HasDefaultValueSQL(//insert first letter of inserted BaseString prop
如何使用symfony使用PHPUnit测试服务?到目前为止,我安装并包括了测试包,DAMA理论包,并创建了测试数据库.
在.env.test内部,我添加了数据库连接
# define your env variables for the test env here
KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/err