SELECT LEFT(`name`, 1) `abc`, `id`, `name` FROM `persons` ORDER BY `name` ASC;
$data = [
['abc' => 'а', 'id' => 1, 'name' => 'Абрамов Михаил Фёдорович'],
['abc' => 'а', 'id' => 2, 'name' => 'Агутин Юрий Николаевич'],
['abc' => 'б', 'id' => 4, 'name' => 'Баринов Олег Юрьевич'],
];
$alphabet = [];
foreach ($data as $row){
$alphabet[$row['abc']][$row['id']] = $row['name'];
}
$alphabet = [
'а' => [
1 => 'Абрамов Михаил Фёдорович',
2 => 'Агутин Юрий Николаевич',
],
'б' => [
4 => 'Баринов Олег Юрьевич',
],
];
foreach($alphabet as $alpha => $rows){
echo '<h2>'.$alpha.'</h2>';
echo '<ul>';
foreach ($rows as $id => $name){
echo '<li><a href="/person?id='.$id.'">'.$name.'</a></li>';
}
echo '</ul>';
}
class Order {
const SECRET_KEY = 'not-log-secret-key-2213123123';
}
$token = Yii::$app->security->hashData($order->id, Order::SECRET_KEY);
Для подтверждения пройдите по <a href="http://site.domain/order/confirm?token=<?= $token ?>">ссылке</a>
class OrderController extends Controller {
public function actionConfirm($token){
if ($id = \Yii::$app->security->validateData($token, Order::SECRET_KEY)){
if (($order = Order::findOne($id)) && $order->updateAttributes(['confirmed' => true])){
Yii::$app->session->addFlash('success', 'Талон подтвержден');
return $this->redirect('orders');
}
}
throw new NotFoundHttpException();
}
}
echo Select2::widget([
'name' => 'my-select2',
'data' => [1 => 'One', 2 => 'Two'],
'options' => [
'placeholder' => 'Select a number ...',
'options' => [
2 => ['disabled' => true],
]
],
]);
<select>
<option value="1">One</option>
<option value="2" disabled="disabled">Two</option>
</select>
[
'label' => 'Роль',
'value' => function($model){
return $model->authAssignment->authItem->description;
}
]
$query = User::find()->with([
'authAssignment' => function($q){
return $q->with('authItem');
}
]);
yii\widgets\ActiveField
, а точнее методы в нём:public $template = "{label}\n{icon}\n{input}\n{hint}\n{error}";
public function render($content = null)
{
if ($content === null) {
if (!isset($this->parts['{input}'])) {
$this->textInput();
}
// добавить это
if (!isset($this->parts['{icon}'])) {
$this->icon();
}
if (!isset($this->parts['{label}'])) {
$this->label();
}
if (!isset($this->parts['{error}'])) {
$this->error();
}
if (!isset($this->parts['{hint}'])) {
$this->hint(null);
}
$content = strtr($this->template, $this->parts);
} elseif (!is_string($content)) {
$content = call_user_func($content, $this);
}
return $this->begin() . "\n" . $content . "\n" . $this->end();
}
public function icon($content, $options = [])
{
$this->parts['{icon}'] = Html::tag('i', null, ['class' => 'icon-'.$this->attribute];
return $this;
}
$form = ActiveForm::begin([
'fieldClass' => 'my\widgets\ActiveField'
]);
public function getSubnet(){
return $this->hasOne(Subnet::class, ['id' => 'subnet']);
}
public function getBras(){
return $this->hasOne(Bras::class, ['id' => 'bras'])->via('subnet');
// или
// return $this->hasOne(Bras::class, ['id' => 'bras'])->viaTable(Subnet::tableName(), ['id' => 'subnet']);
}
ClientSearch {
public $brasName; // добавляем атрибут в модель поиска
}
'id',
[
'attribute' => 'brasName', // выводим в гриде
'value' => function(Client $model){
return $model->bras ? $model->bras->name : null;
}
],