如何在控制器中访问cakephp模型值

时间:2016-11-30 08:39:41

标签: cakephp cakephp-2.4

我想在客户使用忘记密码选项时邮件验证邮件上的密钥字段值。我的查询工作正常。当我在视图中调试时,我能够看到存档值但在控制器中我无法访问该值。

这是我的控制器查询。

Collection {#310 ▼
  #items: array:2 [▼
    0 => CartLine {#294 ▼
      +cart_line_id: 836473
      +cart_id: 12957798
      +parent_line_id: null
      +quantity: 3
      +article_id: 1728
      +article_name: "TAZA CERAMICA"
      +data: ""
      +extradata: "{"original_dsn":"qF3Xxttr3B2w","tmp_dsn":"tmp_4k0k9q6usqd7pnu7d70rg0ta674zv8v4"}"
      +article_family_id: "AAAPTP"
      +article_on_line_v: 1
      +promotion_code: null
      +promotion_id: null
      +url_preview: "http://rp-static.pre/www_api/session_uploads/51_ddbc9b7fc849d214fb462f8af007c97c_6/836473/captura.jpg"
      +available_modify: true
      +model: ArticleModel {#295 ▶}
      +cession: 5.34
      +cession_original: 5.34
      +pvp: 9.95
      +pvp_original: 9.95
      +pvp_discount: 0.0
      +cession_discount: 0.0
      +discount_regularization: null
      +total_cession: 10.69
      +total_cession_original: 10.68
      +total_pvp: 19.9
      +total_pvp_original: 19.9
      #_READ_ONLY: []
      #_HIDDEN_FIELDS: []
      +__WARNINGS: []
    }
    2 => CartLine {#298 ▼
      +cart_line_id: 836475
      +cart_id: 12957798
      +parent_line_id: null
      +quantity: 1
      +article_id: 1378
      +article_name: "JARRA CERVEZA ALEMANA"
      +data: ""
      +extradata: "{"original_dsn":"null","tmp_dsn":"tmp_8cu2ls6q18ip6vvd7qccrsbjiebgsrzj"}"
      +article_family_id: "AAAPTP"
      +article_on_line_v: 1
      +promotion_code: null
      +promotion_id: null
      +url_preview: "http://rp-static.pre/www_api/session_uploads/51_ddbc9b7fc849d214fb462f8af007c97c_6/836475/captura.jpg"
      +available_modify: true
      +model: ArticleModel {#299 ▶}
      +cession: 10.21
      +cession_original: 10.21
      +pvp: 19.0
      +pvp_original: 19.0
      +pvp_discount: 0.0
      +cession_discount: 0.0
      +discount_regularization: null
      +total_cession: 10.21
      +total_cession_original: 10.21
      +total_pvp: 19.0
      +total_pvp_original: 19.0
      #_READ_ONLY: []
      #_HIDDEN_FIELDS: []
      +__WARNINGS: []
    }
  ]
}

在视图部分,我可以看到查询正在通过此

工作
public function forgot() {
    if ($this->User->validates() ) {
    $auserlogin = $this->User->forgot($this->data['user']['email']);
    $this->set('auserlogin', $auserlogin);
    $message="Someone requested to reset password \n\n";
    $message=$message."Verify Key : ".$auserlogin['0']['user']['verifykey']."\n\n";
    $message=$message."Thanks\n\n";
    $Email = new CakeEmail();
    $Email->from(array('mail@gmail.in' => 'mail'))
    ->to($this->data['user']['email'])
    ->subject('Forgot Password')
    ->send($message);
    return $this->redirect(array('controller'=>'users','action'=>'password'));
    }
}

但我想将此验证密钥邮寄给用户,因此我使用了

$auserlogin['0']['user']['verifykey'];

OR

$message="Verify Key : ".$auserlogin['0']['user']['verifykey']."\n\n";

两者都没有在邮件中工作我没有收到仅收到

的邮件的变量值
$this->set('verifykey', $auserlogin['0']['user']['verifykey']);
$message="Verify Key : ".$verifykey."\n\n";

1 个答案:

答案 0 :(得分:0)

模型名称应在控制器内部大写。 $ auserlogin [' 0'] ['用户'] [' verifykey']

积分newbee-dev