我有一个使用MVC模式开发的应用程序,我想现在索引它的多个模型,这意味着每个模型都有不同的数据结构.
是否更好地使用多个索引,每个模型一个或每个模型在同一索引中有一个类型?我认为这两种方式都需要不同的搜索查询.我刚刚开始这个.
如果数据集很小或很大,两个概念之间是否存在绩效差异?
如果有人可以为我推荐一些好的样本数据,我会自己测试第二个问题.
我现在花了2个多小时试图弄清楚如何要求{与方法声明在同一行,而不是默认要求是下一行.我怎么能这样做?我已经将PSR2标准复制到一个名为PSR2的新文件夹,以便根据自己的喜好对其进行修改.所以我正在研究的基础基本上是我想要修改的PSR2标准.
我已经尝试过ruleset.xml,我试图在代码中直接修改它而没有成功.
<rule ref="PEAR.Classes.ClassDeclaration">
<properties>
<property name="eolChar" value="{"/>
</properties>
</rule>
<rule ref="PSR2R.Classes.ClassDeclaration">
<properties>
<property name="eolChar" value="{"/>
</properties>
</rule>
Run Code Online (Sandbox Code Playgroud)
我已经发现这是错的.EOL由phpcs设置.但我无法弄清楚我是否可以通过规则配置一个值.
到目前为止,这对我来说很好用(搞愚蠢的空间!):
<?xml version="1.0"?>
<ruleset name="PSR2R">
<description>PSR2 with tabs instead of spaces.</description>
<arg name="tab-width" value="4"/>
<rule ref="PSR2">
<exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
</rule>
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="indent" value="4"/>
<property name="tabIndent" value="true"/>
</properties>
</rule>
</ruleset>
Run Code Online (Sandbox Code Playgroud)
但我想补充上面的规则.
我们需要在Cakephp 3中阅读Cakephp 2用户cookie.但似乎在更新期间,CakeCookie标签已从cookie中删除.所以每个Cakephp cookie都是分开的.关于这里,Cakephp 3可以读取旧的cookie,如果它们是用AES编写的.但在旧的cakephp中,默认选项是密码,我们的cookie是用密码编写的.所以我们现在不能读旧饼干.
可以选择在Cakephp 2中读取旧cookie并使用AES更新它们.但是当我们更新到Cakephp 3时,会有用户拥有Cakephp 2 cookie.所以我们需要在Cakephp 3中查看这个.
我们计划在cakephp 3中使用密码读取旧cookie,并将其值写入新cookie.我们使用了安全密码方法的代码,并创建了以下代码.
问题是,这段代码适用于字符串,但它在一些嵌套数组上失败了.问题可能是加号或任何其他编码问题.有时候它有效,有时则不然.
我分享了我们的代码来展示我们的流程.您可以提出另一种转换旧cookie的方法.
if (isset($_COOKIE['CakeCookie'])) {
if (is_array($_COOKIE['CakeCookie'])) {
foreach ($_COOKIE['CakeCookie'] as $key => $value) {
$valueDecr=$this->decryptSaltedData($value);
$this->Cookie->configKey($key, ['expires' => '+60 days']);
$this->Cookie->write($key, $valueDecr);
$this->Cookie->delete("CakeCookie[$key]");
unset($_COOKIE['CakeCookie'][$key]);
setcookie("CakeCookie[$key]", "aaa", time()-3600, '/');
setcookie("CakeCookie[$key]", "aaa", time()-3600, '/', '.example.com');
}
}
}
public function decryptSaltedData($data) {
$data2 = substr($data, 8);
$text = base64_decode($data2);
$key = Security::salt();
$cipherSeed='45454545454545454545';
srand($cipherSeed);
$out = '';
$keyLength = strlen($key);
for ($i = 0, …Run Code Online (Sandbox Code Playgroud) 我希望在使用流体布局时,[left | content | right]和[left | content]或[content | right]具有不同的布局,"单元格"之间的沟槽也是流动的并且具有百分比值.但我希望在左/右和内容区域之间有一个固定的宽度,如10px或20px.
有什么建议如何使这项工作?我已经尝试过,但总是以极其频繁的元素结束.
Cakephp 3创建一个带标签的无线电容器 - >输入就像那样
<div class="radio">
<label class="radio-acces-checked" for="condition-access-1">
<input id="condition-access-1" type="radio" value="1" name="condition_access">
Free access
</label>
</div>
...
Run Code Online (Sandbox Code Playgroud)
我想改变结构,但它不起作用,它始终是相同的结构...你有一个关于如何解决我的问题的想法?
$myTemplates = [
'radioWrapper' => '<div class="radio">{{label}}{{input}}</div>'
];
echo $this->Form->radio('condition_access', [
['value' => 1, 'text' => __('Free Access')],
['value' => 2, 'text' => __('Payment Access')],
['value' => 3, 'text' => __('Reduce price')]
]);
Run Code Online (Sandbox Code Playgroud) 自制pubsub系统和addEventListener()使用plus的系统之间有更大的区别new CustomEvent吗?
pubsub的伪代码实现(从此处获取):
// Publishing to a topic:
events.publish('/page/load', {
url: '/some/url/path' // any argument
});
// ...and subscribing to said topic in order to be notified of events:
var subscription = events.subscribe('/page/load', function(obj) {
// Do something now that the event has occurred
});
// ...sometime later where I no longer want subscription...
subscription.remove();
Run Code Online (Sandbox Code Playgroud)
本机API:
var event = new Event('build');
// Listen for the event.
elem.addEventListener('build', function (e) { ... }, false);
// …Run Code Online (Sandbox Code Playgroud) 我们正在评估是否由于缺乏好的库而我们不得不重新发明轮子,或者我们根本找不到.我们有非常明确和严格的要求:
到目前为止,我们发现的最好的东西是Asido,但它已经过时且被遗弃了.
您知道哪些图书馆符合我们的需求?
我有一个CakePHP 3.3.14应用程序,我创建了2个子目录,webroot/data/downloads/和webroot/data/master
我想将这些路径放在自定义配置文件中,并在Controller中引用它们.但我看不出怎么做.
我已经按照配置文档进行了操作,但不是很清楚.
所以我做了什么:
config/my_config.php上面的文件定义了一个数组:
return [ 'downloadsPath' => 'webroot/data/downloads/', 'masterPath' => 'webroot/data/master/' ];
Run Code Online (Sandbox Code Playgroud)在config/bootstrap.php我说:Configure::load('my_config', 'default');
我如何在控制器中使用它?如果我把Configure::read('my_config.masterPath');它给出一个错误说:没有找到类'App\Controller\Configure'
如果我添加use Cake\Core\Configure;到控制器的顶部,则清除错误但返回值为null:
debug(Configure::read('my_config.masterPath')); // null
Run Code Online (Sandbox Code Playgroud) 这是我开始学习CakePHP 3以来一直面临的问题
实体的这个概念是什么,现实世界的例子会有所帮助.
public function add()
{
// why do we have to create new entity / what is the role of entity here.
$comment = $this->Comments->newEntity();
if ($this->request->is('post','put')) {
// why do we have to use this line after posting / what is the role of this line.
$comment = $this->Comments->patchEntity($comment,$this->request->data);
if ($this->Comments->save($comment)) {
$this->Flash->success('comment submitted successfully.');
} else {
$this->Flash->error('Sorry, comment could not be updated.');
}
}
return $this->redirect($this->referer());
}
Run Code Online (Sandbox Code Playgroud) 我想生成6位数的唯一代码但我希望前3个是字母表,最后3个是数字,如下例所示.
AAA111
ABD156
DFG589
ERF542...
Run Code Online (Sandbox Code Playgroud)
请帮助创建具有以上组合的代码..
下面是我的代码..
public function generateRandomString() {
$characters = '1234567890';
$length = 6;
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试compress the quality使用图像ImageMagick。1600X800我的意思是我有一个尺寸为且大小为 的图像4MB。现在我试图在2MB不调整其尺寸的情况下压缩该图像的质量,这意味着新生成的图像也具有与实际图像相同的尺寸(i.e. 1600X800),但该图像的质量应压缩为2MB(half of the actual image)。为此,现在我使用下面的代码,但这并没有压缩新创建的图像的大小:
$src_img = "src.png";
$dest_img = "dest.png";
exec("convert $src_img -quality 90 $dest_img");
Run Code Online (Sandbox Code Playgroud)
那么有人可以告诉我我可以做什么来压缩图像的大小而不丢失其实际尺寸吗ImageMagick?
嗨,我正在制作一个网页以从注册者那里获取电话号码,并将随机数作为密码保存在数据库中。我想显示注册者输入随机数。
所以我做了这些代码。
class RegistersController extends AppController{
public function index()
{
$random = rand(11111,99999);
$register = $this->Registers->newEntity($this->request->data);
if($this->Registers->save($register)) {
$this->Flash->success('The Phone number has been sent.');
$reg = $this->Registers->patchEntity($random);
$this->Registers->save($reg);
return $this->redirect(['action' => 'certnum']);
}
$this->set(compact('register'));
}
}
Run Code Online (Sandbox Code Playgroud)
但不知何故,它产生了致命的错误,我不知道该怎么办?
我是否必须将随机数放入具有特定 id 号或其他内容的数组中?
请帮忙。
谢谢
php ×6
cakephp ×5
cakephp-3.0 ×4
image ×2
cakephp-3.1 ×1
cakephp-3.3 ×1
codesniffer ×1
cookies ×1
css ×1
database ×1
events ×1
forms ×1
helper ×1
imagemagick ×1
javascript ×1
merge ×1
oop ×1
phpcs ×1
radio ×1
random ×1
rules ×1
save ×1
search ×1
string ×1
unit-testing ×1