我正在使用 cakephp 3.2,当我通过查找查询检索数据时,它以这种格式提供日期字段
Array
(
[0] => Cake\I18n\FrozenDate Object
(
[date] => 2016-08-01 00:00:00
[timezone_type] => 3
[timezone] => UTC
)
)
Run Code Online (Sandbox Code Playgroud)
和冻结时间中的时间字段
Cake\I18n\FrozenTime Object
(
[date] => 2016-10-11 10:00:00
[timezone_type] => 3
[timezone] => UTC
)
Run Code Online (Sandbox Code Playgroud)
我需要一个完整站点的通用设置或全局解决方案。因此,当我通过从数据库中查找查询获取数据时,它应该以简单格式为我提供日期时间,而没有任何frozendate 对象。
像这样
Array(
[0] => 2016-08-01
)
Run Code Online (Sandbox Code Playgroud) 我在蛋糕3.2中做了模型关联
在这里,我为同一个表的一个id做了它.
我试图为其他人做这件事,但它根本不起作用
以下是流程.
这个输出我得到了
{
"id": 1,
"publisher_id": 133,
"user_id": 118,
"Publisher": {
"id": 133,
"name": "Sradha sradha"
}
Run Code Online (Sandbox Code Playgroud)
这里我想绑定用户ID,它也属于同一个用户表
输出应该是这样的(我想在下面这样得到)
{
"id": 1,
"publisher_id": 133,
"user_id": 118,
"Publisher": {
"id": 133,
"name": "Sradha sradha"
}
"Users": {
"id": 118,
"name": "Sradha anjo"
}
Run Code Online (Sandbox Code Playgroud)
这里publisher_id和user_id都属于同一个用户表.
$this->AdminRevenues->belongsTo('Users', [
'className' => 'Users',
'foreignKey' => 'user_id',
'propertyName' => 'Users']);
$this->AdminRevenues->belongsTo('Users', [
'className' => 'Publisher',
'foreignKey' => 'publisher_id',
'propertyName' => 'Publisher']);
$totalAdminRevenue = $this->AdminRevenues->find('all')
->contain([
'Users' => ['queryBuilder' => function ($q) {
return …
Run Code Online (Sandbox Code Playgroud) 我正在使用 CakePHP 3.2。我有两张桌子service_requests
和coupon_history
service_requests
桌子
CREATE TABLE `service_requests` (
`id` char(36) NOT NULL,
`request_id` bigint(20) NOT NULL,
`user_id` char(36) NOT NULL,
`user_address_id` char(36) NOT NULL,
`service_id` char(36) NOT NULL,
`service_area_id` char(36) NOT NULL,
`coupon_used` int(11) NOT NULL DEFAULT '0' COMMENT '0: Not Applied; 1: Applied',
`coupon_used_id` char(36) NOT NULL,
`status_code` int(11) NOT NULL,
`status` varchar(50) NOT NULL,
`created` datetime NOT NULL,
`modified` datetime NOT NULL
)
Run Code Online (Sandbox Code Playgroud)
coupon_history
桌子
CREATE TABLE `coupon_history` (
`id` char(36) NOT NULL,
`user_id` …
Run Code Online (Sandbox Code Playgroud) 我正在开发CakePHP 3.2
我想在查询中使用数组 WHERE IN ()
代码是
$filter_p_t = $this->request->query('p_t');
$pros10 = $this->Products->find()
->where([
'SellerProducts.stock >' => 0,
'SellerProducts.status' => 1,
'Products.p_status' => 1,
])
->contain([
'SellerProducts',
'ProductTypes.Subcategories.Categories',
]);
Run Code Online (Sandbox Code Playgroud)
这$filter_p_t
是来自带参数的url的数组
/products/display/1?p_t[]=1&p_t[]=86
Run Code Online (Sandbox Code Playgroud)
我想包括$filter_p_t
在where
条件中找到所有IN(1,86)
如何在CakePHP 3中使用php数组到WHERE IN条件?
我有两个表orders
和sub_orders
.他们的关系是
$orders->hasMany('SubOrders', [
'foreignKey' => 'order_id'
]);
Run Code Online (Sandbox Code Playgroud)
两个表都有invoice_no
和sub_invoice
列orders
和sub_orders
分别.
我必须从orders
表中找到包含相关sub_orders
位置或者$trackingId
匹配的记录Orders.invoice_no
SubOrders.sub_invoice
$findOrder = $this->Orders->find('all', [
'conditions' => [
'OR' => [
'Orders.invoice_no' => $trackingId,
'SubOrders.sub_invoice' => $trackingId
]
],
'contain' => [
'SubOrders'
]
]);
Run Code Online (Sandbox Code Playgroud)
但这会给出错误
Column not found: 1054 Unknown column 'SubOrders.sub_invoice' in 'where clause'
Run Code Online (Sandbox Code Playgroud) 我尝试将CakePHP 3.2的默认日期格式设置dd.mm.YYYY
为YYYY-mm-dd
,所以我不必使用$MyDatas->mydate->format('Y-m-d')
,而在编辑数据时表格中更重要的是格式化日期dd.mm.YYYY
(ex-27.02.2016).我需要YYYY-mm-dd
(2016-02-27).
我寻找解决方案,没有显示任何变化(在表单中或作为视图的一部分:) $MyDatas->mydate
:
// in AppController
ini_set('intl.default_locale', 'pl_PL');
//and/or
use Cake\Database\Type;
Type::build('datetime')->useLocaleParser()->setLocaleFormat('YYYY-mm-dd');
//and/or
use Cake\I18n\I18n;
I18n::locale('pl_PL');
//and/or
use Cake\I18n\Time;
Time::$defaultLocale = 'pl-PL'; //and or
Time::setToStringFormat('YYYY-mm-dd HH:mm');//and or
Type::build('datetime')->useLocaleParser(false);//and or
Run Code Online (Sandbox Code Playgroud)
以上代码都没有帮助.有谁知道如何更改日期格式?
我需要找到与给定文章列表具有相同作者的所有文章
这是我的自定义查找器方法:
public function findSimilar(Query $query, array $options)
{
if (empty($options['idList'])) {
throw new Exception('idList is not populated');
}
// We are given a list of article IDs
$idList = $options['idList'];
return $query->matching('Authors', function ($q) use ($idList) {
return $q->matching('Articles', function ($q2) use ($idList) {
return $q2->where(['Articles.id IN' => $idList]);
});
});
}
Run Code Online (Sandbox Code Playgroud)
不幸的是我收到以下错误消息:PDOException:SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'Articles'
我做错了什么?
我有products
桌子,想要选择所有产品.这就是我所做的
$products = $this->Products->find('all', [
'conditions' => [
'status' => 1
]
]);
$this->set('products', $products);
Run Code Online (Sandbox Code Playgroud)
如果已获取并且No product found
未检索到任何产品,则打印产品.
这就是我为此所做的
if (!empty($products)):
// show products
else:
echo 'No Products Found';
endif;
Run Code Online (Sandbox Code Playgroud)
但这不起作用,即使没有找到产品,否则不打印条件.
如果条件甚至没有在控制器动作中工作.有什么遗失的吗?
我正在使用CakePHP 3.2
我有一张表match_schedules
存储两个之间的匹配teams
.有表teams
存储团队信息.
列match_schedules
是
+-----+---------+---------+-------+-------+
| id | team_a | team_b | date | venue |
+-----+---------+---------+-------+-------+
Run Code Online (Sandbox Code Playgroud)
由于我有两列team_a
和team_b
引用teams
表,我不能team_id
在两列中使用外键.
现在,我想将这两列与teams
表关联起来,以便我可以轻松地检索关联的数据
$matches = $this->MatchSchedules->find('all', [
'contain' => [
'Teams'
]
]);
Run Code Online (Sandbox Code Playgroud)
我在TeamsTable.php中试过这个
$this->belongsTo('MatchSchedules', [
'foreignKey' => 'team_a',
'joinType' => 'INNER'
]);
$this->belongsTo('MatchSchedules', [
'foreignKey' => 'team_b',
'joinType' => 'INNER'
]);
Run Code Online (Sandbox Code Playgroud)
在MatchSchedulesTable.php中
$this->hasMany('Teams', [
'foreignKey' => 'team_a'
]);
$this->hasMany('Teams', [
'foreignKey' => 'team_b'
]);
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
在cakephp 3中,我在POST数据中收到了错误的意外字段.实际上该字段不在我的表中,但我想在控制器中使用.
在cakephp 3的烹饪书中.用于构建url
echo $this->Url->build([
"controller" => "Posts",
"action" => "view",
"foo" => "bar"
]);
Run Code Online (Sandbox Code Playgroud)
将输出为
/posts/view/foo:bar
Run Code Online (Sandbox Code Playgroud)
如何访问foo:bar
in in action并保存在变量中$foo
?
我想使用自定义字段创建下拉列表,但我的列表查询将id字段附加到查询中。如何仅显示查询中的选定字段。
$this->loadModel('CardTypes');
$cardTypes = $this->CardTypes->find('list')->select(['code', 'name']);
Run Code Online (Sandbox Code Playgroud)
在我看来
$this->Form->select('card_type_id', $cardTypes, [ 'default' => 'DELTA']);
Run Code Online (Sandbox Code Playgroud) 我使用下面的代码来总结我所有的钱包余额.
$query = $this->Wallets->find();
$query->select([
'count' => $query->func()->count('id'),
'total_price' => $query->func()->sum('amount')
])
->where(['status' => 4, 'user_id' => $user_id]);
pj($query);
echo $query->total_price;
exit;
Run Code Online (Sandbox Code Playgroud)
出来的 pj($query);
[
{
"count": 2,
"total_price": 700
}
]
Run Code Online (Sandbox Code Playgroud)
在这里,我试图使用下面的查询获得单个单独的价值
echo $query->total_price;
Run Code Online (Sandbox Code Playgroud)
我没有得到它.什么是正确的语法,plz建议我.感谢名单.
cakephp-3.2 ×13
cakephp ×12
cakephp-3.x ×3
php ×3
cakephp-3.0 ×1
date ×1
format ×1
is-empty ×1
mysql ×1
where-in ×1