我有两个型号 - Cars和CarOptions
Cars hasOne CarOptions
如果用户要编辑汽车 - 他们也可以设置一些CarOptions并保存
与Cars保存相关的一切都很好,但CarOptions不能保存.如果我Car在保存之前调试对象 - 我看到以下内容
Car: {
"id": 3,
"name": "Ford Mustang",
"description": "some description",
"city": "San Francisco",
"state": "California",
"country": "USA",
"created": "2015-08-14T12:20:14-0500",
"CarOptions": {
"manual_transmission": "N"
}
}
Run Code Online (Sandbox Code Playgroud)
我保存的代码如下
$car = $this->Cars->findByName('Ford Mustang')->first();
$car = $this->Cars->patchEntity($car, $this->request->data);
$carOptions = $this->Cars->CarOptions->newEntity();
$carOptions->manual_transmission = 'N';
$car->CarOptions = $carOptions;
$this->Cars->save($car);
Run Code Online (Sandbox Code Playgroud)
但是,不会创建或编辑CarOptions记录.我错过了什么?
我需要知道为什么以下不起作用.这段代码将从索引控制器中提取数据以搜索获取json数据.任何请求都没有发生且没有任何反应
我是Cakephp 3.0的新手
我正在尝试在CakePHP 3.0中使用自动完成/自动建议,但我发现的所有内容都是1.3或者不是Cake,我不知道该怎么做才能让它正常工作.我正是需要它为cakephp 3.0 snippet 1.CarsController.php这是carcontroller访问时ajax请求并将在json数据中编码2.CarsTable.php从carstable中获取数据3.index.ctp是视图页面和自动完成方法
<?php
namespace App\Controller;
use App\Controller\AppController;
class CarsController extends AppController {
public function index() {
$this->loadComponent('RequestHandler');
if ($this->request->is('ajax')) {
$term = $this->request->query('term');
$carNames = $this->Car->getCarNames($term);
$this->set(compact('carNames'));
$this->set('_serialize', 'carNames');
}
}
}
?>Run Code Online (Sandbox Code Playgroud)
<?php
namespace App\Model\Table;
use Cake\ORM\Table;
class Carstable extends AppModel {
public function getCarNames ($term = null) {
if(!empty($term)) {
$cars = $this->find('list', array(
'conditions' => array(
'name LIKE' => trim($term) . '%'
)
));
return $cars;
}
return false;
}
} …Run Code Online (Sandbox Code Playgroud)我发现当我使用$ this-> Form-> submit时,提交按钮包装在div.form-group中。
echo $this->Form->submit('submit', array(
'div' => 'form-group',
'class' => 'btn btn-primary'
));
echo $this->Form->button('Reset', array('type'=>'reset' ,'class' => 'btn btn-primary'));
echo $this->Form->end();
Run Code Online (Sandbox Code Playgroud) 我正在尝试更改消息
您无权访问该位置。
与cakedc 3.1的cakedc / users插件一起使用,但我找不到方法。
这是我在src / Controller / AppController中的配置:
public function initialize()
{
parent::initialize();
$this->loadComponent('Flash');
$this->loadComponent('CakeDC/Users.UsersAuth', [
'authError' => 'Did you really think you are allowed to see that?',
]
);
}
Run Code Online (Sandbox Code Playgroud)
但是消息仍然是:
您无权访问该位置。
我在做什么错?
谢谢。
嗨我想用本周,本月,今年从MySql表中搜索数据.下面是我的控制器代码.我没有使用Current获取任何数据DATE_SUB(NOW(), INTERVAL 1 WEEK
控制器初始代码:
$condition = array('Order.eventid' => $id, 'Order.userid !=' => '');
if (isset($_GET['dr']) && !empty($_GET['dr'])) {
if ($_GET['dr'] == 2) { // This week
$condition['Order.addeddate'] = 'DATE_SUB(NOW(), INTERVAL 1 WEEK)';
}
if ($_GET['dr'] == 3) { // This month
$condition['Order.addeddate'] = 'DATE_SUB(NOW(), INTERVAL 1 MONTH)';
}
if ($_GET['dr'] == 4) { // This year
$condition['Order.addeddate'] = 'DATE_SUB(NOW(), INTERVAL 1 YEAR)';
}
if ($_GET['dr'] == 5) { // Custom date range
//$condition[] = array('Order.addeddate' => 'DATE_SUB(NOW(), INTERVAL …Run Code Online (Sandbox Code Playgroud) 我想知道用于编写REST API响应的实践: -
{
"Headline": {
"score": 10,
"summary": "Public Url Description.",
"status": 1,
"description": "Perfect! The URL contains your name"
},
"Profile Picture": {
"score": 10,
"summary": "Profile Picture Description.",
"status": 1,
"description": "Amazing Job, Now you are more approachable."
}
}
Run Code Online (Sandbox Code Playgroud)
要么
{
"status": 200,
"response": {
"Headline": {
"score": 10,
"summary": "Public Url Description.",
"status": 1,
"description": "Perfect! The URL contains your name"
},
"Profile Picture": {
"score": 10,
"summary": "Profile Picture Description.",
"status": 1,
"description": "Amazing …Run Code Online (Sandbox Code Playgroud) 我有一个只显示表格行ID的下拉列表.我想在下拉列表中向该用户显示该表中的多个值.
我是否需要在控制器或类似的变量中添加一个带有列名的数组?
编辑:在功能添加我有这个变量
$addresses = $this->Users->Addresses->find('list', ['limit' => 200]);
Run Code Online (Sandbox Code Playgroud)
在视图中
echo $this->Form->input('address_id', ['options' => $addresses]);
Run Code Online (Sandbox Code Playgroud)
我只想在下拉列表中显示值address_id,city,street,zipcode.
我已经通过composer安装了Google PHP API客户端库; https://github.com/google/google-api-php-client
guzzle,psr,monolog,firebase和google目录现已在我的供应商目录中创建.
但是,我很难将其添加为我的控制器中的依赖项.
大多数答案表明你需要创建一个Cake插件才能在核心中使用新的库,但我很难找到解释如何执行此操作的任何资源.
在不属于蛋糕核心的控制器中使用新库的正确方法是什么?
我使用下面的代码来总结我所有的钱包余额.
$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建议我.感谢名单.
我Security在CakePHP 3.2中使用实用程序进行加密和解密.我打电话的时候
Security::encrypt('string', 'key') //密钥长度为32或更多
在字符串上的方法,它返回带有一些无效字符的加密字符串,如下所示:
8e88c050ff20cb12984bf1af24b11fc7ada198082c67d6b3da7170572d5bcd54plp21ķ;ܝ%N
我想用这个字符串url.但由于存在一些无效字符,因此无法正常工作.
现在我想避免这些角色.有没有办法避免这些角色?
cakephp ×10
php ×5
cakephp-3.0 ×4
cakephp-2.0 ×2
api ×1
cakedc ×1
cakephp-2.3 ×1
cakephp-3.2 ×1
cakephp-3.x ×1
encryption ×1
google-api ×1
javascript ×1
jquery ×1
json ×1
mysql ×1
rest ×1
security ×1