codeigniter 2 with doctrine 2 - 我可以将数据插入到表中但我无法获取数据

时间:2014-10-27 06:06:42

标签: php mysql codeigniter doctrine-orm

我仍然在尝试学习教义,所以我按照在线教程我可以将数据插入到mysql表中。像这样。

public function createObjects() {
        // create a new user object
        $user = new Entities\User;
        $user->setFirstName('Joel');
        $user->setLastName('Verhagen');
        $user->setPassword(md5('Emma Watson'));
        $this->doctrine->em->persist($user);
        $this->doctrine->em->flush();
}

然后我试着像这样回复数据。

public function testing() {
//        $user = new Entities\User;
        $article = new Entities\Article;
        $firstname = $this->doctrine->em->getRepository($article);
        $products = $firstname->findAll();
        foreach ($products as $product) {
            echo sprintf("-%s\n", $product->getContent());
        }
    }

但我得到以下错误可以帮助我吗?

Severity: Warning

Message: ltrim() expects parameter 1 to be string, object given

Filename: ORM/EntityManager.php

Severity: Warning

Message: class_parents(): object or string expected

Filename: Mapping/RuntimeReflectionService.php


Severity: Warning

Message: array_reverse() expects parameter 1 to be array, boolean given

Filename: Mapping/AbstractClassMetadataFactory.php


Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: Mapping/AbstractClassMetadataFactory.php


Fatal error: Uncaught exception 'ReflectionException' with message 'Class does not exist' in E:\xampp\htdocs\shoping\application\libraries\Doctrine\Common\Persistence\Mapping\RuntimeReflectionService.php:73 Stack trace: #0 E:\xampp\htdocs\shoping\application\libraries\Doctrine\Common\Persistence\Mapping\RuntimeReflectionService.php(73): ReflectionClass->__construct('') #1 E:\xampp\htdocs\shoping\application\libraries\Doctrine\ORM\Mapping\ClassMetadataInfo.php(867): Doctrine\Common\Persistence\Mapping\RuntimeReflectionService->getClass(NULL) #2 E:\xampp\htdocs\shoping\application\libraries\Doctrine\ORM\Mapping\ClassMetadataFactory.php(517): Doctrine\ORM\Mapping\ClassMetadataInfo->initializeReflection(Object(Doctrine\Common\Persistence\Mapping\RuntimeReflectionService)) #3 E:\xampp\htdocs\shoping\application\libraries\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php(300): Doctrine\ORM\Mapping\ClassMetadataFactory->initializeReflection(Object(Doctrine\ORM\Mapping\ClassMetadata), Object(Doctrine\Common\Pe in E:\xampp\htdocs\shoping\application\libraries\Doctrine\Common\Persistence\Mapping\RuntimeReflectionService.php on line 73

1 个答案:

答案 0 :(得分:0)

尝试并尝试,最后我找到了一条路。

public function testing() {
//        $user = new Entities\User;
        $article = new Entities\Article;

        $firstname = $this->doctrine->em->getRepository('Entities\Article');
        $products = $firstname->findAll();
        foreach ($products as $product) {
            echo sprintf("-%s\n", $product->getContent());
        }
//        $products = $article->getContent();
//        echo $products.'fdsf';
    }