在cakephp中使用全局变量

在cakephp中使用全局变量,cakephp,global-variables,Cakephp,Global Variables,我在同一个控制器中有两个视图,需要在第二个视图中显示第一个视图的值。我是通过会话完成的,但我希望top使用Configure::write()或variable-How-can-do来完成 public function index() { Configure::write('workinghrs', '5'); } public function view() { $this->set('price', Configure::read('workinghrs'));

我在同一个控制器中有两个视图,需要在第二个视图中显示第一个视图的值。我是通过会话完成的,但我希望top使用
Configure::write()
或variable-How-can-do来完成

public function index() 
{
    Configure::write('workinghrs', '5');
}
public function view() 
{
    $this->set('price', Configure::read('workinghrs'));
}
它不起作用。 我也试过这个

public $workinghrs;
public function index() 
{
    $this->workinghrs = "3";
}
public function view() 
{
    $this->set('price', $this->workinghrs);
}

但我仍然无法获取值,因为两者都提供空值。

如果希望变量在请求之间持久化,则需要使用会话。您使用
Configure::write()
设置的任何内容都会在内存中,并且在特定请求完成后会丢失。

因为他正在使用index()?如果在引导文件中使用它呢?如何将其与数据库一起使用?