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


PHP eZTemplate::unsetVariable方法代码示例

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


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


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