나는 cakephp 2.2에 사이트를 가지고 있으며, 쿼리로부터 가져온 값을 가진 많은 입력 타입 텍스트가있는 폼을 가지고있다.cakephp 폼에서 여러개 삽입하기
모든 입력 텍스트에 대해 데이터베이스의 내 테이블에 새 레코드를 만들 때 제출 버튼을 사용하여 저장하려고합니다.
우선 내가 간단한 검색어를 만들어 변수 (소품)에 넣습니다. 내가 foreach
을 만들고 내가 찾은 모든 레코드에 대해 입력 텍스트를 만듭니다. 그러나 내가 저장할 때 업데이트하고 싶지 않지만 테이블에 새 레코드를 만들려면 값을 변경하거나 변경할 수는 있지만 각 입력 유형을 저장하고 싶습니다. 나는 무언가를 시도했지만 모든 입력이 아닌 마지막 입력 텍스트의 값으로 하나의 레코드 만 생성합니다. ingredient_properties
IngredientProperty
id
, ingredient_id
, property_id
, user_id
, created
, modified
내 표는 일부 필드를
- 테이블 이름을 가지고있다.
이 내보기 *의 add_prop.ctp *
echo $this->Form->create('Ingredient', array ('class' => 'form'));
echo'<p>ELENCO PROPRIETA\'</p>';
foreach($prop as $p){
echo('<p>'.$p['Property']['PropertyAlias'][0]['alias']);
echo $this->Form->input('IngredientProperty.ingredient_id', array ('type'=>'hidden', 'value'=> $p['IngredientProperty']['ingredient_id'],'label'=> false, 'id' => 'id'));
echo $this->Form->input('IngredientProperty.property_id', array ('type'=>'hidden', 'value'=> $p['IngredientProperty']['property_id'],'label'=> false, 'id' => 'id'));
echo $this->Form->input('IngredientProperty.value', array ('label'=> false, 'id' => 'value_'.$p['IngredientProperty']['id'], 'name' => 'value_'.$p['IngredientProperty']['id'],'value'=> $p['IngredientProperty']['value'], 'after' => '<div class="message">Inserisci un valore</div>'));
echo('</p>');
}
echo $this->Form->submit('Salva', array('id'=>'add_prop'));
echo $this->Form->end();
입니다 그리고 이것은 내 컨트롤러 Ingredient.php입니다 함께
public function add_prop($alias) {
if ($this->request->is('post'))
{
//SAVE
if ($this->Ingredient->IngredientProperty->saveAll($this->request->data)){
$this->set('flash_element','success');
$this->Session->setFlash ('Proprietà aggiornate con successo.');
//$this->redirect(array('action'=>'photo',$alias));
}
else{
$this->set('flash_element','error');
$this->Session->setFlash('Errore di salvataggio proprietà');
}
}
else{
//QUERY TO RETRIEVE DATA
$this->set('prop',$this->Ingredient->IngredientProperty->find('all', array('recursive' => 2,
'conditions' => array('IngredientProperty.ingredient_id' => $id))));
$this->loadModel('Property');
$this->set('prop_all',$this->Property->find('all'));
$this->loadModel('Unit');
$this->set('unit',$this->Unit->find('all'));
}
}
:
그리고 양식을 확인을 통해 컨트롤러에 데이터를 요청했다. 질문을 명확하게 설명해 주시겠습니까? –
나는 쿼리를 만들고 모든 레코드에 대해 입력 텍스트를 양식에 인쇄하고 각 필드에 대해 각 레코드에 대해 새 값으로 레코드를 만들고 싶습니다. –