草庐IT

symfony-console

全部标签

php - 为什么不应该在 Symfony 中使用绝对路径常量 __DIR__ 和 __FILE__

我使用SensioLabsInsight控制我的代码质量。对于一个简单的文件上传,我必须得到我的上传目录的绝对路径:protectedfunctiongetUploadRootDir(){//theabsolutedirectorypathwhereuploadedreturn__DIR__.'/../../../../web/'.$this->getUploadDir();}代码直接来自官方文档(HowtohandlefileuploadswithDoctrine)但如果分析的代码包含__DIR__或__FILE__PHP魔术常量,SLInsight会发出警告:__DIR__and_

php - 带有 Symfony 2 的 Twig 显示 prod 和 dev 之间不同的 json 编码变量

我们正在构建一个Symfony2应用程序,它将一些数据从Controller发送到View:Controller$user=array('configuration'=>array('levels'=>array('warning'=>0.05,'danger'=>0.10,),),);return$this->render('MyWebsiteBundle:Core:searchResults.html.twig',array('userJSON'=>json_encode($user)));查看user=$.parseJSON("{{userJSON}}");结果在dev上,结果如

php - Symfony2 命令 "doctrine:schema:update"未检测实体中使用的特征文件更改

我有一个特征文件,其中包含实体之间的共享代码。特征文件示例:status=$status;return$this;}publicfunctiongetStatus(){return$this->status;}publicfunctionsetDate($date){$this->date=$date;return$this;}publicfunctiongetDate(){return$this->date;}}实体文件示例:id;}publicfunctionsetGallery(\Application\Sonata\MediaBundle\Entity\Gallery$gall

php - 更改 Symfony2 中的默认语言环境

我正在尝试更改我的应用程序的默认语言环境。到目前为止我尝试过的事情:将intl.default_locale设置为“et_EE”在app/config/parameters.ini中将语言环境设置为“et”更改了我的包的boot()方法中的默认区域设置here实现了一个扩展StubLocale并覆盖方法getDefault()以返回“et_EE”的Locale类。这里是实现。Locale类似乎没有被覆盖,因为调用\Locale::getDefault()不执行此方法。在尝试了所有这些描述的方法之后,\Locale::getDefault()仍然返回en。我需要它返回et_EE以在适当的

php - 带有选择列表的 Symfony 2 表单

如何在Symfony2中使用数据库表中的值创建一个选择列表?我有2个实体:Student和Classroom具有ManyToOne关系,我需要创建一个包含以下字段的表单:name,姓氏、年龄、类(class)(从可用类(class)中选择列表)。在我的学生表格中我有$builder->add('name')->add('surname')->add('age')->add('classroom',newClassroomType());在我的类表格中我有这个:$classrooms=$this->getDoctrine()->getRepository('UdoCatalogBundl

php - Symfony2 assets 按文件版本控制

问题是否可以在Symfony2上使用assets_versionbyfile?背景我们正在使用assets_version和assets_version_format管理文件版本并强制对CDN和浏览器缓存进行缓存更新。这很有效!但是,我们发现所有使用的静态资源只有一个assets_version参数。这是一个问题,因为我们的web应用程序有大量静态资源,而且我们每天都在将更改部署到生产环境。这种情况会杀死缓存。:(这是我们当前的配置:config.ymlframework:templating:engines:['twig']assets_version:%assets_version

php - Symfony:不推荐使用 cascade_validation 选项

我正在尝试将我的项目从symfony2升级到symfony3。我想去掉这个弃用警告The"cascade_validation"optionisdeprecatedsinceversion2.8andwillberemovedin3.0.Use"constraints"withaValidconstraintinstead."下面是我的代码->add('student_name','collection',array('entry_type'=>TextType::class,'allow_add'=>true,'cascade_validation'=>true,'options'=

php - FOSRestBundle 在 Symfony 4.1 中不起作用

我在使用在Symfony4.1项目下工作的FOSRestBundle返回View时遇到问题。这是来self的Controller的代码:classNewsControllerextendsFOSRestController{publicfunctiongetNewsAction(){$data=['news1','news2'];$view=$this->view($data,200);return$this->handleView($view);}}fos_rest.yamlfos_rest:param_fetcher_listener:trueallowed_methods_lis

php - Symfony2 - Doctrine 和 FOSUserBundle - 错误的注释

总的来说,我是Symfony2的新手。不过,这个问题与Doctrine和FOSUserBundle相关。我有以下基于FOSUserBundle和自引用多对多创建的User.php实体。hasAccessTo=new\Doctrine\Common\Collections\ArrayCollection();$this->hasAccessToMe=new\Doctrine\Common\Collections\ArrayCollection();}}尝试更新缓存或删除时出现以下错误:[Doctrine\Common\Annotations\AnnotationException][Se

php - 使用 Symfony 的 EventDispatcher 组件的正确方法是什么?

我想通过使某些类可观察来促进我的PHP代码中的松散耦合。SymfonyEventDispatchercomponent看起来很有希望,SPL也是如此SplObserver/SplSubject对类。做到这一点的最佳方法是什么?我可以看到几种不同的可能性:(1)在每个可观察类中注入(inject)一个EventDispatcher实例(跟踪全局EventDispatcher实例):classFoo{publicfunction__construct($dispatcher){$this->dispatcher=$dispatcher;}publicfunctionbar(){$this-