mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Making JsHelper::set() work well with setting the variables to an object property.
This commit is contained in:
parent
4be98b6ed9
commit
f07df02087
2 changed files with 11 additions and 3 deletions
|
@ -237,7 +237,8 @@ class JsHelper extends AppHelper {
|
||||||
**/
|
**/
|
||||||
function _createVars() {
|
function _createVars() {
|
||||||
if (!empty($this->__jsVars)) {
|
if (!empty($this->__jsVars)) {
|
||||||
$this->buffer('var ' . $this->setVariable . ' = ' . $this->object($this->__jsVars) . ';');
|
$setVar = (strpos($this->setVariable, '.')) ? $this->setVariable : 'var ' . $this->setVariable;
|
||||||
|
$this->buffer($setVar . ' = ' . $this->object($this->__jsVars) . ';');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -446,9 +446,16 @@ CODE;
|
||||||
$this->Js->set('loggedIn', true);
|
$this->Js->set('loggedIn', true);
|
||||||
$this->Js->set(array('height' => 'tall', 'color' => 'purple'));
|
$this->Js->set(array('height' => 'tall', 'color' => 'purple'));
|
||||||
$this->Js->setVariable = 'WICKED';
|
$this->Js->setVariable = 'WICKED';
|
||||||
$result = $this->Js->getBuffer(false);
|
$result = $this->Js->getBuffer();
|
||||||
$expected = 'var WICKED = {"loggedIn":true,"height":"tall","color":"purple"};';
|
$expected = 'var WICKED = {"loggedIn":true,"height":"tall","color":"purple"};';
|
||||||
$this->assertEqual($result[0], $expected);
|
$this->assertEqual($result[0], $expected);
|
||||||
|
|
||||||
|
$this->Js->set('loggedIn', true);
|
||||||
|
$this->Js->set(array('height' => 'tall', 'color' => 'purple'));
|
||||||
|
$this->Js->setVariable = 'Application.variables';
|
||||||
|
$result = $this->Js->getBuffer();
|
||||||
|
$expected = 'Application.variables = {"loggedIn":true,"height":"tall","color":"purple"};';
|
||||||
|
$this->assertEqual($result[0], $expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue