我正在尝试进行分页,但是有一个错误:
[语法错误]第0行,第57行:错误:字符串的预期结束,得到'限制'
我不太确定这是否是正确的语法(和逻辑)来进行查询:
public function getFriendsFromTo ($user, $limit, $offset)
{
return $this->getEntityManager()
->createQuery('SELECT f FROM EMMyFriendsBundle:Friend f WHERE f.user='.$user.' limit '.$limit. 'offset' .$offset)
->getResult();
}
Run Code Online (Sandbox Code Playgroud)
朋友和用户是相关的很多ToOne和oneToMany,所以在friends表中有一个字段 - user_id.
这是在我的控制器中:
$user = $this->get('security.context')->getToken()->getUser();
$id = $user->getId();
$friends = $user->getFriends();
$result = count($friends)
$FR_PER_PAGE = 7;
$pages = $result/$FR_PER_PAGE;
$em = $this->getDoctrine()->getEntityManager();
$friends = $em->getRepository('EMMyFriendsBundle:Friend')
->getFriendsFromTo($id, $FR_PER_PAGE, $page*$FR_PER_PAGE);
Run Code Online (Sandbox Code Playgroud)
我知道它是愚蠢甚至错误的(特别是第三个参数$page*$FR_PER_PAGE),但我只想尝试查询是否有效,但事实并非如此.
我有一个类别包含这个:
/**
* @ORM\OneToMany(targetEntity="Friend", mappedBy="category")
* @ORM\OrderBy({"name" = "ASC"})
*/
protected $friends;
Run Code Online (Sandbox Code Playgroud)
和一个朋友这个:
/**
* @ORM\ManyToOne(targetEntity="Category", inversedBy="friends")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $category;
Run Code Online (Sandbox Code Playgroud)
我想要的是能够删除类别,无论是否有这个类别的朋友,如果有 - 这个朋友的类别字段被设置为NULL.
我尝试onDelete="CASCADE"使用ManyToOne注释,然后到OneToMany,我尝试了上面显示的内容,我尝试cascade={"remove"}在OneToMany注释中使用,没有任何效果!我也找不到一个例子.请你帮助我好吗?
我有这个方法:
public function getMonth ($month_name)
{
$q = $this->createQueryBuilder('m');
$q->select('m')
->where('m.name = :name')
->setParameter('name', $month_name);
return $q->getQuery()->getResult();
}
Run Code Online (Sandbox Code Playgroud)
从中我希望找到一个月或0个月.我在控制器中以这种方式使用此方法:
$month = $em->getRepository('EMExpensesBundle:Month')
->getMonth($this->findMonth());
$month->setSpended($item->getPrice());
Run Code Online (Sandbox Code Playgroud)
我尝试了这getSingleResult()一切,一切都很完美,直到我遇到一个没有找到月份的情况,一切都失败了!
然后我尝试了getResult(),但它返回一个数组,然后
$month->setSpended($item->getPrice());
Run Code Online (Sandbox Code Playgroud)
据说被称为非对象并修复它我应该到处使用
$month[0]->setSpended($item->getPrice());
Run Code Online (Sandbox Code Playgroud)
是否有更优雅的方法来实现这一点,而无需在任何地方添加不必要的[0]索引?
我很难理解为什么我们得到这段代码的输出:
<?php
class Bar
{
public function test() {
$this->testPrivate();
$this->testPublic();
}
public function testPublic() {
echo "Bar::testPublic\n";
}
private function testPrivate() {
echo "Bar::testPrivate\n";
}
}
class Foo extends Bar
{
public function testPublic() {
echo "Foo::testPublic\n";
}
private function testPrivate() {
echo "Foo::testPrivate\n";
}
}
$myFoo = new foo();
$myFoo->test();
?>
Run Code Online (Sandbox Code Playgroud)
所以Foo扩展了Bar.$ myfoo是Foo类的一个对象.Foo没有一个叫做test()的方法,所以它从它的父Bar扩展它.但是为什么test()的结果是
Bar::testPrivate
Foo::testPublic
Run Code Online (Sandbox Code Playgroud)
你能解释一下为什么第一个不是Foo :: testPrivate,当这个父方法在孩子中被覆盖时?
非常感谢你提前!
我怎样才能比较Twig中的两个日期,第一个来自dababase,第二个是明确的 - 2012-12-31?我试过了
{% if dom.dueDate|date('Y-m-d') > 2012-12-31 %}
Run Code Online (Sandbox Code Playgroud)
但我没有得到我想要的结果.:(
我有一个DateTime字段但我在Twig中找不到DateTime的过滤器,当我使用|date('Y-m-d')它时只打印没有小时的日期:(
如果有人帮助我解决问题,我会非常高兴和感激!
我有一个包含Products的表和另一个包含Notes的表.每种产品都可以有或没有一些注释.我只需要注意知道他们所提到的产品,但产品不知道它的注释.我认为这应该是我的代码:
namespace EM\MyBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use EM\MyBundle\Entity\Productss;
/**
* @ORM\Entity
* @ORM\Table(name="notes")
*/
class Notess
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @OneToOne(targetEntity="Productss")
* @JoinColumn(name="products_id", referencedColumnName="id")
**/
private $products;
//...
}
namespace EM\MyBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="domains")
*/
class Domains
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
// ...
}
Run Code Online (Sandbox Code Playgroud)
但它给出了一个错误:[Doctrine\Common\Annotations\AnnotationException]
[语义错误]从未导入属性EM\MyBundle\Entity\Notes :: $ products中的注释"@OneToOne".您是否忘记为此注释添加"使用"语句?
你能帮我解决这个问题吗?
我想这是一个非常琐碎和愚蠢的问题,但我不知道如何在我的Symfony2项目中安装Doctrine Extensions - https://github.com/beberlei/DoctrineExtensions.因为MONTH,YEAR功能,我需要它们.我应该把文件夹放在哪里?我应该把整个DoctrineExtensions文件夹?在哪里写这个:
<?php
$classLoader = new \Doctrine\Common\ClassLoader('DoctrineExtensions', "/path/to/extensions");
$classLoader->register();
Run Code Online (Sandbox Code Playgroud)
在一个单独的文件?把它放在哪里以及如何调用它?
然后就是我需要使用它们:
public function findOneByYearMonthDay($year, $month, $day)
{
$emConfig = $this->getEntityManager()->getConfiguration();
$emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
$emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
$emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Mysql\Day');
Run Code Online (Sandbox Code Playgroud)
非常感谢你提前和再次抱歉这个问题,但我找不到一个教程(这让我感到更加内疚,因为我觉得它甚至没有教程时太微不足道了)
我在我的控制器中有这个:
if(some stuff) {
throw $this->createNotFoundException('message');
}
Run Code Online (Sandbox Code Playgroud)
当我在dev env中测试它时,我得到了Symfony的页面,告诉我用我的文本检测到Exception,但是我无法在prod env中测试它:(我运行它php app/console cache:clear --env=prod --no-debug然后仅在URL中app_dev.php替换app.php但是工具栏和Symfony的错误页面留.
我创建了这个文件 - app/Resources/TwigBundle/views/Exception/error.html.twig.它会在生产中呈现吗?
这是在:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>An Error Occurred: {{ status_text }}</title>
</head>
<body>
<h1>Oops! An Error Occurred</h1>
<h2>The server returned a "{{ status_code }} {{ status_text }}".</h2>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我应该在哪里给出值status_code和status _text?或者他们是从例外中获取的?
因此,一般来说,我想要做的是当我的控制器动作中的条件为真时,我的自定义错误页面将显示在prod env中.我是否已经成功,如果没有,如何制作它以及如何在prod env中查看结果?
几小时前我刚刚在google play上发布了我的应用程序.当然,我不希望它在谷歌播放中显示出来.也许我要等24小时.
事情是我记得我看到了这个,但不知道在哪里,因为它不在这里http://developer.android.com/tools/publishing/versioning.html并且不确定它是否属实.每当我通过更改高于之前的版本代码更新我在Google Play上的应用程序时,谷歌播放是否通过通知通知通知所有下载我的应用程序的用户?
例如,从versioncode = 1到versioncode = 2?谷歌做这个或我是否必须以编程方式通知用户如果theres并更新?谢谢!
我想这是一个非常愚蠢的问题,我为此感到抱歉,但我不知道如何修复它以及我应该做什么.
我从未使用过源控制系统,因此我开始阅读Git的文档.但是我遇到了这个问题:当我执行$ git log它时,它给了我" :"它等待我做某事但我不知道什么以及如何返回并能够写一个新的命令.它还说"没有下一个标签(按RETURN),但我不知道如何按它:(请帮助,因为现在唯一的方法是在每个$ git日志后关闭bash ...再次抱歉对于这个愚蠢的问题.
php ×5
symfony ×5
doctrine-orm ×4
twig ×2
android ×1
doctrine ×1
git ×1
google-play ×1
inheritance ×1
pagination ×1