好的,所以即时尝试允许用户通过管理面板使用此代码更改密码,但我一直在
ORM_Validation_Exception [0]:无法验证数组〜 MODPATH / orm / classes / kohana / orm.php [1174]
有人有任何解决方案吗?分别是控制器功能和模型功能以及视图
控制器:
public function action_edituser() {
$this->auto_render = false;
$edit = Model::factory('manageusers');
$post = $_POST;
$edit->editUser($post);
}
型号:
public function editUser($array) {
try {
$user = ORM::factory('user')
->where('id', '=', $array['id'])
->find()
->update_user($array, array(
'username',
'password',
'email',
));
return $this->response('success', 'User Edited');
} catch (Database_Exception $e) {
$this->response('error', $e->getMessage());
}
}
查看:
<div class="modal" id="editmodal" style="display: none;">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Edit User</h3>
</div>
<div class="modal-body">
<?php
echo Form::open('admin/manageusers/edituser', array('data-function'=> '/admin/manageusers/updategrid', 'data-element' => 'tbody'));
echo Form::label('username', 'Username');
echo Form::input('username', null, array('id' => 'username'));
echo Form::label('email', 'Email');
echo Form::input('email', null, array('id' => 'email'));
echo HTML::anchor('#', 'Change Password', array('id' => 'changepass', 'style' => 'display: block;'));
echo '<div id="passwordchange" style="display: none;">';
echo Form::label('password', 'Password');
echo Form::password('password', null, array('id' => 'password'));
echo Form::label('password_confirm', 'Confirm Password');
echo Form::password('password_confirm');
echo '</div>';
echo Form::hidden('id', null, array('id' => 'id'));
?>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Close</a>
<input type="submit" class="btn btn-success" value="Save changes" />
</div>
<?php echo Form::close(); ?>
</div>
答案 0 :(得分:4)
问题在于存在验证错误,这意味着您的输入与模型的规则不匹配。
您需要捕获ORM_Validation_Exceptions
,并找出导致错误的原因。
public function editUser($array) {
try {
...
} catch (Database_Exception $e) {
...
} catch (ORM_Validation_Exception $e) {
var_dump($e->errors());
}
}