mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Add View::getBlock()
View::get() had two jobs. That's almost always a bad thing. Add a new method instead.
This commit is contained in:
parent
90f035c54d
commit
7854f9dd52
2 changed files with 19 additions and 9 deletions
|
@ -937,7 +937,7 @@ class ViewTest extends CakeTestCase {
|
|||
echo 'Block content';
|
||||
$this->View->end();
|
||||
|
||||
$result = $this->View->get('test');
|
||||
$result = $this->View->getBlock('test');
|
||||
$this->assertEquals('Block content', $result);
|
||||
}
|
||||
|
||||
|
@ -955,7 +955,7 @@ class ViewTest extends CakeTestCase {
|
|||
echo ' content';
|
||||
$this->View->end();
|
||||
|
||||
$result = $this->View->get('test');
|
||||
$result = $this->View->getBlock('test');
|
||||
$this->assertEquals('Block content', $result);
|
||||
}
|
||||
|
||||
|
@ -966,7 +966,7 @@ class ViewTest extends CakeTestCase {
|
|||
*/
|
||||
public function testBlockSet() {
|
||||
$this->View->setBlock('test', 'Block content');
|
||||
$result = $this->View->get('test');
|
||||
$result = $this->View->getBlock('test');
|
||||
$this->assertEquals('Block content', $result);
|
||||
}
|
||||
|
||||
|
@ -979,7 +979,7 @@ class ViewTest extends CakeTestCase {
|
|||
$this->View->setBlock('test', 'Block');
|
||||
$this->View->append('test', ' content');
|
||||
|
||||
$result = $this->View->get('test');
|
||||
$result = $this->View->getBlock('test');
|
||||
$this->assertEquals('Block content', $result);
|
||||
}
|
||||
|
||||
|
@ -990,7 +990,7 @@ class ViewTest extends CakeTestCase {
|
|||
*/
|
||||
public function testBlockAppendUndefined() {
|
||||
$this->View->append('test', 'Unknown');
|
||||
$result = $this->View->get('test');
|
||||
$result = $this->View->getBlock('test');
|
||||
$this->assertEquals('Unknown', $result);
|
||||
}
|
||||
|
||||
|
|
|
@ -499,12 +499,9 @@ class View extends Object {
|
|||
* @return mixed The content of the named var if its set, otherwise null.
|
||||
*/
|
||||
public function get($var) {
|
||||
if (!isset($this->viewVars[$var]) && !isset($this->_blocks[$var])) {
|
||||
if (!isset($this->viewVars[$var])) {
|
||||
return null;
|
||||
}
|
||||
if (isset($this->_blocks[$var])) {
|
||||
return $this->_blocks[$var];
|
||||
}
|
||||
return $this->viewVars[$var];
|
||||
}
|
||||
|
||||
|
@ -577,6 +574,19 @@ class View extends Object {
|
|||
$this->_blocks[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content for a block.
|
||||
*
|
||||
* @param string $name Name of the block
|
||||
* @return The block content or '' if the block does not exist.
|
||||
*/
|
||||
public function getBlock($name) {
|
||||
if (!isset($this->_blocks[$name])) {
|
||||
return '';
|
||||
}
|
||||
return $this->_blocks[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* End a capturing block. The compliment to View::start()
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue