- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 lumen 应用程序中使用 laravel Doctrine ,在我的一个 Controller 中我有一个索引函数,它应该返回给定实体的所有记录。
函数看起来像这样
public function index(ServerRequestInterface $request)
{
return $this->showResponse(app()->make('em')->getRepository('App\Entities\showOff')->findAll());
}
它返回这样的数据
[
{
"nodeType": 'showOff'
},
{
"nodeType": 'showOff'
},
{
"nodeType": 'showOff'
},
{
"nodeType": 'showOff'
}
]
这只是实体中的一个属性。
如果我打开 doctrine 调试器,就会看到执行的 SQL 查询,如下所示
SELECT t0.type AS type_1, t0.size AS size_2, t0.last_modified AS last_modified_3, t0.hair_cutter AS hair_cutter_4, t0.file_path AS file_path_5, t0.content_url AS content_url_6, t0.embed_url AS embed_url_7, t0.height AS height_8, t0.width AS width_9, t0.player_type AS player_type_10, t0.about AS about_11, t0.award AS award_12, t0.comment AS comment_13, t0.comment_count AS comment_count_14, t0.text AS text_15, t0.thumbnail AS thumbnail_16, t0.version AS version_17, t0.name AS name_18, t0.id AS id_19, t0.nid AS nid_20, t0.node_type AS node_type_21, t0.owner_id AS owner_id_22, t23.enabled AS enabled_24, t23.username AS username_25, t23.email AS email_26, t23.password AS password_27, t23.remember_token AS remember_token_28, t23.name AS name_29, t23.id AS id_30, t23.nid AS nid_31, t23.node_type AS node_type_32, t0.aggregate_rating_id AS aggregate_rating_id_33, t34.rating_count AS rating_count_35, t34.rating_score AS rating_score_36, t34.name AS name_37, t34.id AS id_38, t34.nid AS nid_39, t34.node_type AS node_type_40, t0.author_id AS author_id_41, t42.enabled AS enabled_43, t42.username AS username_44, t42.email AS email_45, t42.password AS password_46, t42.remember_token AS remember_token_47, t42.name AS name_48, t42.id AS id_49, t42.nid AS nid_50, t42.node_type AS node_type_51, t0.translator_id AS translator_id_52, t53.enabled AS enabled_54, t53.username AS username_55, t53.email AS email_56, t53.password AS password_57, t53.remember_token AS remember_token_58, t53.name AS name_59, t53.id AS id_60, t53.nid AS nid_61, t53.node_type AS node_type_62 FROM show_off t0 LEFT JOIN users t23 ON t0.owner_id = t23.id LEFT JOIN aggregate_rating t34 ON t0.aggregate_rating_id = t34.id LEFT JOIN users t42 ON t0.author_id = t42.id LEFT JOIN users t53 ON t0.translator_id = t53.id ;
当从 mysql 命令行运行时,它会按原样返回所有数据。
有些地方我的所有属性都被剥离了。
我的实体看起来像这样
<?php
namespace App\Entities;
use Doctrine\ORM\Mapping as ORM;
use App\Jobs\IndexNewEntitiesJob;
use App\Jobs\UpdateIndexEntitiesJob;
use Doctrine\Common\Collections\ArrayCollection;
use ApiArchitect\Compass\Entities\User;
/**
* Class ShowOff
*
* @package Jkirkby91\DoctrineSchemas
* @author James Kirkby <jkirkby91@gmail.com>
*
* @ORM\Entity
* @ORM\HasLifeCycleCallbacks
* @ORM\Table(name="show_off")
* @ORM\Entity(repositoryClass="App\Repositories\ShowOffRepository")
*/
class ShowOff extends \App\Entities\MediaObject
{
/**
* @ORM\Column(type="string", length=45, nullable=false, unique=false)
*/
protected $type;
/**
* @ORM\Column(type="integer", length=45, nullable=false)
*/
protected $size;
/**
* @ORM\Column(type="datetime", length=45, nullable=false, unique=false)
*/
protected $lastModified;
/**
* @ORM\OneToOne(targetEntity="\ApiArchitect\Compass\Entities\User", fetch="EAGER", cascade={"persist"})
*/
protected $owner;
/**
* @ORM\OneToOne(targetEntity="\App\Entities\HairCutter", fetch="EAGER", cascade={"persist"})
* @ORM\Column(nullable=true, unique=false)
*/
protected $hairCutter;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
protected $filePath;
/**
* HairCutter constructor.
* @param $fileName
* @param $filePath
* @param $owner
* @param $hairCutter
*/
public function __construct($fileName, $filePath, User $owner, $type, $lastModified, $size)
{
$this->name = $fileName;
$this->filePath = $filePath;
$this->owner = $owner;
$this->type = $type;
$this->lastModified = $lastModified;
$this->size = $size;
$this->nodeType = 'showOff';
}
/**
* Gets the value of filePath.
*
* @return mixed
*/
public function getFilePath()
{
return $this->filePath;
}
/**
* Sets the value of filePath.
*
* @param mixed $filePath the file path
*
* @return self
*/
protected function setFilePath($filePath)
{
$this->filePath = $filePath;
return $this;
}
/**
* Gets the value of owner.
*
* @return mixed
*/
public function getOwner()
{
return $this->owner;
}
/**
* Sets the value of owner.
*
* @param mixed $owner the owner
*
* @return self
*/
protected function setOwner(User $owner)
{
$this->owner = $owner;
return $this;
}
/**
* Gets the value of hairCutter.
*
* @return mixed
*/
public function getHairCutter()
{
return $this->hairCutter;
}
/**
* Sets the value of hairCutter.
*
* @param mixed $hairCutter the hair cutter
*
* @return self
*/
protected function setHairCutter($hairCutter)
{
$this->hairCutter = $hairCutter;
return $this;
}
}
我的配置是这样的
<?php
return [
'managers' => [
'default' => [
'dev' => env('APP_DEBUG'),
'meta' => env('DOCTRINE_METADATA', 'annotations'),
'connection' => env('DB_CONNECTION', 'sqlite'),
'namespaces' => [
'app'
],
'paths' => [
env('COMPASS_ENTITIES',base_path('vendor/apiarchitect/compass/src/Entities')),
env('AUTH_ENTITIES',base_path('vendor/apiarchitect/auth/src/Entities')),
env('LOG_ENTITIES',base_path('vendor/apiarchitect/log/src/Entities')),
env('NODE_ENTITIES',base_path('vendor/jkirkby91/lumendoctrinecomponent/src/Entities')),
env('APP_ENTITIES',base_path('/app/Entities')),
],
'repository' => Doctrine\ORM\EntityRepository::class,
'proxies' => [
'namespace' => false,
'path' => storage_path('proxies'),
'auto_generate' => env('DOCTRINE_PROXY_AUTOGENERATE', false)
],
'events' => [
'listeners' => [],
'subscribers' => []
],
'filters' => [],
'mapping_types' => [
'enum' => 'string'
]
]
],
'extensions' => [
LaravelDoctrine\Extensions\Timestamps\TimestampableExtension::class,
LaravelDoctrine\Extensions\SoftDeletes\SoftDeleteableExtension::class,
LaravelDoctrine\Extensions\Loggable\LoggableExtension::class,
LaravelDoctrine\Extensions\Blameable\BlameableExtension::class,
LaravelDoctrine\Extensions\IpTraceable\IpTraceableExtension::class,
LaravelDoctrine\ORM\Extensions\TablePrefix\TablePrefixExtension::class,
'custom_types' => [
'json' => LaravelDoctrine\ORM\Types\Json::class
],
'custom_datetime_functions' => [],
'custom_numeric_functions' => [],
'custom_string_functions' => [],
'logger' => env('DOCTRINE_LOGGER', trrue),
'cache' => [
'default' => env('DOCTRINE_CACHE', 'memcached'),
'namespace' => null,
'second_level' => false,
],
'gedmo' => [
'all_mappings' => false
],
'doctrine_presence_verifier' => true,
];
有谁知道为什么会这样吗?
最佳答案
你在问题中写下:
Some where along the line all my attributes are being stripped out.
我怀疑 showResponse
方法中的数据发生了一些问题,您环绕从存储库 findAll()
调用返回的结果集。
尝试一次将结果与 showResponse
调用分开,然后检查您得到的结果:
public function index(ServerRequestInterface $request)
{
$result = app()->make('em')->getRepository('App\Entities\ShowOff')->findAll();
var_dump( $result ); // <-- should contain a collection of ShowOff entities.
return $this->showResponse($result); // <-- something happens and returns an array
}
关于php - Laravel Doctrine 仅从 findAll() 查询返回单个属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42019091/
你能比较一下属性吗 我想禁用文本框“txtName”。有两种方式 使用javascript,txtName.disabled = true 使用 ASP.NET, 哪种方法更好,为什么? 最佳答案 我
Count 属性 返回一个集合或 Dictionary 对象包含的项目数。只读。 object.Count object 可以是“应用于”列表中列出的任何集合或对
CompareMode 属性 设置并返回在 Dictionary 对象中比较字符串关键字的比较模式。 object.CompareMode[ = compare] 参数
Column 属性 只读属性,返回 TextStream 文件中当前字符位置的列号。 object.Column object 通常是 TextStream 对象的名称。
AvailableSpace 属性 返回指定的驱动器或网络共享对于用户的可用空间大小。 object.AvailableSpace object 应为 Drive 
Attributes 属性 设置或返回文件或文件夹的属性。可读写或只读(与属性有关)。 object.Attributes [= newattributes] 参数 object
AtEndOfStream 属性 如果文件指针位于 TextStream 文件末,则返回 True;否则如果不为只读则返回 False。 object.A
AtEndOfLine 属性 TextStream 文件中,如果文件指针指向行末标记,就返回 True;否则如果不是只读则返回 False。 object.AtEn
RootFolder 属性 返回一个 Folder 对象,表示指定驱动器的根文件夹。只读。 object.RootFolder object 应为 Dr
Path 属性 返回指定文件、文件夹或驱动器的路径。 object.Path object 应为 File、Folder 或 Drive 对象的名称。 说明 对于驱动器,路径不包含根目录。
ParentFolder 属性 返回指定文件或文件夹的父文件夹。只读。 object.ParentFolder object 应为 File 或 Folder 对象的名称。 说明 以下代码
Name 属性 设置或返回指定的文件或文件夹的名称。可读写。 object.Name [= newname] 参数 object 必选项。应为 File 或&
Line 属性 只读属性,返回 TextStream 文件中的当前行号。 object.Line object 通常是 TextStream 对象的名称。 说明 文件刚
Key 属性 在 Dictionary 对象中设置 key。 object.Key(key) = newkey 参数 object 必选项。通常是 Dictionary 
Item 属性 设置或返回 Dictionary 对象中指定的 key 对应的 item,或返回集合中基于指定的 key 的&
IsRootFolder 属性 如果指定的文件夹是根文件夹,返回 True;否则返回 False。 object.IsRootFolder object 应为&n
IsReady 属性 如果指定的驱动器就绪,返回 True;否则返回 False。 object.IsReady object 应为 Drive&nbs
FreeSpace 属性 返回指定的驱动器或网络共享对于用户的可用空间大小。只读。 object.FreeSpace object 应为 Drive 对象的名称。
FileSystem 属性 返回指定的驱动器使用的文件系统的类型。 object.FileSystem object 应为 Drive 对象的名称。 说明 可
Files 属性 返回由指定文件夹中所有 File 对象(包括隐藏文件和系统文件)组成的 Files 集合。 object.Files object&n
我是一名优秀的程序员,十分优秀!