本文整理汇总了PHP中Zend\View\Model\ViewModel类的典型用法代码示例。如果您正苦于以下问题:PHP ViewModel类的具体用法?PHP ViewModel怎么用?PHP ViewModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ViewModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: editarAction
public function editarAction()
{
//definindo variaveis
$request = $this->getRequest();
$id = $this->Params('id');
$serviceGrupo = $this->getServiceLocator()->get('security-service-grupo');
$form = new Grupo();
$dadosGrupo = $this->getEm('Security\\Entity\\Grupo')->find($id)->toArray();
$form->setData($dadosGrupo);
// definindo acao conforme method da request
if ($request->isPost()) {
$form->setInputFilter(new \Security\Filter\Grupo());
$data = $request->getPost()->toArray();
$form->setData($data);
if ($form->isValid()) {
if ($serviceGrupo->update($data, 'Security\\Entity\\Grupo', $id)) {
$this->flashMessenger()->addSuccessMessage('Dados editados com sucesso!');
return $this->redirect()->toUrl($this->getUrlFromSubfolderApplication('/security/grupo'));
} else {
$this->flashMessenger()->addErrorMessage('Ocorreu algum erro ao editar os dados!');
return $this->redirect()->toRoute(array('controller' => 'grupo', 'action' => 'editar'));
}
}
}
$view = new ViewModel(array('form' => $form));
$view->setTemplate('security/grupo/form.phtml');
return $view;
}
示例2: updateAction
public function updateAction()
{
$request = $this->getRequest();
$recipe = $this->readService->findById($this->params('id'));
if (false === $this->authorizationService->isGranted('recipe.manage', $recipe)) {
throw new UnauthorizedException('Insufficient Permissions');
}
$viewModel = new ViewModel();
$viewModel->setTemplate('recipe/update');
$viewModel->setVariables(['form' => $this->form]);
$this->form->bind($recipe);
if ($request->isPost()) {
$this->form->setData($request->getPost());
if ($this->form->isValid()) {
try {
$this->writeService->save($this->form->getData());
$this->flashMessenger()->addSuccessMessage('Rezept erfolgreich aktualisiert');
$this->redirect()->toRoute('recipe/read/update', ['id' => $this->params('id')]);
} catch (\Exception $e) {
var_dump($e->getMessage());
}
}
}
$this->layout('layout/backend');
return $viewModel;
}
示例3: browseAction
public function browseAction()
{
$serviceLocator = $this->getServiceLocator();
$settings = $serviceLocator->get('Omeka\\Settings');
$form = new SettingForm($serviceLocator);
$data = ['administrator_email' => $settings->get('administrator_email'), 'installation_title' => $settings->get('installation_title'), 'time_zone' => $settings->get('time_zone'), 'pagination_per_page' => $settings->get('pagination_per_page'), 'property_label_information' => $settings->get('property_label_information'), 'use_htmlpurifier' => $settings->get('use_htmlpurifier')];
$form->setData($data);
$request = $this->getRequest();
if ($request->isPost()) {
$form->setData($this->params()->fromPost());
if ($form->isValid()) {
$formData = $form->getData();
foreach ($formData as $key => $value) {
$settings->set($key, $value);
}
$this->messenger()->addSuccess('Settings updated');
return $this->redirect()->toRoute(null, ['action' => 'browse'], true);
} else {
$this->messenger()->addError('There was an error during validation');
}
}
$view = new ViewModel();
$view->setVariable('form', $form);
return $view;
}
示例4: processAction
public function processAction()
{
if (!$this->request->isPost()) {
return $this->redirect()->toRoute('register');
}
$post = $this->request->getPost();
$form = $this->getServiceLocator()->get('RegisterForm');
$form->setData($post);
if (!$form->isValid()) {
$model = new ViewModel(array('error' => 'There were one or more isues with your submission. Please correct them as
indicated below.', 'form' => $form));
$model->setTemplate('user/register/register');
return $model;
}
$data = $form->getData();
if ($this->checkIfNotRegistered($data)) {
// Create user
$this->createUser($form->getData());
return $this->redirect()->toRoute('register', array('action' => 'confirm'));
} else {
$model = new ViewModel(array('error' => 'You are already registered', 'form' => $form));
$model->setTemplate('user/register/register');
return $model;
}
}
示例5: setChildViews
protected function setChildViews(ViewModel $view_page)
{
$view_menu = new ViewModel();
$view_menu->setTemplate('setting/common/menu');
$view_page->addChild($view_menu, 'menu');
return $view_page;
}
示例6: indexAction
public function indexAction()
{
$viewModel = new ViewModel();
// Disable Layout
$viewModel->setTerminal(true);
return $viewModel;
}
示例7: formAction
/**
* Processes formular data
*
* @return \Zend\View\Model\ViewModel
*/
public function formAction()
{
$services = $this->getServiceLocator();
$repository = $services->get('repositories')->get('Applications/Application');
$mode = $this->params()->fromQuery('mode', 'new');
$appId = $this->params()->fromQuery('id');
$viewModel = new ViewModel();
if ('edit' == $mode) {
//$application = $repository->findByCommentId($appId);
$comment = $repository->findComment($appId);
} else {
$comment = new Comment();
$comment->setUser($this->auth()->getUser());
}
$this->acl($application, 'read');
$form = $services->get('forms')->get('Applications/CommentForm');
$form->bind($comment);
if ($this->getRequest()->isPost()) {
$form->setData($_POST);
if ($form->isValid()) {
if ('new' == $mode) {
$application = $repository->find($appId);
$application->comments->add($comment);
}
$viewModel->setVariable('isSaved', true);
}
}
$viewModel->setVariables(array('mode' => $mode, 'identifier' => $appId, 'commentForm' => $form));
return $viewModel;
}
示例8: prepareCompilerView
public static function prepareCompilerView($view, $config, $services)
{
$renderer = $services->get('BlogRenderer');
$view->addRenderingStrategy(function ($e) use($renderer) {
return $renderer;
}, 100);
self::$layout = $layout = new Model\ViewModel();
$layout->setTemplate('layout');
$view->addResponseStrategy(function ($e) use($layout, $renderer) {
$result = $e->getResult();
$layout->setVariable('content', $result);
$page = $renderer->render($layout);
$e->setResult($page);
// Cleanup
$layout->setVariable('single', false);
$headTitle = $renderer->plugin('headtitle');
$headTitle->getContainer()->exchangeArray(array());
$headTitle->append('Zend Framework');
$headLink = $renderer->plugin('headLink');
$headLink->getContainer()->exchangeArray(array());
$headLink(array('rel' => 'shortcut icon', 'type' => 'image/vnd.microsoft.icon', 'href' => '/images/Application/favicon.ico'));
$headScript = $renderer->plugin('headScript');
$headScript->getContainer()->exchangeArray(array());
$headMeta = $renderer->plugin('headMeta');
$headMeta->getContainer()->exchangeArray(array());
foreach (array('sidebar', 'scripts') as $name) {
$placeholder = $renderer->placeholder($name);
$placeholder->exchangeArray(array());
}
}, 100);
}
示例9: indexAction
/**
* Displays web configuration form
*
* @return array|ViewModel
*/
public function indexAction()
{
$setupInfo = new SetupInfo($_SERVER);
$view = new ViewModel(['autoBaseUrl' => $setupInfo->getProjectUrl(), 'autoAdminPath' => $setupInfo->getProjectAdminPath()]);
$view->setTerminal(true);
return $view;
}
示例10: processAction
public function processAction()
{
if (!$this->request->isPost()) {
return $this->redirect()->toRoute('zfcadmin/cmspages/settings');
}
try {
$settingsEntity = new \Base\Entity\Settings();
$post = $this->request->getPost();
$form = $this->getServiceLocator()->get('FormElementManager')->get('CmsSettings\\Form\\PageForm');
$form->setData($post);
if (!$form->isValid()) {
// Get the record by its id
$viewModel = new ViewModel(array('error' => true, 'form' => $form));
$viewModel->setTemplate('cms-settings/page/index');
return $viewModel;
}
$data = $form->getData();
// Cleanup the custom settings
$this->recordService->cleanup('Cms');
foreach ($data as $parameter => $value) {
if ($parameter == "submit") {
continue;
}
$settingsEntity->setModule('Cms');
$settingsEntity->setParameter($parameter);
$settingsEntity->setValue($value);
$this->recordService->save($settingsEntity);
// Save the data in the database
}
$this->flashMessenger()->setNamespace('success')->addMessage($this->translator->translate('The information have been saved.'));
} catch (\Exception $e) {
$this->flashMessenger()->setNamespace('error')->addMessage($e->getMessage());
}
return $this->redirect()->toRoute('zfcadmin/cmspages/settings');
}
示例11: saveAction
public function saveAction()
{
$form = $this->getForm();
$request = $this->getRequest();
$id = $this->params('id');
if ($request->isPost()) {
$data = $request->getPost();
$form->setData($data);
$kart = new Kart();
$form->setInputFilter($kart->getInputFilter());
if ($form->isValid()) {
try {
$kart->exchangeArray($form->getData());
$this->serviceLocator->get('karts')->save($kart->getArrayCopy());
} catch (\Exception $e) {
}
return $this->redirect()->toRoute('application/default', ['controller' => 'kart']);
}
} elseif ($id) {
$kartData = $this->serviceLocator->get('karts')->findById($id);
$form->setData($kartData);
}
$viewModel = new ViewModel();
$viewModel->setVariables(['form' => $form]);
$viewModel->setTemplate('application/kart/form.phtml');
return $viewModel;
}
示例12: viewAction
public function viewAction()
{
$id = (string) $this->params()->fromRoute('id', 0);
$viewModel = new ViewModel(array('session' => $this->getService()->getById($id)));
$viewModel->setTerminal(true);
return $viewModel;
}
示例13: indexAction
public function indexAction()
{
$entity = $this->getEntity();
if (!$entity) {
$this->getResponse()->setStatusCode(404);
return false;
}
$type = $this->moduleOptions->getType($entity->getType()->getName());
if ($type->hasComponent('redirect')) {
/* @var $redirect RedirectOptions */
$redirect = $type->getComponent('redirect');
foreach ($entity->getChildren('link', $redirect->getToType()) as $child) {
if (!$child->isTrashed() && $child->hasCurrentRevision()) {
return $this->redirect()->toRoute('uuid/get', ['uuid' => $child->getId()]);
}
}
}
$model = new ViewModel(['entity' => $entity]);
$model->setTemplate('entity/page/default');
if ($this->params('isXmlHttpRequest', false)) {
$model->setTemplate('entity/view/default');
}
$this->layout('layout/3-col');
if (!$entity->hasCurrentRevision()) {
$this->layout('layout/2-col');
$model->setTemplate('entity/page/pending');
}
return $model;
}
示例14: getAjaxDataAction
public function getAjaxDataAction()
{
$view = new ViewModel();
// Function used for not load some content.
$view->setTerminal(true);
return $view;
}
示例15: processAction
public function processAction()
{
if (!$this->request->isPost()) {
return $this->redirect()->toRoute(NULL, array('controller' => 'index', 'action' => 'index'));
}
$post = $this->request->getPost();
$form = $this->getServiceLocator()->get('LoginForm');
$form->setData($post);
if (!$form->isValid()) {
$model = new ViewModel(array('error' => true, 'form' => $form));
$model->setTemplate('customers/login/index');
return $model;
}
/**
* проверка поступивших данных
*/
$this->getAuthService()->getAdapter()->setIdentity($post['login'])->setCredential($post['pass']);
$result = $this->getAuthService()->authenticate();
if ($result->isValid()) {
$customer = $this->getCustomerData($post['login']);
$this->getAuthService()->getStorage()->write($customer);
$this->redirect()->toRoute('info');
} else {
$model = new ViewModel(array('error' => true, 'form' => $form));
$model->setTemplate('customers/login/index');
return $model;
}
}