Cakephp 2请求数据和模型 [英] Cakephp 2 request data and model

查看:85
本文介绍了Cakephp 2请求数据和模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个模型。订单与OrderProduct

I have 2 models. Order & OrderProduct

添加Order时,Im试图操纵Order Model的beforeValidate()中的OrderProduct数据,但未成功。

When an Order to is added, Im trying to manipulate the OrderProduct data in the beforeValidate() of the Order Model but unsuccessfully.

我尝试过。 (都为订单模型)

I've tried. (Both in Order model)

function beforeValidate() 
{
    parent::beforeValidate();
    $this->data['OrderProduct']['total'] = 1000;
    return true;
}

function beforeValidate() 
{
    parent::beforeValidate();
    CakeRequest::data('OrderProduct.total', 1000);
    return true;
}

但是在交易失败后从控制器查看OrderProduct数据不会被修改(!this-> saveAll())。

But the OrderProduct data isnt being modified when viewed from the controller after a failed transaction (!this->saveAll()).

有人可以建议一种无需手动在控制器中设置数据的替代解决方案。

Could any suggest a alternative solution with out manually setting the data in the controller.

推荐答案

尝试$ this-> request-> data ['OrderProduct'] ['total'] = 1000;

Try $this->request->data['OrderProduct']['total'] = 1000;

这篇关于Cakephp 2请求数据和模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆