2013-05-17 4 views
0
Chart hasMany Series 
Series belongsTo Chart 
Series hasAndBelongsToMany Industry 
Series hasAndBelongsToMany Sector 
Industry hasMany Sector 
Sector belongsTo Industry 

사용자가 여러 시리즈와 함께 차트를 ​​저장하도록 허용하려고합니다.cakephp 필드 명명 규칙 - 여러 모델 저장

모든 모델을 저장하기 위해 입력 필드의 이름과 저장 방법을 어떻게 지정해야합니까?

답변

0

한 번에 여러 관련 모델 값을 저장하는 일반적인 규칙은 다음과 같습니다 :

$data = array(
    'User' => array('userFieldName' => 'fieldValue'), 
     'Chart' => array(
      array(
       'chartFieldName' => "chartFieldValue", 
       'Series' => array(
        array(
         'firstSerieItemField' => "Value", 
        ), 
        array(
         'secondSerieItemField' => "Value", 
        ) 
        ... 
        ...//More Series Data 
       ) 
      ) 
     ) 
    ); 

$this->User->saveAll($data); 

참고 :

모델 사이의 관계를 지정하는 것을 잊지 마세요하지만 당신은 할 수 보기 페이지에서 필드 값을 적절히 정의하여이를 달성하십시오. 단지 패턴을 따라 기억

topMdel["topModelFieldName"]; 
topModel["FirstAssociateModel"]["FirstAssociateModelFieldName"]; 
topModel["FirstAssociateModel"]["SecondAssociateModel"]["SecondAssociateModelFieldName"]; 

이 더 명확합니다. Usermodel 데이터 필드에 대한

: 차트 모델 데이터 필드의

User["user_name"]; 
User["user_email"]; //etc. 

: 도움이

User["Chart"]["chart_name"]; 
User["Chart"]["chart_value"]; //etc. 

희망 귀하의 경우이다. 시리즈 모델 데이터 필드 :

User["Chart"]["Series"][0]["series_1_name"]; 
User["Chart"]["Series"][1]["series_2_name"]; 
User["Chart"]["Series"][2]["series_2_name"];