English 中文(简体)
多个咨询建议插入 Cakephp 1 模型
原标题:Advice multiple insert Cakephp 1 model
  • 时间:2012-05-24 22:24:51
  •  标签:
  • cakephp

我在想,是否还有另外一种方法,在同一个表格上插入用户代号,用“cakephp like”插入多个插入。例如,我的工作是:

$user_id = $this->Auth->user( id );
if ($this->request->is( post )) {
        foreach ($this->request->data[ Post ] as $key => $value) {
            if (is_int($key)) {
                $this->request->data[ Post ][$key][ user_id ] = $user_id;
            }
            unset($key);
            unset($value);
        }
        debug($this->data[ Post ]);
        die();
        $this->Post->saveAll($this->data[ Post ]);
    }

I don t use input hidden value user_id for serurity reason. Thanks for your help !

最佳回答

尝试一下这样的东西:

$result = Set::insert($this->request->data,  Post.{n}.user_id , array( user_id  => $user_id));
问题回答

如果我记忆记忆正确提醒我, 您的数据需要像以下数据, 然后在用户模型上呼叫“ 全部” 。

Array
(
    [User] => Array
        (
            [id] => {you_user_id}
        )
    [Post] => Array
        (
            [0] => Array
                (
                    [field] => blah
                )
            [1] => Array
                (
                    [field] => blah
                )
        )
)

换言之:

$this->request->data[ User ] = array( id  => $this->Auth->user( id ));
$this->Post->User->saveAll($this->request->data);




相关问题
PHP Framework: Ebay Like Site

I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal. What would be the best PHP framework to use to build this quickly, ...

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

Using DISTINCT in a CakePHP find function

I am writing a CakePHP 1.2 app. I have a list of people that I want the user to be able to filter on different fields. For each filterable field, I have a drop down list. Choose the filter ...

Assistance with CakePHP model relationships

How would I represent the following in a CakePHP model? Product ======= product_id .... Cart ==== cart_id .... Carts_Products ============== cart_id product_id quantity

Prevent controller from trying to autoload model

I am a beginning Cake user and trying to do some work on an already existing application. Running into a problem when I create a new controller. I have created StoreController and when I try to call ...

热门标签