Warning (2): Parameter 1 to Employment::beforeFind() expected to be a reference, value given [CORE/Cake/Event/CakeEventManager.php, line 244]
他の人のアプリケーションのモデルに Cryptable 動作を追加しようとしています。アプリケーションは事前に完全に機能していました。ここに私が追加したものがあります:
アプリ/モデル/動作/CryptableBehavior.php
function setup(&$model, $settings) {
if (!isset($this->settings[$model->alias])) {
$this->settings[$model->alias] = array(
'fields' => array(),
'all' => true
);
}
$this->settings[$model->alias] = array_merge($this->settings[$model->alias], $settings);
}
function beforeFind(&$model, $queryData) {
foreach ($this->settings[$model->alias]['fields'] AS $field) {
if (isset($queryData['conditions'][$model->alias.'.'.$field]) || $this->settings[$model->alias]['all']) {
$queryData['conditions'][$model->alias.'.'.$field] = $this->encrypt($queryData['conditions'][$model->alias.'.'.$field]);
}
}
return $queryData;
}
function afterFind(&$model, $results, $primary) {
foreach ($this->settings[$model->alias]['fields'] AS $field) {
if ($primary) {
foreach ($results AS $key => $value) {
if (isset($value[$model->alias][$field]) || $this->settings[$model->alias]['all']) {
$results[$key][$model->alias][$field] = $this->decrypt($value[$model->alias][$field]);
}
}
} else {
if (isset($results[$field])) {
$results[$field] = $this->decrypt($results[$field]);
}
}
}
return $results;
}
function beforeSave(&$model) {
foreach ($this->settings[$model->alias]['fields'] AS $field) {
if (isset($model->data[$model->alias][$field]) || $this->settings[$model->alias]['all']) {
$model->data[$model->alias]['cleartext_'.$field] = $model->data[$model->alias][$field];
$model->data[$model->alias][$field] = $this->encrypt($model->data[$model->alias][$field]);
}
}
return true;
}
public function encrypt($data) {
if ($data !== '') {
return base64_encode(mcrypt_encrypt(Configure::read('Cryptable.cipher'), Configure::read('Cryptable.key'), $data, 'cbc', Configure::read('Cryptable.iv')));
} else {
return '';
}
}
public function decrypt($data, $data2 = null) {
if (is_object($data)) {
unset($data);
$data = $data2;
}
if ($data != '') {
return trim(mcrypt_decrypt(Configure::read('Cryptable.cipher'), Configure::read('Cryptable.key'), base64_decode($data), 'cbc', Configure::read('Cryptable.iv')));
} else {
return '';
}
}
}
アプリ/モデル/雇用.php
<?php
class Employment extends AppModel {
var $actsAs = array(
'Cryptable' => array("all" => true)
); #this is the only line I added here
public $name = 'Employment';
}
app/Config/bootstrap.php
[...]
Configure::write('Cryptable.cipher', 'rijndael-192');
Configure::write('Cryptable.key','******************');
Configure::write('Cryptable.iv', base64_decode('**************************')); #not the exact lenggth
[...]
php -v
PHP 4.4.9 (cgi-fcgi) (built: Jul 22 2013 09:48:43)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
app/../lib/Cake/VERSION.txt
[...]
2.1.2
繰り返しますが、明らかなバージョンの不一致にもかかわらず、以前はすべてが機能していました。誰でもこれで私を助けることができますか?