Jak na vyhledávací formulář?
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- KONY
- Člen | 16
Ahoj,
zkusim to jeste trosku priblizit:
Do DashboardPresenter.php jsem si dopsal view a tovarnicku pro formular vyhledavani:
<?php
/********************* views search *********************/
public function renderSearch()
{
$form = $this['searchForm'];
if (!$form->isSubmitted()) {
$album = new Albums;
$row = $album->searchAll()->fetch();
if (!$row) {
throw new BadRequestException('Record not found');
}
$form->setDefaults($row);
}
protected function createComponentSearchForm()
{
$form = new AppForm;
$form->addText('artist', 'Artist:')
->addRule(Form::FILLED, 'Please enter an artist.');
$form->addSubmit('search', 'Search')->getControlPrototype()->class('default');
$form->addSubmit('cancel', 'Cancel')->setValidationScope(NULL);
$form->onSubmit[] = callback($this, 'searchFormSubmitted');
$form->addProtection('Please submit this form again (security token has expired).');
return $form;
}
public function searchFormSubmitted(AppForm $form)
{
if ($form['search']->isSubmittedBy()) {
$album = new Albums;
$album->searchAll();
}
$this->redirect('search');
}
?>
Vytvoril jsem si pohled search.phtml upravou default.phtml
<?php
{block #content}
<h1>{block #title}My Albums{/block}</h1>
<p>vyhledane alba</p>
<table class="grid">
<tr>
<th>Title</th>
<th>Artist</th>
<th> </th>
</tr>
{foreach $albums as $album}
<tr>
<td>{$album->title}</td>
<td>{$album->artist}</td>
<td>
<a href="{link edit, $album->id}">Edit</a>
<a href="{link delete, $album->id}">Delete</a>
</td>
</tr>
{/foreach}
</table>
<p><a href="{link User:default}">Users</a></p>
?>
Vim, ze musim jeste do modelu napsat funkci searchAll, ale nevim, jak na to a jestli nemam neco spatne v tom, co jsem dosud napsal.
Diky moc.
KONY>