本文整理汇总了PHP中UserForm::setDefaults方法的典型用法代码示例。如果您正苦于以下问题:PHP UserForm::setDefaults方法的具体用法?PHP UserForm::setDefaults怎么用?PHP UserForm::setDefaults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserForm
的用法示例。
在下文中一共展示了UserForm::setDefaults方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: editAction
public function editAction()
{
$this->view->title = 'Edit user profile';
$this->view->messages = $this->_helper->flashMessenger->getMessages();
$form = new UserForm();
$this->view->form = $form;
$userId = $this->_request->getParam('id');
if ($this->getUser()->getid_uzivatel() !== $userId && !$this->getUser()->isAdmin()) {
// Redirects
$this->_helper->redirector->gotoRoute(array('controller' => 'candidate', 'action' => 'index'), 'default', true);
return;
}
if (!empty($userId)) {
$user = My_Model::get('Users')->getById($userId);
if ($user !== NULL) {
$form->setDefaults($user->get_data());
$avatar = $user->getFoto();
if ($avatar !== NULL) {
$base64 = base64_encode($avatar->getfoto());
$form->avatar->setAttrib('src', "data:image/gif;base64," . $base64);
}
}
}
// ########################### POST ###########################
// Handles form submission
if ($this->_request->isPost()) {
if ($this->_request->getPost('saveButton', false)) {
if ($form->isValid($this->_request->getPost())) {
$formValues = $form->getValues();
// Profile photo
$photo;
if ($form->profilePhoto->isUploaded()) {
if (!$form->profilePhoto->receive()) {
print "Error receiving the file";
}
// Reads location and creates blob
$profilePhotoLocation = $form->profilePhoto->getFileName();
$profilePhotoBlob = file_get_contents($profilePhotoLocation);
if (!empty($profilePhotoBlob)) {
// Creates photo object
$photo = My_Model::get('Photos')->createRow();
$photo->foto = $profilePhotoBlob;
$photo->nazev = array_pop(explode("/", $profilePhotoLocation));
$photo->save();
}
// Deletes file from directory (is already in DB)
unlink($profilePhotoLocation);
}
// Adds photo id
if (!empty($photo)) {
$formValues['id_fotografie'] = $photo->getid_foto();
}
if ($user === NULL) {
$user = My_Model::get('Users')->createRow();
}
if (!empty($formValues["heslo"])) {
$formValues["heslo"] = sha1("interview" . $formValues["heslo"]);
} else {
unset($formValues["heslo"]);
}
$user->updateFromArray($formValues);
$this->_helper->redirector->gotoRoute(array('controller' => 'user', 'action' => 'detail', 'id' => $userId), 'default', true);
}
} else {
if ($this->_request->getPost('closeButton', false)) {
if (!empty($userId)) {
$this->_helper->redirector->gotoRoute(array('controller' => 'user', 'action' => 'detail', 'id' => $userId), 'default', true);
} else {
$this->_helper->redirector->gotoRoute(array('controller' => 'user', 'action' => 'index'), 'default', true);
}
} else {
if ($this->_request->getPost('deleteButton', false)) {
if (!empty($userId)) {
My_Model::get('Users')->getById($userId)->delete();
}
$this->_helper->redirector->gotoRoute(array('controller' => 'user', 'action' => 'index'), 'default', true);
}
}
}
}
}