在CakePHP 2我总是用来empty检查是否有任何结果.
<?php
$result = $this->Modelname->find('first', ['conditions' => ['field' => 'value'] ] );
if ( empty($result) ) {
// Bad Request
}
Run Code Online (Sandbox Code Playgroud)
在CakePHP 3它看起来很怪异.
$fancyTable = TableRegistry::get('FancyTable');
$query = $fancyTable->find()->where(['name' => 'fancy', 'active' => 0]);
if ( 0 === $query->count() ) {
// Bad Request
}
Run Code Online (Sandbox Code Playgroud)
这是正确的方法吗?
我有一个从Firefox浏览器导出的p12文件.现在我想提取公钥以将它们交给朋友(而不是整个p12文件).
我使用OpenSSL-Windows32并将p12转换为pem,之后我尝试从pem导出公钥.
这就是我使用的语法:
openssl pkcs12 -in pgp.p12 -clcerts -out pgp.pem
openssl pkey -in pgp.pem -pubout -out pub.pem
Run Code Online (Sandbox Code Playgroud)
现在我有pub.pem包含这样的东西:
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9......
-----END PUBLIC KEY-----
Run Code Online (Sandbox Code Playgroud)
这是导出pub文件的正确方法吗?我可以毫无风险地将pgp.pem交给我的朋友吗?
我遇到CakePHP 3的问题,并保存新实体及其与一个操作的关联.
在我看来,我这样做就像文档中推荐的那样.
我的控制器:
$articles = TableRegistry::get('Articles');
$article = $articles->newEntity($this->request->data);
if ($this->request->is('post')) {
$valid = $articles->validate($article, [
'associated' => ['Topics']
]);
if ( $valid ) {
$articles->save($article, [
'validate' => false,
'associated' => ['Topics']
]);
}
}
Run Code Online (Sandbox Code Playgroud)
那是我的模特:
class ArticlesTable extends Table {
public function initialize(array $config) {
$this->primaryKey('article_id');
$this->belongsTo ( 'Topics', [
'targetForeignKey' => 'topic_id'
]);
}
}
class TopicsTable extends Table {
public function initialize(array $config) {
$this->primaryKey('topic_id');
$this->hasMany ( 'Articles', [
'targetForeignKey' => 'article_id'
]);
}
Run Code Online (Sandbox Code Playgroud)
这是我的数据库: …