Skip to content

Instantly share code, notes, and snippets.

@ramainen
Last active November 3, 2025 15:52
Show Gist options
  • Select an option

  • Save ramainen/4686932 to your computer and use it in GitHub Desktop.

Select an option

Save ramainen/4686932 to your computer and use it in GitHub Desktop.
Различные примеры фильтров и сортировок. Сортировка по параметрам взята вскользь
<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}
<?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();
}
}
[admin.fields]
small title "Название"
small year "год основания"
select_table station_id "Станция метро" stations
select is_goverment "Государственная?" "Нет(0)" "Да(1)"
image image "Изображение" galleries 50 50
rich text "Описание"
<?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';
}
}
[admin.fields]
small title "Название"
@waleed-seo83689
Copy link

The CSC Samagra platform helps citizens access government welfare schemes and update their family details online. Through digital services, csc samagra makes record management easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment