本文整理汇总了PHP中Zend\Form\Form::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::setData方法的具体用法?PHP Form::setData怎么用?PHP Form::setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\Form
的用法示例。
在下文中一共展示了Form::setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setData
public function setData($data)
{
if ($data instanceof Traversable) {
$data = ArrayUtils::iteratorToArray($data);
}
$isAts = isset($data['atsEnabled']) && $data['atsEnabled'];
$isUri = isset($data['uriApply']) && !empty($data['uriApply']);
$email = isset($data['contactEmail']) ? $data['contactEmail'] : '';
if ($isAts && $isUri) {
$data['atsMode']['mode'] = 'uri';
$data['atsMode']['uri'] = $data['uriApply'];
$uri = new Http($data['uriApply']);
if ($uri->getHost() == $this->host) {
$data['atsMode']['mode'] = 'intern';
}
} elseif ($isAts && !$isUri) {
$data['atsMode']['mode'] = 'intern';
} elseif (!$isAts && !empty($email)) {
$data['atsMode']['mode'] = 'email';
$data['atsMode']['email'] = $email;
} else {
$data['atsMode']['mode'] = 'none';
}
if (!array_key_exists('job', $data)) {
$data = array('job' => $data);
}
return parent::setData($data);
}
示例2: validate
public function validate($data)
{
$this->form->setData($data);
$isValid = $this->form->isValid();
$normalized = $this->form->getData();
unset($normalized['ViewReportControl']);
$validated = new \SSRS\Form\ValidateResult();
$validated->isValid = $isValid;
$validated->parameters = $normalized;
return $validated;
}
示例3: add
/**
* @param \Zend\Form\Form $form
* @param $data
* @return Entity\Comment|null
* @throws \Exception
*/
public function add(\Zend\Form\Form $form, $data)
{
$serviceLocator = $this->getServiceLocator();
$entityManager = $serviceLocator->get('Doctrine\\ORM\\EntityManager');
$entityType = $entityManager->getRepository('\\Comment\\Entity\\EntityType')->findOneByAlias($data['alias']);
if (!$entityType) {
throw new EntityNotFoundException();
}
$form->setData($data);
if ($form->isValid()) {
if ($entityType->getIsEnabled()) {
$data = $form->getData();
$comment = new Entity\Comment();
$comment->setEntityType($entityType);
$user = $serviceLocator->get('Zend\\Authentication\\AuthenticationService')->getIdentity()->getUser();
$comment->setUser($user);
$comment->setComment($data['comment']);
$entityManager->getConnection()->beginTransaction();
try {
$hydrator = new DoctrineHydrator($entityManager);
$hydrator->hydrate($data, $comment);
$entityType->getComments()->add($comment);
$entityManager->persist($comment);
$entityManager->persist($entityType);
$entityManager->flush();
$entityManager->getConnection()->commit();
return $comment;
} catch (\Exception $e) {
$entityManager->getConnection()->rollback();
throw $e;
}
}
}
return null;
}
示例4: create
/**
* Create a new image
*
* @param array $data
* @param \Zend\Form\Form $form
* @return bool
*/
public function create($data, &$form)
{
$entity = new ImageEntity();
$em = $this->getEntityManager();
$form->bind($entity);
$form->setData($data);
if (!$form->isValid()) {
return false;
}
// we rename the file with a unique name
$newName = FileUtilService::rename($data['image']['image'], 'images/gallery', "gallery");
foreach (ImageEntity::$thumbnailVariations as $variation) {
$result = FileUtilService::resize($newName, 'images/gallery', $variation["width"], $variation["height"]);
if (!$result) {
$this->message = $result;
return false;
}
}
$entity->setImage($newName);
try {
$em->persist($entity);
$em->flush();
$this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_IMAGE_CREATED"]);
return true;
} catch (\Exception $e) {
$this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_IMAGE_NOT_CREATED"]);
return false;
}
}
示例5: create
/**
* Create a new post
*
* @param array $data
* @param \Zend\Form\Form $form
* @return bool
*/
public function create($data, &$form)
{
$post = new PostEntity();
$em = $this->getEntityManager();
$form->bind($post);
$form->setData($data);
if (!$form->isValid()) {
return false;
}
// we rename the file with a unique name
$newName = FileUtilService::rename($data['post']['thumbnail'], 'images/posts', "post");
foreach (PostEntity::$thumbnailVariations as $variation) {
$result = FileUtilService::resize($newName, 'images/posts', $variation["width"], $variation["height"]);
if (!$result) {
$this->message = $result;
return false;
}
}
$post->setThumbnail($newName);
$post->setPostDate("now");
$post->setUrl($this->getPostUrl($post));
try {
$em->persist($post);
$em->flush();
$this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_POST_CREATED"]);
return true;
} catch (\Exception $e) {
$this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_POST_NOT_CREATED"]);
return false;
}
}
示例6: testPreserveEntitiesBoundToCollectionAfterValidation
public function testPreserveEntitiesBoundToCollectionAfterValidation()
{
$this->form->setInputFilter(new \Zend\InputFilter\InputFilter());
$fieldset = new TestAsset\ProductCategoriesFieldset();
$fieldset->setUseAsBaseFieldset(true);
$product = new Entity\Product();
$product->setName('Foobar');
$product->setPrice(100);
$c1 = new Entity\Category();
$c1->setId(1);
$c1->setName('First Category');
$c2 = new Entity\Category();
$c2->setId(2);
$c2->setName('Second Category');
$product->setCategories(array($c1, $c2));
$this->form->add($fieldset);
$this->form->bind($product);
$data = array('product' => array('name' => 'Barbar', 'price' => 200, 'categories' => array(array('name' => 'Something else'), array('name' => 'Totally different'))));
$hash1 = spl_object_hash($this->form->getObject()->getCategory(0));
$this->form->setData($data);
$this->form->isValid();
$hash2 = spl_object_hash($this->form->getObject()->getCategory(0));
// Returned object has to be the same as when binding or properties
// will be lost. (For example entity IDs.)
$this->assertTrue($hash1 == $hash2);
}
示例7: setData
public function setData($data)
{
$parsedData = $data;
if ($data instanceof AbstractSiteOptions) {
$parsedData = array('config' => $data->toArray());
}
return parent::setData($parsedData);
}
示例8: updateAction
public function updateAction()
{
if (!($seo = $this->loadObject($this->seoService, "Seo record doesn't exist."))) {
return $this->redirect()->toRoute('seo', array('action' => 'list'));
}
$this->seoForm->bind($seo);
if ($this->request->isPost()) {
$this->seoForm->setData($this->request->getPost());
if ($this->seoForm->isValid()) {
$this->seoService->update($this->seoForm->getData());
$this->flashMessenger()->addSuccessMessage(sprintf('Seo "%s" has been successfully updated.', $seo->getId()));
return $this->redirect()->toRoute('seo', array('action' => 'list'));
}
}
$view = new ViewModel(array('id' => $seo->getId(), 'form' => $this->seoForm));
$view->setTerminal(true);
return $view;
}
示例9: checkFormIsValid
/**
* Metodo para validar o isPost e isValid
*
* @param Form $form Formulario a ser validado
*
* @return int 0 -> invalid, 1 valid, 2 not isPost
*/
public function checkFormIsValid(Form $form)
{
$objRequest = $this->getRequest();
if ($objRequest->isPost()) {
$form->setData($objRequest->getPost());
return $form->isValid() ? self::CHECK_FORM_IS_VALID : self::CHECK_FORM_IS_NOT_VALID;
} else {
return self::CHECK_FORM_IS_NOT_POST;
}
}
示例10: setData
/**
* @param array|\ArrayAccess|\Traversable $data
* @return Form
*/
public function setData($data)
{
//Set default values
foreach ($this->getDefaults() as $index => $value) {
if (!isset($data[$index])) {
$data[$index] = $value;
}
}
return parent::setData($data);
}
示例11: setData
public function setData($data)
{
if ($data instanceof Traversable) {
$data = ArrayUtils::iteratorToArray($data);
}
if (!array_key_exists('job', $data)) {
$data = array('job' => $data);
}
return parent::setData($data);
}
示例12: preReset
/**
* @param Params $params
* @param Form $form
* @param \FzyAuth\Service\Password\Reset $reset
* @return \Zend\Http\Response|ViewModel
*/
protected function preReset(Params $params, Form $form, \FzyAuth\Service\Password\Reset $reset)
{
if (!trim($params->get('token')) || $reset->getUserByToken($params->get('token'))->isNull()) {
return $this->redirect()->toRoute(UserController::ROUTE_LOGIN);
}
$form->setData($params->get());
$view = new ViewModel(array('changePasswordForm' => $form));
$view->setTemplate('fzy-auth/password/reset');
return $view;
}
示例13: login
/**
* @param \Zend\Form\Form $form
* @param $data
* @return bool
*/
public function login(&$form, $data)
{
$user = new User();
$form->bind($user);
$form->setData($data);
if ($form->isValid()) {
return true;
} else {
return false;
}
}
示例14: checkFormIsValid
/**
* Metodo para validar o isPost e isValid
*
* @param Form $form Formulario a ser validado
*
* @return Form
*/
public function checkFormIsValid(Form $form)
{
$objRequest = $this->getRequest();
if ($objRequest->isPost()) {
$form->setData($objRequest->getPost());
if ($form->isValid()) {
return true;
}
}
return false;
}
示例15: saveAction
public function saveAction(Request $request, Create $createService, Form $form, View $view, Redirect $redirect)
{
if ($request->isPost()) {
$form->setData($request->getPost());
if ($form->isValid()) {
$createService->create($form->getData());
return $redirect->toRoute('admin-translate-words');
}
}
$view->setForm($form);
$view->setTemplate('translate/admin/word/edit');
return $view;
}