안녕하세요 저는 cakephp 프레임 워크를 배우기 시작했습니다. 시작하기 전에 간단한 게임을 만들고 싶었습니다.cakephp foreach 제목이있는 정렬
나는 사용자 컨트롤러가 이미 (아직 끝나지 않았지만 작동한다 : D) 이제 장비를 작성하기 시작했다. 하지만 난 이런 (등 헬멧, 갑옷, 방패) 유형별 foreach는 이제 스크립트 출력 테이블 정렬 노력하고있어 순간에 붙어 :
Id Owner Name Status Type Cost
1 23 Krasnoludzka Salada B H 100
2 23 Jakieś spodnie B L 10
3 23 Zbroja B A 123
을하지만 난 이런 식으로 그것을 만들 싶어 :
Id Owner Name Status Type Cost
Helmets:
1 23 Krasnoludzka Salada B H 100
4 23 Smocza Salada B H 100
Legs:
2 23 Jakieś spodnie B L 10
Armors:
3 23 Zbroja B A 123
내 equipments_controller.php :
<?php
class EquipmentsController extends AppController {
var $name = 'Equipments';
var $helpers = array('Html', 'Form');
function index() {
$this->set('equipments', $this->Equipment->find('all', array('conditions' => array('owner='.$this->Session->read('Auth.User.id'), 'status=\'B\''))));
//$this->set('equipments', $this->Equipment->find('owner='.$this->Session->read('Auth.User.id')));
}
function view ($id = null) {
$this->Equipment->id = $id;
$owner = $this->Equipment->read('owner');
if ($owner['Equipment']['owner']==$this->Session->read('Auth.User.id')) {
$this->redirect(array('controller' => 'equipments', 'action' => 'index'));
$this->Session->setFlash('To nie twój przedmiot!');
} else {
$this->set('equipment', $this->Equipment->read());
}
}
}
그리고 장비/index.ctp :
<!-- File: /app/views/news/index.ctp (edit links added) -->
<h1>Plecak</h1>
<table>
<tr>
<th>Id</th>
<th>Owner</th>
<th>Name</th>
<th>Status</th>
<th>Type</th>
<th>Cost</th>
</tr>
<!-- Here's where we loop through our $news array, printing out news info -->
<?php foreach ($equipments as $equipment): ?>
<tr>
<td><?php echo $equipment['Equipment']['id']; ?></td>
<td><?php echo $equipment['Equipment']['owner']; ?></td>
<td><?php echo $equipment['Equipment']['name']; ?></td>
<td><?php echo $equipment['Equipment']['status'];?></td>
<td><?php echo $equipment['Equipment']['type']; ?></td>
<td><?php echo $equipment['Equipment']['cost']; ?></td>
</tr>
<?php endforeach; ?>
</table>
아무도 도와 줄 수 있습니까?
없이 그들은 유일한 유형으로 분류한다 오하지만 난 각 유형 – KryQ