![](/img/trans.png)
[英]Symfony2 SoftDeleteable not working on QueryBuilder Delete
[英]Symfony2 QueryBuilder not working
我正在使用Doctrine2學習Symfony2
我正在嘗試使用createQueryBuilder()
,但是嘗試在indexController
調用結果時出現錯誤。
錯誤是:
Catchable fatal error: Object of class API\TestBundle\TestDoctrine\Repository\TestRepo could not be converted to string in /Users/tomasz.koprowski/Dev/jv-api/src/API/TestBundle/Controller/IndexController.php on line 60
我的TestRepo:
<?php
namespace API\TestBundle\TestDoctrine\Repository;
use API\TestBundle\TestDoctrine\DatabaseRepository;
use Doctrine\DBAL\Connection;
use Psr\Log\LoggerInterface;
class TestRepo extends DatabaseRepository{
protected $test = array();
public function __construct(
Connection $connection,
LoggerInterface $logger
){
parent::__construct($connection, $logger);
}
public function getTestData()
{
$check = $this->db->createQueryBuilder()
->select('test.user_name')
->from('test');
$this->test = $check->execute()->fetchAll(\PDO::FETCH_ASSOC);
return $this->test;
}
}
我的控制器:
<?php
namespace API\TestBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use API\TestBundle\TestDoctrine\Repository\TestRepo;
class IndexController
{
public $test;
public function __construct(
TestRepo $test
) {
$this->$test = $test;
}
public function testDoctrineAction()
{
return new JsonResponse($this->test->getTestData());
}
}
任何想法,我要去哪里錯了嗎?
這里 :
$this->$test = $test;
您可能可以弄清楚自己出了什么問題:)我很確定這是第60行,如錯誤消息中所述。
我沒有給您答案,因為這通常是您在詢問StackOverflow之前應該自己發現的一種錯誤。 如果您能自己弄清楚,您可能不會再做一次。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.