当我在我的控制器动作中创建一个表单时,如下所示:
$form = $this->createFormBuilder()
->add('field_name')
->getForm();
return array(
'form' => $form
);
Run Code Online (Sandbox Code Playgroud)
...我尝试在这样的树枝模板中渲染此表单:
<form action="{{ path('...') }}" method="post">
{{ form_widget(form.field_name) }}
</form>
Run Code Online (Sandbox Code Playgroud)
... form_widget
调用产生以下异常/错误:
在渲染模板期间抛出异常("Catchable Fatal Error:传递给Symfony\Component\Form\FormRenderer :: searchAndRenderBlock()的参数1必须是Symfony\Component\Form\FormView的实例,Symfony的实例\给出的Component\Form\Form,在...中调用
我该如何解决这个问题?
我试着将symfony移动到共享主机.
我将symfony结构移动到/,我的web文件夹是/ public_html.
警告:要求(/家/用户/应用/缓存/生产/教义/ ORM /代理/ __ CG__UserBundleEntityUser.php):未能打开流:在/ home /用户/供应商/教义/ common/lib下没有这样的文件或目录/第209行的Doctrine/Common/Proxy/AbstractProxyFactory.php
警告:要求(/家/用户/应用/缓存/生产/教义/ ORM /代理/ __ CG__UserBundleEntityUser.php):未能打开流:在/ home /用户/供应商/教义/ common/lib下没有这样的文件或目录/第209行的Doctrine/Common/Proxy/AbstractProxyFactory.php
致命错误:需要():失败开口所需 '/home/user/app/cache/prod/doctrine/orm/Proxies/__CG__UserBundleEntityUser.php'(include_path中= ':/选择/ php55/LIB/PHP')中/第209行的home/user/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php
此错误仅在prod
环境中发生.dev
环境中不会抛出异常.
我尝试了以下方法:
rm -rf /app/cache + chmod 777
app/console cache:warmup
Run Code Online (Sandbox Code Playgroud)
我使用Symfony 2.8.3.以下目录存在于本地和服务器上:
LOCAL CACHE: - /annotations,/ twig,/ vich_uploader +/doctrine,/ translations
SERVER CACHE: - /annotations,/ twig,/ vich_uploader
如果我将本地缓存上传到服务器,则异常消失.
随着代码:
$qb = $entityManager->createQueryBuilder();
$qb->select('cat')->from('BuyAndSellSiteBundle:Category ', 'cat');
$qb->getQuery();
$a =$qb->getResult();
Run Code Online (Sandbox Code Playgroud)
我得到一个例外:
FatalErrorException: Error: Call to undefined method Doctrine\ORM\QueryBuilder::getResult() in C:\xampp\htdocs\buySell\src\BuyAndSell\SiteBundle\Controller\DefaultController.php line
Run Code Online (Sandbox Code Playgroud) 我在symfony2(doctrine)中使用以下代码作为我的多对多关系
实体:
/**
* @ORM\ManyToMany(targetEntity="BizTV\ContainerManagementBundle\Entity\Container", inversedBy="videosToSync")
* @ORM\JoinTable(name="syncSchema")
*/
private $syncSchema;
public function __construct()
{
$this->syncSchema = new \Doctrine\Common\Collections\ArrayCollection();
}
public function addSyncSchema(\BizTV\ContainerManagementBundle\Entity\Container $syncSchema)
{
$this->syncSchema[] = $syncSchema;
}
Run Code Online (Sandbox Code Playgroud)
控制器:
$entity->addSyncSchema($container);
$em->flush();
Run Code Online (Sandbox Code Playgroud)
现在,我该如何使用它来删除关系?我是否需要向我的实体添加方法,如removeSyncSchema()?那会是什么样的?
当我跑...
composer install
Run Code Online (Sandbox Code Playgroud)
...在安装了 PHP 和 nginx 的服务器上。
我收到以下异常:
[ErrorException]
"continue" 目标切换相当于"break"。您的意思是使用“继续 2”吗?
我怎样才能解决这个问题?
我是Symfony的新手.我创建了一个自定义命令,其唯一目的是从系统中擦除演示数据,但我不知道如何执行此操作.
在控制器中我会这样做:
$nodes = $this->getDoctrine()
->getRepository('MyFreelancerPortfolioBundle:TreeNode')
->findAll();
$em = $this->getDoctrine()->getManager();
foreach($nodes as $node)
{
$em->remove($node);
}
$em->flush();
Run Code Online (Sandbox Code Playgroud)
从我得到的命令中的execute()函数执行此操作:
Call to undefined method ..... ::getDoctrine();
Run Code Online (Sandbox Code Playgroud)
我如何从execute()函数执行此操作?此外,如果有一种更简单的方法来擦除数据,而不是循环它们并删除它们,请随意提及.
1.)情况(简化)
我有两个实体:一个Container-entity,它只有一个Content-entity.content_id存储在Container-entity中.
2.)软删除内容实体
我实现了一个软删除内容实体的功能,所以我在Content-entity中添加了一个"已删除"的属性.一切正常.
3.)问题
现在,当我想创建一个新的Container实体时,自动生成的选项显示所有内容实体 - 甚至是那些我"标记为已删除"的实体(delete-attribute = 1).
4.)问题
添加"过滤器"/"查询"的正确位置在哪里才能显示未标记为已删除的元素?(删除!= 1)
5.)我尝试过的
a.)view/twig方法:我尝试修改{{form_widget(form.contentId)}}的呈现但没有成功
b.)控制器方法:我试图在创建表单的newAction中操作表单数据($ form = $ this-> createCreateForm($ entity))但没有成功
c.)type/buildForm方法:我试图改变buildForm() - 方法......再次,没有成功
如果你能给我一个提示和/或一个简短的代码示例,我可以在哪里勾选到删除软删除选项的动作.
非常感谢你提前!
如果存在登录错误,我想自定义错误消息("错误凭据").我这样做却无效.这是模板登录:
{% if error %}
<div>{{ error.message|trans }}</div>
{% endif %}<form action="{{ path('login_check') }}" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="_username" value="{{ last_username }}" />
<label for="password">Password:</label>
<input type="password" id="password" name="_password" />
<input type="hidden" name="_target_path" value="/account" />
<input type="submit" name="login" />
Run Code Online (Sandbox Code Playgroud)
文件config.yml我有这个:
framework:
#esi: ~
translator: { fallback: "%locale%" }
Run Code Online (Sandbox Code Playgroud)
在parametre.yml我有这个:
locale: en
Run Code Online (Sandbox Code Playgroud)
我在MyBundle/Resources/translations/messages.en.ymy目录中添加了该文件:
security:
login:
username: "Username:"
password: "Password:"
submit: Login
forgot_username: "Forgot username"
forgot_password: "Forgot password"
registration: register
# Security
"Bad credentials": "Your user name or password are …
Run Code Online (Sandbox Code Playgroud) 我的symfony 2.4环境中存在大量问题,在我的翻译中使用换行符
我试过两个:
#messages.de.yml
foo: |
Hello i am a line
Hello i am a new line
Run Code Online (Sandbox Code Playgroud)
和
#messages.de.yml
foo: >
Hello i am a line
Hello i am a new line
Run Code Online (Sandbox Code Playgroud)
枝条
#template.html.twig
{{ 'foo'|trans }}
Run Code Online (Sandbox Code Playgroud)
翻译工作但换行没有.
也许我错了,但我想我完全按照文件说的做了.
我正在使用User实体内部的回调进行自定义验证.
因此,我需要获取当前登录用户的User对象.
在控制器中,我可以这样做:
$user= $this->get('security.context')->getToken()->getUser();
Run Code Online (Sandbox Code Playgroud)
但是我应该如何在User实体中执行此操作?
symfony ×9
php ×5
doctrine ×4
doctrine-orm ×3
twig ×2
command ×1
composer-php ×1
console ×1
database ×1
forms ×1
laravel ×1
php-7.2 ×1
symfony-2.4 ×1
validation ×1
yaml ×1