本文整理汇总了PHP中Zend\View\Model\ViewModel::setVariables方法的典型用法代码示例。如果您正苦于以下问题:PHP ViewModel::setVariables方法的具体用法?PHP ViewModel::setVariables怎么用?PHP ViewModel::setVariables使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\Model\ViewModel
的用法示例。
在下文中一共展示了ViewModel::setVariables方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例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: 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;
}
示例4: indexAction
public function indexAction()
{
/** @var \DDD\Service\Parking\General $parkingGeneralService */
$parkingGeneralService = $this->getServiceLocator()->get('service_parking_general');
$auth = $this->getServiceLocator()->get('library_backoffice_auth');
$hasAMM = $auth->hasRole(Roles::ROLE_APARTMENT_MANAGEMENT);
$form = $this->getForm();
$form->prepare();
$viewModel = new ViewModel();
$textline = $active = 0;
$parkingPermit = '';
if ($this->parkingLotId) {
$generalInfo = $parkingGeneralService->getParkingById($this->parkingLotId);
$usages = iterator_to_array($parkingGeneralService->getUsages($this->parkingLotId));
foreach ($usages as $usage) {
$usage['link'] = '<a href="' . $this->url()->fromRoute('apartment/general', ['apartment_id' => $usage['id']]) . '" target="_blank">
<span class="glyphicon glyphicon-share"></span> ' . $usage['name'] . '</a>';
}
if (!$generalInfo) {
Helper::setFlashMessage(['error' => 'Parking lot not found']);
return $this->redirect()->toRoute('parking/lots');
}
$textline = $generalInfo->getDirectionTextlineId();
$parkingPermit = $generalInfo->getParkingPermit();
$active = $generalInfo->isActive();
$viewModel->setVariables(['hasAMM' => $hasAMM, 'usages' => $usages]);
}
$uploadForm = new ParkingUpload('parking-permit');
$viewModel->setVariables(['parkingLotId' => $this->parkingLotId, 'form' => $form, 'textlineId' => $textline, 'parkingPermit' => $parkingPermit, 'isActive' => $active, 'uploadForm' => $uploadForm]);
return $viewModel;
}
示例5: __construct
public function __construct()
{
$event = $this->getEvent();
$this->viewModel = $event->getViewModel();
$sharedEvents = StaticEventManager::getInstance();
$sharedEvents->attach('Zend\\Mvc\\Controller\\AbstractActionController', MvcEvent::EVENT_DISPATCH, function (Event $event) {
// get view model for layout
$view = $event->getViewModel();
// assign locales information
$sm = $this->getServiceLocator();
$config = $sm->get('Configuration');
$view->setVariable('locale', $sm->get('translator')->getLocale());
$view->setVariable('locales', $config['locales']['list']);
// assign flashmessanger messages
$messages = $this->flashmessenger()->getSuccessMessages();
$view->setVariable('messages', $messages);
$info = $this->flashmessenger()->getInfoMessages();
$view->setVariable('info', $info);
$warnings = $this->flashmessenger()->getMessages();
$view->setVariable('warnings', $warnings);
$errors = $this->flashmessenger()->getErrorMessages();
$view->setVariable('errors', $errors);
// assign variables to action view
$this->viewModel->setVariables($view->getVariables());
});
}
示例6: onBootstrap
public function onBootstrap(EventInterface $e)
{
// Récupération des erreurs en ajoutant un callback qui affiche l'erreur coté serveur
$application = $e->getTarget();
$event = $application->getEventManager();
$event->attach(MvcEvent::EVENT_DISPATCH_ERROR, function (MvcEvent $e) {
error_log('DISPATCH_ERROR : ' . $e->getError());
error_log($e->getControllerClass() . ' ' . $e->getController());
});
$event->attach(MvcEvent::EVENT_RENDER_ERROR, function (MvcEvent $e) {
error_log('RENDER_ERROR : ' . $e->getError());
});
$event->attach(MvcEvent::EVENT_RENDER, function (MvcEvent $e) {
$services = $e->getApplication()->getServiceManager();
$session = $services->get('session');
$rightViewModel = new ViewModel();
if (!isset($session->user)) {
$form = $services->get('MiniModule\\Form\\Authentification');
$formUser = $services->get('MiniModule\\Form\\NewUser');
$rightViewModel->setVariables(array('form' => $form, 'newUserForm' => $formUser));
$rightViewModel->setTemplate('layout/form-auth');
} else {
$rightViewModel->setVariables(array('user' => $session->user));
$rightViewModel->setTemplate('layout/info-auth');
}
$view = $e->getViewModel();
// c'est le viewModel qui contient le layout (top viewModel)
$view->addChild($rightViewModel, 'formulaireAuth');
});
}
示例7: indexAction
public function indexAction()
{
/**
* @var \DDD\Service\Cubilis\Connection $cubilisConnectionService
* @var General $apartmentGeneralService
*/
$cubilisConnectionService = $this->getServiceLocator()->get('service_cubilis_connection');
$apartmentGeneralService = $this->getServiceLocator()->get('service_apartment_general');
$cubilisDetails = $apartmentGeneralService->getCubilisDetailsAsArray($this->apartmentId);
$form = new CubilisConnection($this->url()->fromRoute('apartment/channel-connection/save', ['apartment_id' => $this->apartmentId]));
$form->prepare();
$form->populateValues($cubilisDetails);
$formTemplate = 'form-templates/cubilis-connection';
$viewModelForm = new ViewModel();
$viewModelForm->setVariables(['form' => $form]);
$viewModelForm->setTemplate($formTemplate);
$rates = $apartmentGeneralService->getRoomRates($this->apartmentId);
$rateConnections = $cubilisConnectionService->getCubilisTypes($this->apartmentId, $rates);
$urlLinkRates = $this->url()->fromRoute('apartment/channel-connection/link', ['apartment_id' => $this->apartmentId]);
$apartmentOTAService = $this->getServiceLocator()->get('service_apartment_ota_distribution');
$apartmentOTAList = $apartmentOTAService->getOTAList($this->apartmentId);
$partnerList = $apartmentOTAService->getPartnerList();
$hasApartmentConnectionRole = false;
$auth = $this->getServiceLocator()->get('library_backoffice_auth');
if ($auth->hasRole(Roles::ROLE_APARTMENT_CONNECTION)) {
$hasApartmentConnectionRole = true;
}
$viewModel = new ViewModel();
$viewModel->setVariables(['apartmentId' => $this->apartmentId, 'apartmentStatus' => $this->apartmentStatus, 'rateConnections' => $rateConnections, 'rates' => $rates, 'urlLinkRates' => $urlLinkRates, 'cubilisDetails' => $cubilisDetails, 'apartmentOTAList' => $apartmentOTAList, 'partnerList' => $partnerList, 'OTAStatus' => Objects::getOTADistributionStatusList(), 'isCubilisConnecter' => $hasApartmentConnectionRole]);
// child view to render form
$viewModel->addChild($viewModelForm, 'formOutput');
$viewModel->setTemplate('apartment/channel-connection/index');
return $viewModel;
}
示例8: editAction
public function editAction()
{
$entityManager = $this->getOM();
$viewmodel = new ViewModel();
$ud = $this->zfcUserAuthentication()->getIdentity()->getId();
$staff = $this->getOM()->getRepository('Admin\\Entity\\Staff')->findOneBy(array('user' => $ud));
$id = $staff->getId();
if (!$id) {
return $this->redirect()->toRoute('teachers', array('controller' => 'teachers', 'action' => 'dashboard'));
}
$image = $staff->getImage();
$form = new StaffForm($entityManager);
$form->bind($staff);
$form->get('submit')->setAttribute('value', 'Edit');
$request = $this->getRequest();
if ($request->isPost()) {
$dataForm = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
$form->setData($dataForm);
//exclude section and year from being validated
$form->setValidationGroup(array('staff' => array('fname', 'lname', 'mname', 'mobile1', 'mobile2', 'twitter', 'facebook', 'paddress', 'raddress', 'country', 'email', 'state', 'lga', 'image', 'dob', 'sex', 'religion', 'nokName', 'nokRel', 'nokMobile')));
if ($form->isValid()) {
$data = $form->getData('staff')->getImage();
if (!$data) {
$staff->setImage($image);
}
$entityManager->persist($staff);
$entityManager->flush();
// Redirect to list of albums
return $this->redirect()->toRoute('teachers', array('controller' => 'students', 'action' => 'dashboard'));
}
}
$viewmodel->setVariables(array('form' => $form, 'id' => $id, 'image' => $image));
return $viewmodel;
}
示例9: comprasbyarticulovarianteAction
function comprasbyarticulovarianteAction()
{
//Cachamos los datos de la url
$idarticulovariante = $this->params()->fromQuery('idarticulovariante');
$descripcion = $this->params()->fromQuery('descripcion');
$modalName = 'modal-producto-' . $idarticulovariante . '-compras';
$producto = array();
$articuloVariante = \ArticulovarianteQuery::create()->findPk($idarticulovariante);
$producto['nombre'] = $articuloVariante->getArticulo()->getArticuloNombre();
$producto['descripcion'] = $descripcion;
$producto['imagen'] = $articuloVariante->getArticulovarianteImagen();
//Ahora las compras
$compras = array();
$compraDetalle = \OrdencompradetalleQuery::create()->filterByIdarticulovariante($idarticulovariante)->useOrdencompraQuery()->filterByIdproveedor(1, \Criteria::NOT_EQUAL)->endUse()->find();
foreach ($compraDetalle as $kcd => $vcd) {
$tmp = array();
$tmp['costo'] = $vcd->getOrdencompradetalleCosto();
$tmp['fecha'] = $vcd->getOrdencompra()->getOrdencompraFecha('d-m-Y');
$tmp['proveedor'] = $vcd->getOrdencompra()->getProveedor()->getProveedorNombre();
array_push($compras, $tmp);
}
//var_dump($this->flashMessenger()->getMessages());
$viewModel = new ViewModel();
$viewModel->setTerminal(true);
$viewModel->setVariables(array('modalName' => $modalName, 'producto' => $producto, 'compras' => $compras));
return $viewModel;
}
示例10: indexAction
public function indexAction()
{
$pageId = (int) $this->params()->fromRoute('pageId');
$lang = $this->params()->fromRoute('lang');
$queryParams = $this->params()->fromQuery();
if (!is_array($queryParams)) {
$queryParams = array();
}
$queryParams['lang'] = $lang;
$page = $this->fetchPage($pageId, $queryParams, true);
if ($page instanceof Page) {
$viewVariables = $page->getData();
$template = $page->getTemplate();
if ((bool) $queryParams['debug']) {
return new JsonModel($viewVariables);
}
if ($template->isValid()) {
$this->setPageAssets($template, $viewVariables);
$view = new ViewModel();
$view->setTemplate($template->getMainFile(false));
$view->setVariables($viewVariables);
$view->setTerminal(true);
return $view;
}
}
$this->getResponse()->setStatusCode(404);
}
示例11: indexAction
public function indexAction()
{
$viewModel = new ViewModel();
/* @var $userService \User\Service\User */
$userService = $this->getServiceLocator()->get('User\\Service\\User');
$user = $userService->getUser();
// $form = $this->getServiceLocator()->get('User\Form\ChangePassword');
$avatar = new \User\Form\ProfileFile('upload-file');
$translator = $this->getServiceLocator()->get('translator');
if (!file_exists(MEDIA_PATH . '/user')) {
mkdir(MEDIA_PATH . '/user');
chmod(MEDIA_PATH . '/user', 0777);
}
if (!file_exists(MEDIA_PATH . '/user/avatar')) {
mkdir(MEDIA_PATH . '/user/avatar');
chmod(MEDIA_PATH . '/user/avatar', 0777);
}
$files = scandir(MEDIA_PATH . '/user/avatar');
$fileavatar = '';
foreach ($files as $f) {
if ($this->user()->getIdentity() == explode('.', $f)[0]) {
$fileavatar = $f;
}
}
$message = '';
$viewModel->setVariables(['userService' => $userService, 'user' => $user, 'fileavatar' => $fileavatar, 'avatar' => $avatar, 'message' => $message]);
return $viewModel;
}
示例12: indexAction
public function indexAction()
{
$userResult = $this->getMpayManager()->getConnector()->userSearch($this->getMpayManager()->getAccessToken());
$viewModel = new ViewModel();
$viewModel->setVariables(array('users' => $userResult['data']['users']));
return $viewModel;
}
示例13: loginAction
/**
* Login action for backoffice..
*
* @return ViewModel
*/
public function loginAction()
{
$view = new ViewModel();
$form = $this->getServiceLocator()->get('FormElementManager')->get('admin.form.login');
$failed = null;
if ($this->getRequest()->isPost()) {
$data = $this->params()->fromPost();
$form->setData($data);
$logger = $this->getServiceLocator()->get('logger');
if ($form->isValid()) {
// Go to service and check credentials
$data = $form->getData();
$result = $this->getServiceLocator()->get('core.service.registration')->login($data['email'], $data['password']);
if ($result->isValid()) {
$session = new Container('locale');
$session->locale = $result->getIdentity()->getLanguage();
$logger->info('User ' . $result->getIdentity()->getNameSurname() . ' has been logged in to backoffice');
$this->redirect()->toUrl('/');
} else {
$failed = _('Authentication failed. Please check your credentials.');
$logger->info('Login attempt failed.', $data);
}
}
}
$view->setVariables(array('loginForm' => $form, 'failed' => $failed));
return $view;
}
示例14: indexAction
public function indexAction()
{
$this->_mainParam["data"]["id"] = $this->params("id");
$display = $this->params("display", "list");
$viewModel = new ViewModel();
//view chính
$bookView = new ViewModel();
//view -hiện danh sách book
$bookView->setTemplate('shop/category/' . $display);
//CATEGORY INFO
$categoryItem = $this->getTable()->getItem($this->_mainParam["data"]);
if (empty($categoryItem)) {
$this->redirect()->toRoute("shopRoute/default", array("controller" => "notice", "action" => "no-data"));
}
//BREADCRUMB
$listBreadcumb = $this->getTable()->listItem($categoryItem, array("task" => "list-breadcrumb"));
//LISTBOOK BY CATEGORY
$catIDs = $this->getTable()->listItem($categoryItem, array("task" => "list-id-category"));
$this->_mainParam["catIDs"] = $catIDs;
$bookTable = $this->getServiceLocator()->get("shopBookTable");
$listBook = $bookTable->listItem($this->_mainParam, array("task" => "list-book-by-category"));
$totalItem = $bookTable->countItem($catIDs, array("task" => "count-book"));
$viewModel->addChild($bookView, "list_book_category");
$bookView->setVariables(array("listBook" => $listBook));
$viewModel->setVariables(array("categoryItem" => $categoryItem, "listBreadcumb" => $listBreadcumb, "paginator" => \ZendVN\Paginator\Paginator::createPagination($totalItem, $this->_configPaginator), "displayType" => $display, "paramSetting" => $this->_mainParam));
return $viewModel;
}
示例15: indexAction
/**
* @return \Zend\View\Model\ViewModel
*/
public function indexAction()
{
/**
* @var \DDD\Service\Apartment\General $apartmentGeneralService
*/
$apartmentGeneralService = $this->getServiceLocator()->get('service_apartment_general');
$form = $this->getForm();
$form->prepare();
$generalInfo = false;
if ($this->apartmentId) {
$generalInfo = $apartmentGeneralService->getApartmentGeneral($this->apartmentId);
$form->populateValues(['id' => $this->apartmentId, 'apartment_name' => $generalInfo['name'], 'status' => $generalInfo['status'], 'room_count' => $generalInfo['room_count'], 'square_meters' => $generalInfo['square_meters'], 'max_capacity' => $generalInfo['max_capacity'], 'bedrooms' => $generalInfo['bedroom_count'], 'bathrooms' => $generalInfo['bathroom_count'], 'chekin_time' => date('H:i', strtotime($generalInfo['check_in'])), 'chekout_time' => date('H:i', strtotime($generalInfo['check_out'])), 'general_description_textline' => $generalInfo['general_descr'], 'general_description' => $generalInfo['general_description']]);
} else {
// Pre-filled default values when adding apartment
$form->populateValues(['chekin_time' => '15:00', 'chekout_time' => '11:00']);
}
// passing form and map to the view
$viewModelForm = new ViewModel();
$viewModelForm->setVariables(['form' => $form, 'date_created' => isset($generalInfo['create_date']) ? $generalInfo['create_date'] : '', 'apartmentStatus' => $this->apartmentStatus]);
$viewModelForm->setTemplate('form-templates/general');
$viewModel = new ViewModel();
$viewModel->setVariables(['apartment' => $generalInfo, 'apartmentId' => $this->apartmentId, 'apartmentStatus' => $this->apartmentStatus]);
// child view to render form
$viewModel->addChild($viewModelForm, 'formOutput');
$viewModel->setTemplate('apartment/general/index');
return $viewModel;
}