本文整理汇总了PHP中Zend\View\Model\ViewModel::getVariable方法的典型用法代码示例。如果您正苦于以下问题:PHP ViewModel::getVariable方法的具体用法?PHP ViewModel::getVariable怎么用?PHP ViewModel::getVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\Model\ViewModel
的用法示例。
在下文中一共展示了ViewModel::getVariable方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getVariable
public function getVariable($name, $default = null)
{
if ($name == 'rowsData') {
$bodyRowsData = parent::getVariable('rowsData');
if (!$bodyRowsData instanceof \ArrayObject) {
throw new \RuntimeException('Variable result must be instance of ' . \ArrayObject::class . '. ' . gettype($bodyRowsData) . ' given');
}
$result = [];
foreach ($bodyRowsData as $rowData) {
if (!$rowData instanceof EntityInterface) {
throw new \RuntimeException('Variable result must be instance of ' . EntityInterface::class . '. ' . gettype($rowData) . ' given');
}
$row = $rowData->extract();
$result[] = $row;
}
return $result;
}
if ($name == 'headRows') {
$columnsConf = parent::getVariable('columns');
$result = [];
$row = [];
foreach ($columnsConf as $columnConf) {
$row[] = $columnConf['head'];
}
$result[] = $row;
return $result;
}
return parent::getVariable($name, $default);
}
示例2: getVariable
public function getVariable($name, $default = null)
{
if ($name == 'parentCallVar') {
return 'parentCallVarValue';
}
return parent::getVariable($name, $default);
}
示例3: getVariable
public function getVariable($name, $default = null)
{
$validCriteria = parent::getVariable('validCriteria');
if (!empty($validCriteria[$name])) {
return $validCriteria[$name];
}
return parent::getVariable($name, $default);
}
示例4: getVariable
public function getVariable($name, $default = null)
{
if ($name == 'name') {
$myself = $this->fetchMyself();
return $myself['name'];
}
return parent::getVariable($name, $default);
}
示例5: getVariable
public function getVariable($name, $default = null)
{
if ($name == 'routeParams') {
$id = parent::getVariable('id');
return ['id' => $id];
}
return parent::getVariable($name, $default);
}
示例6: getVariable
public function getVariable($name, $default = null)
{
if ($name != 'options') {
return parent::getVariable($name, $default);
}
$options = [0 => 'All'];
foreach ($this->config as $name => $queue) {
$options[$name] = $name;
}
return $options;
}
示例7: getVariable
public function getVariable($name, $default = null)
{
$entity = parent::getVariable('result');
if ($entity) {
$data = $entity->extract();
if (isset($data[$name])) {
return $data[$name];
}
}
return parent::getVariable($name, $default);
}
示例8: getVariable
public function getVariable($name, $default = null)
{
$row = parent::getVariable('row', []);
if ($name == 'createdDt' || $name == 'updatedDt') {
return date("Y-m-d H:i:s", strtotime($row[$name]));
}
if (isset($row[$name])) {
return $row[$name];
}
return parent::getVariable($name, $default);
}
示例9: getVariable
public function getVariable($name, $default = null)
{
$variable = parent::getVariable($name, $default);
if ($name == 'result') {
if ($variable !== null) {
if (!$variable instanceof EntityInterface) {
throw new \RuntimeException('Variable result must be instance of ' . EntityInterface::class . '. ' . gettype($variable) . ' given');
}
$variable = $variable->extract();
}
}
return $variable;
}
示例10: getVariable
public function getVariable($name, $default = null)
{
if ($name == 'country') {
if (self::$countries === null) {
self::$countries = $this->fetchCountries(self::$countryIds);
}
$countryId = $this->getVariable('countryId');
if (isset(self::$countries[$countryId]['name'])) {
return self::$countries[$countryId]['name'];
}
}
return parent::getVariable($name, $default);
}
示例11: getVariable
public function getVariable($name, $default = null)
{
if ($name == 'name' || $name == 'countryId') {
if (self::$users === null) {
self::$users = $this->fetchUsers(self::$userIds);
}
$userId = $this->getVariable('userId');
if (isset(self::$users[$userId][$name])) {
return self::$users[$userId][$name];
}
}
return parent::getVariable($name, $default);
}
示例12: getVariable
public function getVariable($name, $default = null)
{
$variable = parent::getVariable($name, $default);
if ($name == 'result') {
if ($variable !== null) {
if (!$variable instanceof \ArrayObject) {
throw new \RuntimeException('Variable result must be instance of ' . \ArrayObject::class . '. ' . gettype($variable) . ' given');
}
$result = [];
foreach ($variable as $entry) {
if (!$entry instanceof EntityInterface) {
throw new \RuntimeException('Variable result must be instance of ' . EntityInterface::class . '. ' . gettype($entry) . ' given');
}
$result[] = $entry->extract();
}
return $result;
}
}
return $variable;
}
示例13: getVariable
public function getVariable($name, $default = null)
{
$changes = parent::getVariable('changes');
if (isset($changes[$name])) {
return $changes[$name];
}
if (strpos($name, 'changesErrors:') === 0) {
$changesErrors = parent::getVariable('changesErrors', []);
if (!empty($changesErrors)) {
$explodedName = explode(':', $name);
if (isset($explodedName[1])) {
$elementName = $explodedName[1];
if (isset($changesErrors[$elementName])) {
return $changesErrors[$elementName];
}
}
}
}
return parent::getVariable($name, $default);
}
示例14: EventHandler
public function EventHandler(Console\Event $pEvent)
{
try {
$console = $this->getServiceLocator()->get('console');
$config = $this->getServiceLocator()->get('Config');
if (true == $pEvent->getVerboseFlag()) {
$console->write(' --------------- ', ColorInterface::LIGHT_GREEN);
$console->writeLine('-----------------------------------------------------------', ColorInterface::YELLOW);
$console->write(" [Listener] ", ColorInterface::LIGHT_GREEN);
$console->writeLine(__CLASS__, ColorInterface::YELLOW);
$console->write(' --------------- ', ColorInterface::LIGHT_GREEN);
$console->writeLine('-----------------------------------------------------------', ColorInterface::YELLOW);
}
if (true == $pEvent->getVerboseFlag()) {
$console->write(" [Template Key] ");
$console->writeLine($this->mTemplateKey, ColorInterface::YELLOW);
}
// create the view model for the vhost template
$view = new ViewModel();
$view->setTemplate($this->mTemplateKey);
$vhost_config = $config['Installation']['Vhost'];
$server = $vhost_config['Server'];
$prefix = $server['Prefix'];
$region = $server['Region'];
$domain = $server['Domain'];
$suffix = $server['Suffix'];
$view->setVariable('ServerName', $prefix . $region . $domain . $suffix);
$public = $server['PublicFolder'];
$view->setVariable('DocumentRoot', getcwd() . '/' . $public);
$view->setVariable('ApplicationEnv', $pEvent->getEnvironment());
$view->setVariable('Config', $vhost_config);
if (true == $pEvent->getVerboseFlag()) {
$console->write(" [Server Name] ");
$console->writeLine($view->getVariable('ServerName'), ColorInterface::YELLOW);
$console->write(" [Document Root] ");
$console->writeLine($view->getVariable('DocumentRoot'), ColorInterface::YELLOW);
$console->write(" [Environment] ");
$console->writeLine($view->getVariable('ApplicationEnv'), ColorInterface::YELLOW);
}
// setup specific configurations
$view->setVariable('ApacheLogDir', $vhost_config['ApacheLog']);
$view->setVariable('UseSyslog', $vhost_config['UseSysLog']);
$view->setVariable('Ports', $vhost_config['Ports']);
$view->setVariable('CorsOrigin', false);
if (array_key_exists('CorsOrigin', $config['Installation'])) {
$cors = $config['Installation']['CorsOrigin'];
if (false === is_array($cors)) {
throw new Exception('CorsOrigin configuration must be an array.');
}
$origin_list = implode('|', $cors);
$view->setVariable('CorsOrigin', 'http(s)?://(' . $origin_list . ')');
}
/**
* Create a template map resolver from the template map in the config
* file.
* Using that we create a renderer that will parse the zf2 view
* template like an ordinary template, so that we can get back its
* contents
*/
$map = new TemplateMapResolver($config['view_manager']['template_map']);
$renderer = new PhpRenderer();
$renderer->setResolver($map);
// Rewrite/modsec rule additions
$rewritePreView = new ViewModel();
$rewritePreView->setTemplate($this->mRewriteRulesPreTemplateKey);
$rewritePreView->setVariable('Config', $vhost_config);
$view->setVariable('RewritePreRules', $renderer->render($rewritePreView));
$rewritePostView = new ViewModel();
$rewritePostView->setTemplate($this->mRewriteRulesPostTemplateKey);
$rewritePostView->setVariable('Config', $vhost_config);
$view->setVariable('RewritePostRules', $renderer->render($rewritePostView));
$modSec = new ViewModel();
$modSec->setTemplate($this->mModsecTemplateKey);
$modSec->setVariable('Config', $vhost_config);
$view->setVariable('ModSecRules', $renderer->render($modSec));
if (true == $pEvent->getVerboseFlag()) {
$console->write(" [View Template] ");
$console->writeLine(realpath($map->get($this->mTemplateKey)), ColorInterface::YELLOW);
}
// write the vhost file here....
$vhost_extension = $server['Extension'];
$vhost_path = $server['Path'];
$vhost_filename = $view->getVariable('ServerName') . '.' . $vhost_extension;
$vhost_file = $vhost_path . $vhost_filename;
if (true == $pEvent->getVerboseFlag()) {
$console->write(" [Apache VHost] ");
$console->writeLine($vhost_file, ColorInterface::YELLOW);
}
if (false === is_dir($vhost_path)) {
$result = mkdir($vhost_path, 0775, true);
if (true === $result) {
if (true == $pEvent->getVerboseFlag()) {
$console->write(" [NOTICE] ", ColorInterface::LIGHT_CYAN);
$console->writeLine("Vhost directory has been created.", ColorInterface::CYAN);
}
} else {
if (true == $pEvent->getVerboseFlag()) {
$console->write(" [Failure] ", ColorInterface::RED);
$console->writeLine('Failed to create vhost directory, ' . $vhost_path . PHP_EOL, ColorInterface::RED);
}
//.........这里部分代码省略.........