- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的数据库中有一个模型(php 类)和一个表。当我尝试在没有 where 子句的情况下 find_many
时,它会找到所有数据库条目。它为每个数据库条目创建一个模型。但是这些模型是空的并且没有分配数据,因为我有自己的模型 setter/getter。
<?php
class City extends Model {
private $id;
private $idOwm;
private $idBla;
private $name;
private $longitude;
private $latitude;
private $country;
public function data() {
return $this->has_many('Data', 'idCity');
}
public function getId() {
return $this->id;
}
public function setId($id) {
$this->id = $id;
}
public function getIdOwm() {
return $this->idOwm;
}
public function setIdOwm($idOwm) {
$this->idOwm = $idOwm;
}
public function getIdBla() {
return $this->idBla;
}
public function setIdBla($idBla) {
$this->idBla = $idBla;
}
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
}
public function getLongitude() {
return $this->longitude;
}
public function setLongitude($longitude) {
$this->longitude = $longitude;
}
public function getLatitude() {
return $this->latitude;
}
public function setLatitude($latitude) {
$this->latitude = $latitude;
}
public function getCountry() {
return $this->country;
}
public function setCountry($country) {
$this->country = $country;
}
}
$cities = Model::factory('City')->find_many();
$cities
是一个包含许多类型为 City
的模型的数组。
City Object
(
[id:protected] =>
[idOwm:protected] =>
[idBla:protected] =>
[name:protected] =>
[longitude:protected] =>
[latitude:protected] =>
[country:protected] =>
[orm] => ORM Object
(
[_connection_name:protected] => default
[_table_name:protected] => city
[_table_alias:protected] =>
[_values:protected] => Array
(
)
[_result_columns:protected] => Array
(
[0] => *
)
[_using_default_result_columns:protected] => 1
[_join_sources:protected] => Array
(
)
[_distinct:protected] =>
[_is_raw_query:protected] =>
[_raw_query:protected] =>
[_raw_parameters:protected] => Array
(
)
[_where_conditions:protected] => Array
(
)
[_limit:protected] =>
[_offset:protected] =>
[_order_by:protected] => Array
(
)
[_group_by:protected] => Array
(
)
[_having_conditions:protected] => Array
(
)
[_data:protected] => Array
(
[id] => 1
[idOwm] => 2950159
[idBla] => 0
[name] => Berlin
[latitude] => 52.52
[longitude] => 13.41
[country] => DE
)
[_dirty_fields:protected] => Array
(
)
[_expr_fields:protected] => Array
(
)
[_is_new:protected] =>
[_instance_id_column:protected] => id
)
)
如何在 Idiorm/Paris 中使用我自己的 setter/getter?这是可能的还是我必须以不同的方式执行一些模型逻辑?
最佳答案
你不能这样做,因为 Idiorm 依赖于 __set()
和 __get()
魔术方法 - 如果你包含适当的同名类属性,那么那些永远不会访问魔术方法。查看PHP manualdocs link有关这方面的更多详细信息。
要使您的 IDE 正常工作,您可以使用 PHPDoc @property
commentsdocs link ,专为此目的而设计。我实际上并没有使用 PHPStorm,但从我在其文档中看到的内容来看,它确实理解 PHPDoc 注释并可以使用它们来理解代码结构。
所以你的代码应该是这样的:
/**
* @property int $id
* @property int $idOwm
* @property int $idBla
* @property string $name
* @property string $longitude
* @property string $latitude
* @property string $country
*/
class City extends Model {
public function data() {
return $this->has_many('Data', 'idCity');
}
public function getId() {
return $this->id;
}
...
}
这个其他的 stackoverflow 问题和答案表明这将在 Netbeans 中工作:https://stackoverflow.com/a/15160464/461813
关于php - 如何在 Idiorm/Paris 中使用自己的 setter/getter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38071533/
我正在尝试让 Idiorm/Paris 与我的 PHP 项目一起工作。我的表对象位于名为项目的文件夹/命名空间中,当我尝试运行 Idiorm/Paris 时,它将“项目”名称添加到列中。 "Uncau
MySQL 语法 SELECT users.*, roles.name, departments.name FROM users INNER JOIN roles ON users.roleId =
我正在使用 Idiorm - 一个非常简单的 ORM。我正在尝试在单个查询中更新多行。 Idiorm 不支持这个,所以我只剩下 n 查询或 raw_query陈述。 我选择后者。 但是,我似乎无法让它
我想显示特定日期最后插入行的字段 (bal)。 $BALdata171201 = ORM::for_table('sys_transactions')->where('date',$data17120
我正在使用 Paris (它建立在 Idiorm 之上)。 我有以下模型类(受 documentation on github 启发的示例): belongs_to('User'); } }
我无法使用 php idiorm/paris 获取 has_many 查询的结果。遵循 paris site 中的示例帖子的 has_many 结果作为对象返回。 太好了,我可以运行对象并访问各个方法
我正在尝试使用 idiorm 从 mysql 数据库中获取最后 30 个条目。一个单元格仅包含存储的“/question”或“/info”,而在我的 php 页面中,这些行未显示。我只是回应这些条目。
我在我的 PHP 项目中使用 Idiorm 和 Paris。 我想向我的 mysql 数据库添加一些带有空值的条目。 例如: $openingtime->setBegin(null); $openin
我有更新记录的功能,但我不能失败并向我发送“行中缺少主键 ID 或为空”消息,我该如何解决? public static function update_child($data) { try
我使用 WAMP 在本地主机上运行 PHP 代码。问题是在我的本地主机上我收到 utf8 错误,例如“lán”。在实时服务器上,我得到了“lån”,就像怀疑的那样。 到目前为止我已经尝试过 将服务器和
我的数据库中有一个模型(php 类)和一个表。当我尝试在没有 where 子句的情况下 find_many 时,它会找到所有数据库条目。它为每个数据库条目创建一个模型。但是这些模型是空的并且没有分配数
我有一个基于 Paris 的模型及其相关的“帖子”表: class Post extends Model { public static $_table = 'posts'; publ
我使用 PHP 并使用名为 Idiorm 的 ORM 进行 SQL 调用. 请求可能如下所示: $person = ORM::for_table('person')->create(); $perso
我想用 idiorm & paris 数据库工具包 ( http://j4mie.github.io/idiormandparis/ ) 提出这个请求: SELECT mqtt_table.* FRO
我是一名优秀的程序员,十分优秀!