当前位置: 首页>>代码示例>>PHP>>正文


PHP eZTemplate::variable方法代码示例

本文整理汇总了PHP中eZTemplate::variable方法的典型用法代码示例。如果您正苦于以下问题:PHP eZTemplate::variable方法的具体用法?PHP eZTemplate::variable怎么用?PHP eZTemplate::variable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eZTemplate的用法示例。


在下文中一共展示了eZTemplate::variable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSetScopeSafeVariable

    /**
     * Test for issue #12285
     * Variables set by functions handled by eZObjectForwarder (like attribute_view_gui) are not scope safe.
     * The patch for this issue ensures that, if requested, a template variable can be backed up in a safe namespace
     * (same var name but different namespace), so that it can't be overridden
     * @param string $varName
     * @param string $val
     * @param string $namespace
     * @link http://issues.ez.no/12285
     * @group issue12285
     */
    public function testSetScopeSafeVariable()
    {
        $namespace = "myNamespace";
        $varName = "foo";
        $aVal = array( "bar", "baz", "biz" ); // Simulate 3 level of nesting
        $previousVal = null;
        $nestingLevel = 0;

        // Try to set different values to a tpl variable to emulate a nested set like described in the issue
        foreach ( $aVal as $val )
        {
            $this->tpl->setVariable( $varName, $val, $namespace, true );
            self::assertEquals( $val, $this->tpl->variable( $varName, $namespace ), "Template variable has not been correctly set" );

            if ( !empty( $previousVal ) )
            {
                $safeNamespace = $namespace . str_repeat( ":safe", $nestingLevel );
                self::assertEquals( $previousVal, $this->tpl->variable( $varName, $safeNamespace ), "Template variable has not been backed up in a safe namespace" );
            }

            $previousVal = $val;
            $nestingLevel++;
        }

        // Now unset the tpl variables and check that they are well restored
        $aUnsetVal = array_reverse( $aVal );
        // Nesting level must decrease to 0, so decrease it first
        $nestingLevel -= 1;
        foreach ( $aUnsetVal as $val )
        {
            $safeNamespace = $namespace . str_repeat( ":safe", $nestingLevel );
            $this->tpl->unsetVariable( $varName, $namespace );
            self::assertNull( $this->tpl->variable( $varName, $safeNamespace ), "Backed up tpl variable has not been deleted" );

            $nestingLevel--;
            // Check that backed up value is correctly restored
            if ( $nestingLevel >= 0 )
            {
                self::assertEquals( $aVal[$nestingLevel], $this->tpl->variable( $varName, $namespace ), "Backed up tpl variable has not been properly restored from safe namespace" );
            }
            else
            {
                self::assertNull( $this->tpl->variable( $varName, $namespace ), "Template variable has not been unset" );
            }
        }
    }
开发者ID:robinmuilwijk,项目名称:ezpublish,代码行数:57,代码来源:eztemplate_regression.php

示例2: generateNodeViewData

 /**
  * Generate result data for a node view
  *
  * @param eZTemplate $tpl
  * @param eZContentObjectTreeNode $node
  * @param eZContentObject $object
  * @param bool|string $languageCode
  * @param string $viewMode
  * @param int $offset
  * @param array $viewParameters
  * @param bool|array $collectionAttributes
  * @param bool $validation
  * @return array Result array for view
  */
 static function generateNodeViewData(eZTemplate $tpl, eZContentObjectTreeNode $node, eZContentObject $object, $languageCode, $viewMode, $offset, array $viewParameters = array('offset' => 0, 'year' => false, 'month' => false, 'day' => false), $collectionAttributes = false, $validation = false)
 {
     $section = eZSection::fetch($object->attribute('section_id'));
     if ($section) {
         $navigationPartIdentifier = $section->attribute('navigation_part_identifier');
         $sectionIdentifier = $section->attribute('identifier');
     } else {
         $navigationPartIdentifier = null;
         $sectionIdentifier = null;
     }
     $keyArray = array(array('object', $object->attribute('id')), array('node', $node->attribute('node_id')), array('parent_node', $node->attribute('parent_node_id')), array('class', $object->attribute('contentclass_id')), array('class_identifier', $node->attribute('class_identifier')), array('view_offset', $offset), array('viewmode', $viewMode), array('remote_id', $object->attribute('remote_id')), array('node_remote_id', $node->attribute('remote_id')), array('navigation_part_identifier', $navigationPartIdentifier), array('depth', $node->attribute('depth')), array('url_alias', $node->attribute('url_alias')), array('class_group', $object->attribute('match_ingroup_id_list')), array('state', $object->attribute('state_id_array')), array('state_identifier', $object->attribute('state_identifier_array')), array('section', $object->attribute('section_id')), array('section_identifier', $sectionIdentifier));
     $parentClassID = false;
     $parentClassIdentifier = false;
     $parentNodeRemoteID = false;
     $parentObjectRemoteID = false;
     $parentNode = $node->attribute('parent');
     if (is_object($parentNode)) {
         $parentNodeRemoteID = $parentNode->attribute('remote_id');
         $keyArray[] = array('parent_node_remote_id', $parentNodeRemoteID);
         $parentObject = $parentNode->attribute('object');
         if (is_object($parentObject)) {
             $parentObjectRemoteID = $parentObject->attribute('remote_id');
             $keyArray[] = array('parent_object_remote_id', $parentObjectRemoteID);
             $parentClass = $parentObject->contentClass();
             if (is_object($parentClass)) {
                 $parentClassID = $parentClass->attribute('id');
                 $parentClassIdentifier = $parentClass->attribute('identifier');
                 $keyArray[] = array('parent_class', $parentClassID);
                 $keyArray[] = array('parent_class_identifier', $parentClassIdentifier);
             }
         }
     }
     $res = eZTemplateDesignResource::instance();
     $res->setKeys($keyArray);
     if ($languageCode) {
         $oldLanguageCode = $node->currentLanguage();
         $node->setCurrentLanguage($languageCode);
     }
     $tpl->setVariable('node', $node);
     $tpl->setVariable('viewmode', $viewMode);
     $tpl->setVariable('language_code', $languageCode);
     if (isset($viewParameters['_custom'])) {
         foreach ($viewParameters['_custom'] as $customVarName => $customValue) {
             $tpl->setVariable($customVarName, $customValue);
         }
         unset($viewParameters['_custom']);
     }
     $tpl->setVariable('view_parameters', $viewParameters);
     $tpl->setVariable('collection_attributes', $collectionAttributes);
     $tpl->setVariable('validation', $validation);
     $tpl->setVariable('persistent_variable', false);
     $parents = $node->attribute('path');
     $path = array();
     $titlePath = array();
     foreach ($parents as $parent) {
         $path[] = array('text' => $parent->attribute('name'), 'url' => '/content/view/full/' . $parent->attribute('node_id'), 'url_alias' => $parent->attribute('url_alias'), 'node_id' => $parent->attribute('node_id'));
     }
     $titlePath = $path;
     $path[] = array('text' => $object->attribute('name'), 'url' => false, 'url_alias' => false, 'node_id' => $node->attribute('node_id'));
     $titlePath[] = array('text' => $object->attribute('name'), 'url' => false, 'url_alias' => false);
     $tpl->setVariable('node_path', $path);
     $event = ezpEvent::getInstance();
     $event->notify('content/pre_rendering', array($node, $tpl, $viewMode));
     $Result = array();
     $Result['content'] = $tpl->fetch('design:node/view/' . $viewMode . '.tpl');
     $Result['view_parameters'] = $viewParameters;
     $Result['path'] = $path;
     $Result['title_path'] = $titlePath;
     $Result['section_id'] = $object->attribute('section_id');
     $Result['node_id'] = $node->attribute('node_id');
     $Result['navigation_part'] = $navigationPartIdentifier;
     $contentInfoArray = array();
     $contentInfoArray['object_id'] = $object->attribute('id');
     $contentInfoArray['node_id'] = $node->attribute('node_id');
     $contentInfoArray['parent_node_id'] = $node->attribute('parent_node_id');
     $contentInfoArray['class_id'] = $object->attribute('contentclass_id');
     $contentInfoArray['class_identifier'] = $node->attribute('class_identifier');
     $contentInfoArray['remote_id'] = $object->attribute('remote_id');
     $contentInfoArray['node_remote_id'] = $node->attribute('remote_id');
     $contentInfoArray['offset'] = $offset;
     $contentInfoArray['viewmode'] = $viewMode;
     $contentInfoArray['navigation_part_identifier'] = $navigationPartIdentifier;
     $contentInfoArray['node_depth'] = $node->attribute('depth');
     $contentInfoArray['url_alias'] = $node->attribute('url_alias');
     $contentInfoArray['current_language'] = $object->attribute('current_language');
     $contentInfoArray['language_mask'] = $object->attribute('language_mask');
//.........这里部分代码省略.........
开发者ID:CG77,项目名称:ezpublish-legacy,代码行数:101,代码来源:eznodeviewfunctions.php

示例3: setPersistentArray

 /**
  * Function for setting values to deal with persistent_variable either from
  * template or internally on {@link self::$persistentVariable}
  *
  * @internal
  * @param string $key Key to store values on
  * @param string|array $value Value(s) to store
  * @param eZTemplate $tpl Template object to get values from
  * @param bool $append Append or prepend value?
  * @param bool $arrayUnique Make sure array is unique to remove duplicates
  * @param bool $returnArrayDiff Return diff against existing values instead of resulting array
  * @param bool $override Override/Wipe out values or merge?
  * @return array
  */
 public static function setPersistentArray($key, $value, eZTemplate $tpl, $append = true, $arrayUnique = false, $returnArrayDiff = false, $override = false)
 {
     $isPageLayout = false;
     $persistentVariable = array();
     if ($tpl->hasVariable('module_result')) {
         $isPageLayout = true;
         $moduleResult = $tpl->variable('module_result');
     }
     if (isset($moduleResult['content_info']['persistent_variable'])) {
         $persistentVariable = $moduleResult['content_info']['persistent_variable'];
     } else {
         if (!$isPageLayout && $tpl->hasVariable('persistent_variable')) {
             $persistentVariable = $tpl->variable('persistent_variable');
         } else {
             if (self::$persistentVariable !== null) {
                 $persistentVariable = self::$persistentVariable;
             }
         }
     }
     if ($persistentVariable === false || !is_array($persistentVariable)) {
         // Give warning if value is not array as we depend on it
         if (!$isPageLayout && $persistentVariable) {
             eZDebug::writeError('persistent_variable was not an array and where cleared, see ezjscore requriments!', __METHOD__);
         }
         $persistentVariable = array();
     }
     // make a copy in case we need to diff value in the end
     $persistentVariableCopy = $persistentVariable;
     if (!$override) {
         if (isset($persistentVariable[$key]) && is_array($persistentVariable[$key])) {
             if (is_array($value)) {
                 if ($append) {
                     $persistentVariable[$key] = array_merge($persistentVariable[$key], $value);
                 } else {
                     $persistentVariable[$key] = array_merge($value, $persistentVariable[$key]);
                 }
             } else {
                 if ($append) {
                     $persistentVariable[$key][] = $value;
                 } else {
                     $persistentVariable[$key] = array_merge(array($value), $persistentVariable[$key]);
                 }
             }
         } else {
             if (is_array($value)) {
                 $persistentVariable[$key] = $value;
             } else {
                 $persistentVariable[$key] = array($value);
             }
         }
     } else {
         $persistentVariable[$key] = $value;
     }
     if ($arrayUnique && isset($persistentVariable[$key][1])) {
         $persistentVariable[$key] = array_unique($persistentVariable[$key]);
     }
     // set the finnished array in the template
     if ($isPageLayout) {
         if (isset($moduleResult['content_info']['persistent_variable'])) {
             $moduleResult['content_info']['persistent_variable'] = $persistentVariable;
             $tpl->setVariable('module_result', $moduleResult);
         }
     } else {
         $tpl->setVariable('persistent_variable', $persistentVariable);
     }
     // storing the value internally as well in case this is not a view that supports persistent_variable (ezpagedata will look for it)
     self::$persistentVariable = $persistentVariable;
     if ($returnArrayDiff && isset($persistentVariableCopy[$key][0])) {
         return array_diff($persistentVariable[$key], $persistentVariableCopy[$key]);
     }
     return $persistentVariable[$key];
 }
开发者ID:jordanmanning,项目名称:ezpublish,代码行数:86,代码来源:ezjscpackertemplatefunctions.php

示例4: getPath

 /**
  * @param eZTemplate $tpl
  *
  * @return array
  */
 private function getPath($tpl)
 {
     if ($tpl->hasVariable('module_result')) {
         $moduleResult = $tpl->variable('module_result');
     } else {
         $moduleResult = array();
     }
     //        $viewmode = false;
     //        if ( isset( $moduleResult['content_info'] ) )
     //        {
     //            if ( isset( $moduleResult['content_info']['viewmode'] ) )
     //            {
     //                $viewmode = $moduleResult['content_info']['viewmode'];
     //            }
     //        }
     return isset($moduleResult['path']) && is_array($moduleResult['path']) ? $moduleResult['path'] : array();
 }
开发者ID:OpencontentCoop,项目名称:ocoperatorscollection,代码行数:22,代码来源:ocoperatorscollection.php


注:本文中的eZTemplate::variable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。