2012-03-01 3 views
0

이것은 조치 URL : http://localhost/carsdirectory/users/dashboard입니다.삽입 검색어가 케이크 PHP에서 작동하지 않습니다

dashboad.ctp

<?php echo $this->Form->create('User', array('type' => 'file', 'action' => 'dashboard')); ?> 

    <label class="ls-details-label">Type</label> 
    <div class="ls-details-box"> 
     <?php 
      foreach ($car_types as $car_type) 
      { 
       $car_type_new[$car_type['Car_type']['id']]= 
             $car_type['Car_type']['car_type']; 
      } 
      echo $this->Form->input('car_type', 
            array( 'label'=>false, 
              'options'=>$car_type_new, 
              'empty'=>' Select ', 
              'class'=>'styledselect_form_1')); 
     ?> 
    </div> 
<?php echo $this->Form->end(array('label' => 'Submit', 
            'name' => 'Submit',  
            'div' => array('class' => 'ls-submit')));?> 

users_controller.php (컨트롤러)

class UsersController extends AppController{ 

    var $name = "Users"; 

    public function dashboard(){ 

     $this->loadModel('Car_type'); // your Model name => Car_type  
     $this->set('car_types', $this->Car_type->find('all')); 

     if(!empty($this->data)) 
     { 

     $this->loadModel('Car'); 

     if($this->Car->save($this->data)) 
     { 
      $this->Session->setFlash('Detail has Been Saved'); 

      $this->redirect(array('action'=>'dashboard')); 

     } 
     else 
     { 
      $this->Session->setFlash('Detail could not save'); 

     } 

    } 

} 

차 (I 그 출원 car_type 테이블 이름 car_types 데이터를 페치 출원이 선택 필드 IM에서 선택한 한) .php (모델)

<?php 
class Car extends appModel{ 
    var $name = "Car"; 
} 
?> 

데이터를 삽입하려는 car_type_id 필드 (table

그래서 PLZ, 카스 tyagi

+1

VAR를 사용하지 마십시오. PUBLIC을 사용하십시오. – cwallenpoole

+0

'else'로가는 것이 오류입니까? –

+0

답장을 보내 주셔서 감사합니다. 공개했으나 여전히 car_type_id에 null 값이 기록되었습니다. –

답변

1

당신이 시도 할 수 있습니다 사전에 나에게

덕분에 도움) 자동차 이름,하지만 난 그것을 할 수없는 M :

echo $this->Form->input('Car.car_type_id', array(...)); 
+0

감사합니다 Paulo Rodrigues you r grt. 그것은 나를 위해 일했습니다. –

관련 문제