本文整理匯總了PHP中Zend\View\Model\JsonModel::setVariable方法的典型用法代碼示例。如果您正苦於以下問題:PHP JsonModel::setVariable方法的具體用法?PHP JsonModel::setVariable怎麽用?PHP JsonModel::setVariable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\View\Model\JsonModel
的用法示例。
在下文中一共展示了JsonModel::setVariable方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: folderPermissionsAction
public function folderPermissionsAction()
{
$jsonModel = new JsonModel();
foreach ($this->config['component'] as $component) {
if (@$component['image_path'] || @$component['video_path'] || @$component['file_path']) {
if (isset($component['image_path']) && !empty($component['image_path'])) {
if (!file_exists($component['image_path'])) {
$oldmask = umask(0);
mkdir($component['image_path'], 0777);
umask($oldmask);
$jsonModel->setVariable($component['image_path'], $component['image_path']);
}
}
if (isset($component['video_path']) && !empty($component['video_path'])) {
if (!file_exists($component['video_path'])) {
$oldmask = umask(0);
mkdir($component['video_path'], 0777);
umask($oldmask);
$jsonModel->setVariable($component['video_path'], $component['video_path']);
}
}
if (isset($component['file_path']) && !empty($component['file_path'])) {
if (!file_exists($component['file_path'])) {
$oldmask = umask(0);
mkdir($component['file_path'], 0777);
umask($oldmask);
$jsonModel->setVariable($component['file_path'], $component['file_path']);
}
}
}
}
$response = $this->getResponse();
$response->setContent(json_encode($jsonModel->getVariables()));
return $response;
}
示例2: indexAction
/**
* @return JsonModel
*/
public function indexAction()
{
$json = new JsonModel();
$json->setVariable('nav', $this->navigation->getData());
$json->setVariable('menu', $this->navigation->getMenuItems());
$json->setVariable('main', $this->navigation->getMainItems());
$json->setVariable('titles', $this->navigation->getTitles());
return $json;
}
示例3: startAction
/**
* Index Action
*
* @return JsonModel
*/
public function startAction()
{
$this->log->clear();
$json = new JsonModel();
try {
$data = array_merge($this->importDeploymentConfigForm(), $this->importUserConfigForm(), $this->importAdminUserForm());
$this->installer->install($data);
$json->setVariable('key', $this->installer->getInstallInfo()[SetupConfigOptionsList::KEY_ENCRYPTION_KEY]);
$json->setVariable('success', true);
$json->setVariable('messages', $this->installer->getInstallInfo()[Installer::INFO_MESSAGE]);
} catch (\Exception $e) {
$this->log->logError($e);
$json->setVariable('success', false);
}
return $json;
}
示例4: setErrors
/**
* @param mixed $errors
*/
public function setErrors(array $errors)
{
$this->errors = $errors;
if (empty($errors)) {
$this->setSuccess(true);
} else {
$this->setSuccess(false);
}
parent::setVariable('errors', $errors);
return $this;
}
示例5: jsAction
/**
* Apresentar Configurações
*
* @return JsonModel Modelo de Visualização
*/
public function jsAction()
{
// Capturar Configurações
$configs = [];
// Inicialização
$view = new JsonModel($configs);
// Requisição
$request = $this->getRequest();
// Tipagem Correta?
if (!$request instanceof Http\PhpEnvironment\Request) {
throw new Exception('Invalid Request');
}
// Configurar Caminho Base
$view->setVariable('basePath', $this->getRequest()->getBaseUrl());
// Configurar Linguagem de Localização
$view->setVariable('locale', $this->getLocale());
// Configurar Variável
$view->setJsonpCallback('$.application.setConfigs');
// Apresentação
return $view;
}
示例6: deleteAction
public function deleteAction()
{
$jsonModel = new JsonModel();
$id = (int) $this->params()->fromPost('id');
if ($id > 0) {
$result = $this->getNoteTable()->delete($id);
} else {
$result = false;
}
$jsonModel->setVariable("result", $result);
return $jsonModel;
}
示例7: deleteAction
public function deleteAction()
{
$id = $this->params()->fromQuery('id');
$em = $this->getEntityManager();
$jsonModel = new JsonModel();
/** @var $res \Base\Entity\Competition */
$res = $em->getRepository('Base\\Entity\\User')->find($id);
$em->remove($res);
$em->flush();
$jsonModel->setVariable('success', true);
return $jsonModel;
}
示例8: indexAction
/**
* @return JsonModel
*/
public function indexAction()
{
$this->logger->clear();
$data = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
$this->config->setConfigData($data);
$this->config->install();
$this->setupFactory->setConfig($this->config->getConfigData());
$moduleNames = array_keys($this->moduleList);
foreach ($moduleNames as $moduleName) {
$setup = $this->setupFactory->create($moduleName);
$setup->applyUpdates();
$this->logger->logSuccess($moduleName);
}
$this->logger->logSuccess('Artifact');
// Set data to config
$setup->addConfigData('web/seo/use_rewrites', isset($data['config']['rewrites']['allowed']) ? $data['config']['rewrites']['allowed'] : 0);
$setup->addConfigData('web/unsecure/base_url', isset($data['config']['address']['web']) ? $data['config']['address']['web'] : '{{unsecure_base_url}}');
$setup->addConfigData('web/secure/use_in_frontend', isset($data['config']['https']['front']) ? $data['config']['https']['front'] : 0);
$setup->addConfigData('web/secure/base_url', isset($data['config']['address']['web']) ? $data['config']['address']['web'] : '{{secure_base_url}}');
$setup->addConfigData('web/secure/use_in_adminhtml', isset($data['config']['https']['admin']) ? $data['config']['https']['admin'] : 0);
$setup->addConfigData('general/locale/code', isset($data['store']['language']) ? $data['store']['language'] : 'en_US');
$setup->addConfigData('general/locale/timezone', isset($data['store']['timezone']) ? $data['store']['timezone'] : 'America/Los_Angeles');
$currencyCode = isset($data['store']['currency']) ? $data['store']['currency'] : 'USD';
$setup->addConfigData('currency/options/base', $currencyCode);
$setup->addConfigData('currency/options/default', $currencyCode);
$setup->addConfigData('currency/options/allow', $currencyCode);
// Create administrator account
$this->adminAccountFactory->setConfig($this->config->getConfigData());
$adminAccount = $this->adminAccountFactory->create($setup);
$adminAccount->save();
$this->logger->logSuccess('Admin User');
if ($data['config']['encrypt']['type'] == 'magento') {
$key = md5($this->random->getRandomString(10));
} else {
$key = $data['config']['encrypt']['key'];
}
$this->config->replaceTmpEncryptKey($key);
$this->config->replaceTmpInstallDate(date('r'));
$phpPath = $this->phpExecutablePath();
exec($phpPath . 'php -f ' . escapeshellarg($this->systemConfig->create()->getMagentoBasePath() . '/dev/shell/run_data_fixtures.php'), $output, $exitCode);
if ($exitCode !== 0) {
$outputMsg = implode(PHP_EOL, $output);
$this->logger->logError(new \Exception('Data Update Failed with Exit Code: ' . $exitCode . PHP_EOL . $outputMsg));
$this->json->setVariable('success', false);
} else {
$this->logger->logSuccess('Data Updates');
$this->json->setVariable('success', true);
}
$this->json->setVariable('key', $key);
return $this->json;
}
示例9: translateAction
/**
* Translate
*
* @return JsonModel
*/
public function translateAction()
{
$model = new JsonModel();
$namespace = $this->getEvent()->getRouteMatch()->getParam('namespace', 'default');
$locale = $this->getEvent()->getRouteMatch()->getParam('locale', null);
if ($this->getRequest()->getMethod() === 'GET') {
$params = $this->getRequest()->getQuery();
if (array_key_exists('callback', $params)) {
$model->setJsonpCallback($params['callback']);
}
} else {
$params = $this->getRequest()->getPost();
}
if (!isset($params['key'])) {
$model->setVariable('error', 'No key[] given');
}
if (!is_array($params['key'])) {
$params['key'] = array($params['key']);
}
foreach ($params['key'] as $key) {
$model->setVariable($key, $this->getTranslator()->translate($key, $namespace, $locale));
}
return $model;
}
示例10: validFormAction
public function validFormAction()
{
$jsonModel = new JsonModel();
$formData = $this->params()->fromPost();
$formManager = $this->getServiceLocator()->get('formElementManager');
$form = $formManager->get('addressForm');
$form->setData($formData);
$result = $form->isValid();
$messages = [];
if (!$result) {
$messages = $form->getMessages();
}
$jsonModel->setVariable('jsonData', ['isValid' => $result, 'messages' => $messages]);
$this->getResponse()->getHeaders()->addHeaderLine('content-type', 'application/json');
return $jsonModel;
}
示例11: productSearchSerialAction
public function productSearchSerialAction()
{
$product = $this->params()->fromPost('product');
$jsonModel = new JsonModel();
$productList = array();
if (isset($product) && !empty($product)) {
$products = $this->getProductTable()->getBySerial($product);
foreach ($products as $key => $productValue) {
//if(stristr($productValue,$product)){
$productList[$key] = $productValue;
//}
}
$jsonModel->setVariable("products", $productList);
return $jsonModel;
}
}
示例12: updaterolefeatureAction
public function updaterolefeatureAction()
{
$actionId = $this->getRequest()->getPost('actionId');
$roleId = $this->getRequest()->getPost('roleId');
$value = $this->getRequest()->getPost('value');
$jsonModel = new JsonModel();
if (in_array($roleId, array(\User\Model\User::ROLE_ADMIN, \User\Model\User::ROLE_SUPERADMIN, \User\Model\User::ROLE_MEMBER, \User\Model\User::ROLE_GUEST))) {
$jsonModel->setVariables(array('code' => 0, 'messages' => ['Không thể điều chỉnh quyền này của nhóm người dùng này']));
return $jsonModel;
}
$role = new \System\Model\Role();
$role->setId($roleId);
$roleMapper = $this->getServiceLocator()->get('\\System\\Model\\RoleMapper');
if (!$roleMapper->get($role)) {
$jsonModel->setVariables(array('code' => 0, 'messages' => ['Không tìm thấy quyền này']));
return $jsonModel;
}
$action = new Action();
$action->setId($actionId);
$actionMapper = $this->getServiceLocator()->get('\\System\\Model\\ActionMapper');
if (!$actionMapper->get($action)) {
$jsonModel->setVariables(array('code' => 0, 'messages' => ['Không tìm thấy action này']));
return $jsonModel;
}
$roleFeature = new \System\Model\Role\Feature();
$roleFeature->setActionId($actionId);
$roleFeature->setRoleId($roleId);
$roleFeatureMapper = $this->getServiceLocator()->get('\\System\\Model\\Role\\FeatureMapper');
if ($value) {
if (!$roleFeatureMapper->isExisted($roleFeature)) {
$roleFeature->setCreatedById($this->user()->getIdentity());
$roleFeature->setCreatedDateTime(DateBase::getCurrentDateTime());
$roleFeatureMapper->save($roleFeature);
}
} else {
if ($roleFeatureMapper->isExisted($roleFeature)) {
$roleFeatureMapper->delete($roleFeature);
}
}
$jsonModel->setVariable('code', 1);
return $jsonModel;
}
示例13: groupAction
/**
* Return group members in JSON
*
* @return \Zend\View\Model\ViewModel
*/
public function groupAction()
{
$jsonModel = new JsonModel(array('success' => false));
$groupId = $this->getRequest()->getPost('group');
if (empty($groupId) || !is_numeric($groupId)) {
return $jsonModel;
}
$groupMembers = $this->groupService->fetchGroupMembers($groupId, $this->identity->getId());
$jsonModel->setVariable('success', true);
$jsonModel->setVariable('groupMembers', $groupMembers);
return $jsonModel;
}
示例14: deleteFileAction
public function deleteFileAction()
{
$id = (int) $this->params()->fromQuery('id');
$em = $this->getEntityManager();
/** @var $res \base\Entity\PageFile */
$res = $em->getRepository('Base\\Entity\\PageFile')->find($id);
$jsonModel = new JsonModel();
if ($res) {
$fileName = $res->getFileName();
$filePath = $this->FileStorePath() . '/' . $fileName;
if (is_file($filePath)) {
unlink($filePath);
}
$em->remove($res);
$em->flush();
$jsonModel->setVariable('success', true);
} else {
$jsonModel->setVariable('success', false);
}
return $jsonModel;
}
示例15: searchUsersAction
/**
* Helper action for userselect form element.
*
* @return \Zend\View\Model\JsonModel
*/
public function searchUsersAction()
{
if (!$this->getRequest()->isXmlHttpRequest()) {
throw new \RuntimeException('This action must be called via ajax request');
}
$model = new JsonModel();
$query = $this->params()->fromPost('query', false);
if (false === $query) {
$result = array();
} else {
$services = $this->getServiceLocator();
$repositories = $services->get('repositories');
$repository = $repositories->get('Auth/User');
$users = $repository->findByQuery($query);
$userFilter = $services->get('filtermanager')->get('Auth/Entity/UserToSearchResult');
$filterFunc = function ($user) use($userFilter) {
return $userFilter->filter($user);
};
$result = array_values(array_map($filterFunc, $users->toArray()));
}
$model->setVariable('users', $result);
return $model;
}