【问题标题】:CakePHP: How can be displayed the inserted information into database?CakePHP:如何将插入的信息显示到数据库中?
【发布时间】:2012-03-02 07:44:11
【问题描述】:

我在控制器中有以下代码:

    function add() {            
        if (!empty($this->data)) {              
            if ($this->Password->save($this->data)) {
            $this->Session->setFlash('the password I_WANT_TO_DISPLAY_THE_INSERTED_PASSWORD_HERE was added');
            $this->redirect(array('action' => 'index'));
        }
    }
}

问题是如何在视图中显示插入的信息? 一条消息“密码 XXX 已添加到您的数据库中”。 我认为必须从文本字段中检索数据。我不知道如何在 cakePHP 中做到这一点。

【问题讨论】:

    标签: php cakephp


    【解决方案1】:

    所有保存的数据始终可从$this->data 数组中获得。您可以使用以下语法:

    $this->data['Model']['field'];
    

    例如,如果您将字段passwd 保存到passwords 表中,它应该是:

    $this->Session->setFlash(
        'the password ' . $this->data['Password']['passwd'] . ' was added'
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多