Cakephp With MongoDB:无法在beforeSave函数中设置新变量

Cakephp With MongoDB:无法在beforeSave函数中设置新变量,php,mongodb,cakephp,cakephp-model,Php,Mongodb,Cakephp,Cakephp Model,在将数据保存到MongoDB之前,即在beforeSave()方法中,如何将变量设置为集合 假设我有一个控制器 class BooksController extends AppController { $model_name = 'Books'; function save() { if($this->request->is('post')) { $data = $this->request->data['forms']

在将数据保存到MongoDB之前,即在
beforeSave()方法中,如何将变量设置为集合

假设我有一个控制器

class BooksController extends AppController
{
    $model_name = 'Books';

    function save() {
        if($this->request->is('post')) {
        $data = $this->request->data['forms'];
        $this->$model_name->save($data);  // Already loaded the model
        }
    }
}
和模型

class Books extends AppModel 
{

    function beforeSave($options = array()) {
        $this->data['Books']['active'] = '1'; 
        // Tried this as well but found unstructured (key,value) pair `$this->data['active'] = '1';`
        //print_r($this->data) found correct format but active field is not getting saved in MongoDB
        return true;
    }

}
请让我知道任何进一步的澄清是必要的。 非常感谢您的帮助

我是usign