2013-05-14 4 views
0

저는 Yii 프레임 워크에서 일하고 있는데 한 가지 문제가 있습니다. 편의 시설을 갖춘 테이블이 하나 있는데 그 모든 것을 찾고 싶습니다.데이터베이스에서 모든 레코드를 수집하고 존재를 확인했습니다.

$ amenities = RoomTypeAmenity :: model() -> findAll(); 이 명령은 정상적으로 작동합니다. > ('idRoomTypeAmenity')로 - -

그럼 난 편의 시설이 방을 가지고) ( $ amenities_room = RoomTypeAmenity :: 모델을 입력 한 내용을 찾으려면> findall은(); 그리고이 명령은 잘 동작합니다. 그러나 편의 시설을 인쇄 할 때 존재하는 편의 시설을 확인하고 싶습니다.

foreach ($amenities as $amenity) { ?> 
     <input type="checkbox" class="css-checkbox" id="facility_<?php echo $amenity->id_room_type_amenity; ?>"> 
     <label class="css-label" for="facility_<?php echo $amenity->id_room_type_amenity; ?>"><?php echo $amenity->name; ?></label> 

     <?php }?> 

답변

1

사용 for-loop 내부 if else 상태. 현재 어메니티에 대한 현재 어메니티 룸이 있는지 확인하십시오. 종료하는 경우 checkedcheckbox입니다.

foreach ($amenities as $amenity) { ?> 
    if($amenity->id_room_type_amenity!=null){ 
     <input type="checkbox" class="css-checkbox" id="facility_<?php echo $amenity->id_room_type_amenity; ?>" checked> 
     <label class="css-label" for="facility_<?php echo $amenity->id_room_type_amenity; ?>"><?php echo $amenity->name; ?></label> 
    } else { 
     <input type="checkbox" class="css-checkbox" id="facility_<?php echo $amenity->id_room_type_amenity; ?>"> 
     <label class="css-label" for="facility_<?php echo $amenity->id_room_type_amenity; ?>"><?php echo $amenity->name; ?></label> 
    } 

<?php }?> 

희망이 있습니다.