2010-02-25 6 views
0

내 zend 프로젝트에서 드롭 다운 상자 및 텍스트 영역과 함께 몇 가지 건강상의 문제를 보여주고 싶습니다. 내 컨트롤러 및보기는 아래에 나와 있습니다.데이터 제출 zendframework

class IndexController extends Zend_Controller_Action 

{

public function init() 
{ 
    /* Initialize action controller here */ 
} 

public function indexAction() 
{ 
    $healthproblems =new Model_DbTable_Healthproblems(); 
    $this->view->healthproblems=$healthproblems->fetchAll(); 
} 

public function addAction() 
{ 

} 

}

--index.phtml--

<table border='1'> 
<tr> 
    <th>Name</th>  
    <th>&nbsp;</th> 
    <th>&nbsp;</th> 
</tr> 
<?php foreach($this->healthproblems as $prob) : ?> 
<tr> 
    <td><?php echo $this->escape($prob->healthproblem_name);?></td> 
    <td><select id="ddl_<?php echo $prob->prob_id; ?>"> 
      <option selected="selected">--Select--</option> 
      <option>Yes</option> 
      <option>No</option> 
     </select></td> 
    <td><input type="text" style="width: 50px" value=""></input></td> 

</tr> 

<?php endforeach; ?> 
<tr><td colspan="3" align="center"> 
<input type="submit" id="submit" value="Submit" ></input></td></tr> 

'어떻게 데이터베이스에이 데이터를 추가하는 것입니다 내 문제? ' problemid 및 메모와 같은 필드가 있습니다. 다른 모든 대체 방법이 가능합니까? HeaalthProblems 하나의 테이블에 포함하고 각 개인의 문제를 다른 테이블에 삽입하고 싶습니다. 제발 도와주세요.

답변

0

처음부터 Zend_Form을 사용하는 것이 좋습니다.

두 번째로는 문제를 해결하려면 양식에있는 사람과 문제 ID가있는 person_id 및 problem_id 필드 (숨김) 필드가 있어야합니다.

컨트롤러에서 데이터를 잡아 내고 모델로 보내면됩니다 (아래 설명 참조).

그러면 insetPersonHealthProblem ($ data) 메소드로 PersonProblem이라는 새 모델을 만들어야합니다. 어느 컨트롤러에서 데이터를 받게됩니다.

은 지금까지 당신은 당신의 $ 데이터 배열이 같은 뭔가를해야합니다 :

array(
'person_id' => 1, 
'problem_id' => 15, 
'hasproblem' => ', // 1 for yes and 0 for no 
'note' => 'something' 
); 

그래서 당신의 분야는 "hasproblem"라고하며 대신에 당신이해야 name 필드에 문제 ID를 연결할 필요가 숨겨진 필드.

마지막으로 insetPersonHealthProblem의 방법에 당신이 관계를 삽입 할 수 있습니다, 당신은 그런 일에 종료됩니다 :

id | person_id | problem_id | hasproblem | note 

1    1     15    1   something 

양식은 다음과 같이 표시됩니다 도움말

<form method="POST" action="url('......')"> 
<input type="hidden" name="person_id" value="<?php echo $person_id; ?>" /> 
<input type="hidden" name="person_id" value="<?php echo $problem_id; ?>" /> 
<table border='1'> 
<tr> 
    <th>Name</th>  
    <th>&nbsp;</th> 
    <th>&nbsp;</th> 
</tr> 
<?php foreach($this->healthproblems as $prob) : ?> 
<tr> 
    <td><?php echo $this->escape($prob->healthproblem_name);?></td> 
    <td><select id="hasproblem"> 
      <option selected="selected">--Select--</option> 
      <option>Yes</option> 
      <option>No</option> 
     </select></td> 
    <td><input type="text" name="note" style="width: 50px" value=""></input></td> 

</tr> 

<?php endforeach; ?> 
<tr><td colspan="3" align="center"> 
<input type="submit" id="submit" value="Submit" ></input></td></tr> 
</form> 

희망 당신.

관련 문제