2012-10-10 3 views
1

cakephp 2의 saveAll() 메소드를 사용하여 많은 양의 데이터를 한 번에 저장하려고합니다. 문제는 saveAll() 함수에 전달하는 배열이 어떤 모양인지 이해할 수 없다는 것입니다. .Cakephp - saveall() - arrray는 어떻게 생겼을 까?

나는 다음과 같은 모델이 : 그래서 두 성분 각각이 recipeitems와 조리법을 저장할지 여부를

Recipe: 
hasMany: Recipeitem 
hasAndBelongsToMany:Category 

Category: 
hasAndBelongsToMany: Recipe 

Recipeitem: 
belongsTo: Recipe 
hasMany: Ingredient 

Ingredient: 
belongsTo: Grocery, Recipeitem 

Grocery: 
hasMany: Ingredient 

를, 무엇을해야 나가 시려면 보이는 기능에 전달있어 배열 객체 처럼?

이 내 배열이 순간에 모습입니다 : CakePHP의이 요리 책 읽고 지금

Array 
(
[Recipe] => Array 
    (
     [title] => Mushroom pie 
     [instructions] => Just mix it! 
     [cooking_time] => 20 
    ) 

[Category] => Array 
    (
     [Category] => Array 
      (
       [0] => 5 
       [1] => 3 
      ) 

    ) 

[Recipeitem] => Array 
    (
     [0] => Array 
      (
       [Recipeitem] => Array 
        (
         [name] => Crust 
         [order] => 0 
         [Ingredients] => Array 
          (
           [0] => Array 
            (
             [Ingredient] => Array 
              (
               [amount] => 2 
               [unit] => dl 
               [order] => 0 
               [Grocery] => Array 
                (
                 [name] => Butter 
                 [description] => Butter 
                ) 

              ) 

            ), 
           [1] => Array 
            (
             [Ingredient] => Array 
              (
               [amount] => 3 
               [unit] => dl 
               [order] => 1 
               [Grocery] => Array 
                (
                 [name] => Sugar 
                 [description] => Sugar 
                ) 

              ) 

            ) 

          ) 

        ) 

      ), 
     [1] => Array 
      (
       [Recipeitem] => Array 
        (
         [name] => Filling 
         [order] => 1 
         [Ingredients] => Array 
          (
           [0] => Array 
            (
             [Ingredient] => Array 
              (
               [amount] => 2 
               [unit] => dl 
               [order] => 0 
               [Grocery] => Array 
                (
                 [name] => Mushroom 
                 [description] => Mushroom 
                ) 

              ) 

            ) 

          ) 

        ) 

      ) 

    ) 

)

+0

([나는 그것에 대해 쓴 기사] http://www.pabloleanomartinet.com/cakephp-2-x-saving-and- validating-a-habtm-relation-example /) 요 전날 .. 도움이 될만한 :) – pleasedontbelong

답변

0

내가 문제를 스스로 해결했습니다 조금 더 나은 :

버전 2.1에서 변경되었습니다 : 더 깊은 관련 데이터를 으로 저장할 수 있습니다. $ options [ 'deep'] = true;

그래서 나를 위해이 내가 필요한 모든했다 :

$saveOptions['deep'] = true; 
if ($this->Recipe->saveAll($this->request->data, $saveOptions)) { 
관련 문제