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';
}
应用程序/配置/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
应用程序/../lib/Cake/VERSION.txt
[...]
2.1.2
我再说一遍,尽管版本明显不匹配,但以前一切正常。谁能帮我解决这个问题?