本文整理汇总了PHP中UserForm::setModifyMode方法的典型用法代码示例。如果您正苦于以下问题:PHP UserForm::setModifyMode方法的具体用法?PHP UserForm::setModifyMode怎么用?PHP UserForm::setModifyMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserForm
的用法示例。
在下文中一共展示了UserForm::setModifyMode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: editAction
public function editAction()
{
$record = null;
$photoFilename = null;
$userId = $this->_request->getParam('id');
if (!empty($userId)) {
$record = My_Model::get('Users')->getById($userId);
if (!$record) {
throw new Zend_Controller_Action_Exception('The requested page does not exist', 404);
}
$this->view->userId = $userId;
}
$form = new UserForm();
$form->setAction($this->_helper->url->url());
if ($record === null) {
$this->view->title = 'Add User';
} else {
$this->view->title = 'Edit User';
$form->setModifyMode();
}
$this->view->form = $form;
if ($this->_request->isPost()) {
if ($form->isValid($this->_request->getPost())) {
$formValues = $form->getValues();
$foundUser = My_Model::get('Users')->fetchRow(array("username = ?" => $formValues["username"]));
if ($foundUser != null && $foundUser->getId() != $userId) {
$form->getElement('username')->addError('This username is taken');
$form->markAsError();
return;
}
//XXX: Je to dobytčárna
if ($form->photo->receive()) {
$photo = $form->photo;
$oldFullPath = $photo->getFileName();
$path_parts = pathinfo($oldFullPath);
if ($path_parts) {
$photoFilename = $photo->getHash('md5') . '.' . $path_parts['extension'];
$newFullPath = $path_parts['dirname'] . '/' . $photoFilename;
rename($oldFullPath, $newFullPath);
}
}
if ($record === null) {
$record = My_Model::get('Users')->createRow();
if ($photoFilename) {
$record->setPhotoFilename($photoFilename);
}
$record->updateFromArray($formValues, true);
} else {
if ($photoFilename) {
$record->setPhotoFilename($photoFilename);
}
$record->updateFromArray($formValues, false);
//do not update created on value
}
//Zend_Debug::dump($formValues);
//echo '================================================================<br />';
//Zend_Debug::dump($formValues);
//echo '========================PHOTO=========================<br />';
//$var = file_get_contents($form->photo);
//Zend_Debug::dump($var);
$this->_helper->flashMessenger->setNamespace("success")->addMessage("Your changes have been saved!");
$this->_helper->redirector->gotoRoute(array('controller' => 'user'), 'default', true);
}
} else {
if ($record !== null) {
$form->populate($record->toArray());
}
}
}