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