本文整理汇总了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" );
}
}
}