Skip to content

Instantly share code, notes, and snippets.

@nojimage
Created January 27, 2011 17:47
Show Gist options
  • Save nojimage/798876 to your computer and use it in GitHub Desktop.
Save nojimage/798876 to your computer and use it in GitHub Desktop.
CakePHP Js::bufferメソッドを使う前提であれば、Js::setで値をJSへ渡すことが可能
<?php
// in layout/default.ctp
?>
<!-- // .. snip -->
<?php echo $this->Js->writeBuffer(); ?>
</body></html>
<?php
// some_view.ctp
// set to app.webroot
$this->Js->set('webroot', $this->Html->url('/'));
// set to app.here
$this->Js->set('here', $this->Html->url());
// call
$this->Js->buffer("
console.log(app.webroot);
console.log(app.here);
");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment