...或者我必须如下消毒它们吗?
class RelationshipController extends Controller
{
...
public function deleteAction($objectId)
{
$objectId = filter_var($objectId, FILTER_SANITIZE_NUMBER_INT)
...
Run Code Online (Sandbox Code Playgroud) 我的symfony项目中有3个实体管理器,我想将新表添加到特定的实体管理器.我知道我可以通过使用以下命令传递--em ="EntityManager1"从命令行执行此操作:
php app/console doctrine:migration:migrate --em="EntityManager1"
Run Code Online (Sandbox Code Playgroud)
但我想在代码本身中这样做.
例:
public function up(Schema $schema)
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");?
$this->addSql("CREATE TABLE `myTable` (
`id` int(11) NOT NULL,
`name` varchar(45) DEFAULT NULL,
`email` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1?");
}
public function down(Schema $schema)
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
$this->addSql("DROP TABLE myTable");?
}
Run Code Online (Sandbox Code Playgroud)
提前致谢
我在phpspec中仍然很新鲜,但通常我会在遇到困难时找到解决方案,但这个很难.
我尝试了很多不同的方法,但我还没有找到解决方案.我正在使用Symfony2.
我有一个我想测试的课程:
class MyClass
{
public function getDataForChildren(MyObject $object)
{
foreach ($object->getChildren() as $child) {
$query = \json_decode($child->getJsonQuery(), true);
$data = $this->someFetcher->getData($query);
$child->setData($data);
}
return $object;
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我的spec类:
class MyClassSpec
{
function let(SomeFetcher $someFetcher)
{
$this->beConstructedWith($someFetcher);
}
function it_is_initializable()
{
$this->shouldHaveType('MyClass');
}
function it_should_get_data_for_children_and_return_object(
MyClass $object,
MyClass $child, // it means that MyClass has a self-reference to MyClass
$someFetcher
)
{
$query = '{"id":1}';
$returnCollection = new ArrayCollection(array($child));
$object->getChildren()->shouldBeCalled()->willReturn($returnCollection);
$child->getJsonQuery()->shouldBeCalled()->willReturn($query);
$someFetcher->getData($query)->shouldBeCalled();
$this->getDataForChildren($object);
}
}
Run Code Online (Sandbox Code Playgroud)
运行phpspec后,我收到此错误:
warning: json_decode() expects …Run Code Online (Sandbox Code Playgroud) 我试图在Symfony 2.4中的事件监听器中获取用户ID,但据我所知,EventListener未被控制器调用,因此我无法使用
$这 - >的getUser();
获得身份证的最佳方式是什么?
我想过在调用事件的services.yml中给它.
感谢anyhelp或任何有用的文档.
问候,
我正在尝试建立一个表格来回答一个小调查.
在使用我的表单加载页面时,我收到此错误:
表单的视图数据应该是标量,数组或\ ArrayAccess的实例,但是类VS\myproject\UserBundle\Entity\User的实例.您可以通过将"data_class"选项设置为"VS\myproject\UserBundle\Entity\User"或添加视图转换器来将类VS\myproject\UserBundle\Entity\User的实例转换为标量,数组或\ ArrayAccess的一个实例.
我无法在第一时间看到我将使用User实体的位置,并且很难从这个错误消息中做出一些事情.有人可以帮忙吗?
in <myprojectdirectorypath>\vendor\symfony\symfony\src\Symfony\Component\Form\Form.php at line 353 +
at Form ->setData (object(User))
in <myprojectdirectorypath>\vendor\symfony\symfony\src\Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper.php at line 57 +
at PropertyPathMapper ->mapDataToForms (object(CustomerSurvey), object(RecursiveIteratorIterator))
in <myprojectdirectorypath>\vendor\symfony\symfony\src\Symfony\Component\Form\Form.php at line 385 +
at Form ->setData (object(CustomerSurvey))
in <myprojectdirectorypath>\vendor\symfony\symfony\src\Symfony\Component\Form\Form.php at line 477 +
at Form ->initialize ()
in <myprojectdirectorypath>\vendor\symfony\symfony\src\Symfony\Component\Form\FormBuilder.php at line 230 +
at FormBuilder ->getForm ()
in <myprojectdirectorypath>\vendor\symfony\symfony\src\Symfony\Component\Form\FormFactory.php at line 39 +
at FormFactory ->create (object(CustomerSurveyType), object(CustomerSurvey), array())
in <myprojectdirectorypath>\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Controller\Controller.php at line 181 +
at Controller ->createForm …Run Code Online (Sandbox Code Playgroud) 我在树枝上有这个链接:
<a href="{{ path('relation-delete', {'id': c.getCustomerId}) }}"
onclick="return confirm('{% trans %}relation.delete{% endtrans %}');"
class="tip" data-original-title="Verwijder klant {{ c.getCustomerName }}">
Run Code Online (Sandbox Code Playgroud)
源代码中的HTML:
<a href="/app_dev.php/projects/delete/1" class="tip"
data-original-title="Verwijder project Lantaarn plaatsen"
onclick="return confirm('Verwijderen');">
<button class="btn btn-danger"><i class="fa fa-times fa-fw"></i></button></a>`
Run Code Online (Sandbox Code Playgroud)
onlick确认取消按钮不会取消操作,而是继续执行。有人知道此退货确认有什么问题吗?
我已将我的操作系统从12.04更新到ubuntu 14.04,当我尝试重新加载我的Symfony2项目时,我收到此错误:
You don't have permission to access /app_dev.php/ on this server.
Run Code Online (Sandbox Code Playgroud)
这是我的apache2文件:
<VirtualHost *:80>
ServerName s**a
ServerAlias d**n
# Indexes + Directory Root.
DirectoryIndex index.html index.php
DocumentRoot /home/****/
<Directory />
Options -Indexes +FollowSymLinks
Require all granted
</Directory>
<DirectoryMatch .*\.svn/.*>
Deny From All
</DirectoryMatch>
# Logfiles
</VirtualHost>
PS : it works well before the update !
Run Code Online (Sandbox Code Playgroud) 添加"实体"类型的表单字段时,我有SF2的这个问题.这是我的情况:
此NetworkFormType包含Country字段,因此在我的NetworkFormType.php中:
$builder->add('country', 'entity', [
'label' => $translator->trans('global.labels.country'),
'data_class' => 'MyBundle\Entity\Country',
'property' => 'name',
'choices' => $countries
])
Run Code Online (Sandbox Code Playgroud)我还在我的网络实体中宣布了公共制定者和吸气者.顺便说一句,我将我的表单注册为服务:
mybundle.form.network:
class: MyBundle\Form\NetworkFormType
tags:
- { name: form.type, alias: mybundle_form_network }
Run Code Online (Sandbox Code Playgroud)
但它总是导致:
Could not load type "entity"
Run Code Online (Sandbox Code Playgroud)
参考:实体字段类型
有人有个主意吗?
有没有办法将service.yml中的实际设置更改为Service.xml?当我创建捆绑包时,我将yml定义为标准形式,现在我需要切换到xml,因为那里存在现有服务.我希望在不改变它们的情况下使用的xml文件(我认为这也可行).
我在我的Controller中有这个方法,多次调用indexAction().我应该保持它原样,还是应该为它和其他可重用方法创建Helper类(服务),因为我可以避免传递诸如此类$em情况的参数?我无法理解服务的背景以及何时使用它们很舒服.
public function getProfile($em, $username, $password) {
$dql = $em->createQuery('SELECT Profiles FROM ProjectProjectBundle:Profiles AS Profiles WHERE Profiles.email = :email AND Profiles.password = :password')
->setParameters(array(
'email' => $username,
'password' => $password
));
return $dql->getArrayResult();
}
Run Code Online (Sandbox Code Playgroud)