1.Apache,MySQL start
2.
index.ctp
C:\xampp\htdocs\mycakeapp\src\Template\People
<p>This is People table records.</p>
<?=$this->Form->create(null,
['type'=>'post',
'url'=>['controller'=>'People',
'action'=>'index']]) ?>
<div>find</div>
<div><?=$this->Form->text('People.find') ?></div>
<div><?=$this->Form->submit('検索') ?></div>
<?=$this->Form->end() ?>
<hr>
<table>
<thead><tr>
<th>id</th><th>name</th><th>mail</th><th>age</th><th></th>
</tr></thead>
<?php foreach($data->toArray() as $obj): ?>
<tr>
<td><?=h($obj->id) ?></td>
<td><a href="<?=$this->Url->build(['controller'=>'People',
'action'=>'edit']); ?>?id=<?=$obj->id ?>">
<?=h($obj->name) ?></a></td>
<td><?=h($obj->mail) ?></td>
<td><?=h($obj->age) ?></td>
<td><a href="<?=$this->Url->build(['controller'=>'People',
'action'=>'delete']); ?>?id=<?=$obj->id ?>">delete</a></td>
</tr>
<?php endforeach; ?>
</table>
3.一致检索
PeopleController.php
<?php
namespace App\Controller;
use App\Controller\AppController;
class PeopleController extends AppController{
public function index() {
if ($this->request->is('post')){
$find = $this->request->data['People']['find'];
$condition = ['conditions'=>['name'=>$find]];
$data = $this->People->find('all', $condition);
} else {
$data = $this->People->find('all');
}
$this->set('data', $data);
}
}
?>
4.
http://localhost/mycakeapp/people/
5.模糊检索
PeopleController.php
C:\xampp\htdocs\mycakeapp\src\Controller
<?php
namespace App\Controller;
use App\Controller\AppController;
class PeopleController extends AppController{
public function index() {
if ($this->request->isPost()){
$find = $this->request->data['People']['find'];
$condition = ['conditions'=>['name like'=>$find]];
$data = $this->People->find('all', $condition);
} else {
$data = $this->People->find('all');
}
$this->set('data', $data);
}
}
?>