Различные примеры фильтров и сортировок.
Сортировка по параметрам взята вскользь
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Список: {{add 'companies'}}</h1> | |
<form> | |
<input type="text" name="s"> | |
<label class="checkbox"><input type="checkbox" name="only_goverment" value="1">только государственные</label> | |
<label class="checkbox"><input type="checkbox" name="with_image" value="1">только с изображением</label> | |
<br> | |
От <input name="year_begin" class="span1"> до <input name="year_end" class="span1"><br> | |
<foreach Station> | |
<label class="checkbox"><input type="checkbox" name="station[{.id}]" value="1">{.title}</label> | |
</foreach> | |
<br> | |
<input type="submit" value="искать" class="btn"> | |
</form> | |
<table class="table table-striped table-bordered table-condensed"> | |
<thead> | |
<tr> | |
<th>ID</th> | |
<th>Название</th> | |
<th>Изображение</th> | |
<th><a href="?sort=yes">Год основания</a></th> | |
<th>Станция метро</th> | |
<th>Государственная?</th> | |
</tr> | |
</thead> | |
<foreach companies_list> | |
<tr> | |
<td>{.id}</td> | |
<td>{.title}</td> | |
<td><img src="{.preview}"></td> | |
<td>{.year}</td> | |
<td>{this.station.title}</td> | |
<td>{.is_goverment_title} {{edit}}{{delete}}</td> | |
</tr> | |
</foreach> | |
</table> | |
{paginator} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Контролер | |
*/ | |
class CompaniesController | |
{ | |
/** | |
* Список всех элементов | |
*/ | |
function index() | |
{ | |
d()->companies_list = d()->Company; | |
if(isset($_GET['s']) && $_GET['s']!=''){ | |
d()->companies_list->search('title','text',$_GET['s']); | |
} | |
if(isset($_GET['only_goverment']) && $_GET['only_goverment']=='1'){ | |
d()->companies_list->only('goverment'); | |
//is_goverment == 1 | |
} | |
if(isset($_GET['with_image']) && $_GET['with_image']=='1'){ | |
d()->companies_list->where('image != ""'); | |
} | |
if(isset($_GET['year_begin']) && $_GET['year_begin']!=''){ | |
d()->companies_list->where('year > ?',$_GET['year_begin']); | |
} | |
if(isset($_GET['year_end']) && $_GET['year_end']!=''){ | |
d()->companies_list->where('year < ?',$_GET['year_end']); | |
} | |
if(isset($_GET['station'])){ | |
$stations = array_keys($_GET['station']); | |
d()->companies_list->where('station_id IN (?)', $stations); | |
} | |
if (isset($_GET['sort'])){ | |
d()->companies_list->order_by('year'); | |
} | |
d()->companies_list->paginate(2); | |
d()->paginator = d()->Paginator->bootstrap->generate(d()->companies_list); | |
print d()->view(); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[admin.fields] | |
small title "Название" | |
small year "год основания" | |
select_table station_id "Станция метро" stations | |
select is_goverment "Государственная?" "Нет(0)" "Да(1)" | |
image image "Изображение" galleries 50 50 | |
rich text "Описание" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Контролер | |
*/ | |
class Company extends ActiveRecord | |
{ | |
function is_goverment_title() | |
{ | |
if($this->get('is_goverment')){ | |
return 'Да'; | |
} | |
return 'Нет'; | |
} | |
function preview(){ | |
if($this->get('image')){ | |
return preview($this->get('image')); | |
} | |
return '/images/no.png'; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[admin.fields] | |
small title "Название" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment