本文整理汇总了PHP中UserForm::populate方法的典型用法代码示例。如果您正苦于以下问题:PHP UserForm::populate方法的具体用法?PHP UserForm::populate怎么用?PHP UserForm::populate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserForm
的用法示例。
在下文中一共展示了UserForm::populate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: editAction
/**
* Allows users to edit another users' data
* (should be reserved for administrators)
*
* @access public
* @return void
*/
public function editAction()
{
$this->title = 'Edit this user';
$form = new UserForm();
$userModel = new BackofficeUser();
if ($this->getRequest()->isPost()) {
if ($form->isValid($this->getRequest()->getPost())) {
$userModel->save($form->getValues());
$this->_helper->FlashMessenger(array('msg-success' => 'The user was successfully updated'));
App_FlagFlippers_Manager::save();
$this->_redirect('/users/');
}
} else {
$id = $this->_getParam('id');
if (!is_numeric($id)) {
$this->_helper->FlashMessenger(array('msg-error' => 'The user id you provided is invalid'));
$this->_redirect('/users/');
}
if ($id == 1) {
$this->_helper->FlashMessenger(array('msg-error' => 'It is forbidden to mess with the admin account in this release.'));
$this->_redirect('/users/');
}
$row = $userModel->findById($id);
if (empty($row)) {
$this->_helper->FlashMessenger(array('msg-error' => 'The requested user could not be found'));
$this->_redirect('/users/');
}
$data = $row->toArray();
$data['groups'] = $row->groupIds;
$form->populate($data);
$this->view->item = $row;
}
$this->view->form = $form;
}
示例2: 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());
}
}
}