本文整理匯總了PHP中UserForm::setAction方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserForm::setAction方法的具體用法?PHP UserForm::setAction怎麽用?PHP UserForm::setAction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類UserForm
的用法示例。
在下文中一共展示了UserForm::setAction方法的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());
}
}
}