Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@alexaandrov
alexaandrov / PHP Multilanguage content
Created March 29, 2016 15:15
Реализация мультиязычности
Сомневался в добавлении этого в статью. Добавлю комментом. Обычно делаем через таблицу связей. Типичный пример для блога и постов.
Таблица post(модель Post) — храним метаинформацию, которая не имеет отношения к контенту.
То есть такие поля: id, owner_id, date_create, date_update.
Таблица post_lang(модель PostLang) — связь контента по языкам. Поля: id, post_id, lang_id, name, description.
Соответственно поля post_id — это id из таблицы post, lang_id — это id из таблицы lang. name и
description — контент на соответствующем языке.
В модель Post добавляем отношение:
public function getContent($lang_id=null)
{
@alexaandrov
alexaandrov / yii2_htaccess
Last active April 1, 2016 08:10
Yii2 htaccess
### Basic package
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# Если запрос не начинается с web, добавляем его
RewriteCond %{REQUEST_URI} !^/(web)
RewriteRule (.*) /web/$1
# Если файл или каталог не существует, идём к /web/index.php
@alexaandrov
alexaandrov / yii2_timestamp_behavior.txt
Last active April 1, 2016 08:11
Поведение для автоматического обновления даты при редактировании и создании записи в таблице
public function behaviors()
{
return [
'timestamp' => [
'class' => 'yii\behaviors\TimestampBehavior',
'attributes' => [
\yii\db\ActiveRecord::EVENT_BEFORE_INSERT => ['date_create', 'date_update'],
\yii\db\ActiveRecord::EVENT_BEFORE_UPDATE => ['date_update'],
],
],
@alexaandrov
alexaandrov / yii2_manytomany_in_gridview
Last active April 9, 2016 11:18
Display information of many to many relation tables in view
// Create method in your model class
public function getManyToManyTableName($relationName)
{
$string = '';
$array = $this->$relationName;
if(empty($array)) {
return Yii::t('app', 'Not set');
}
$arrayLength = count($array);
$counter = 0;
<?php
/**
* Application requirement checker script.
*
* In order to run this script use the following console command:
* php requirements.php
*
* In order to run this script from the web, you should copy it to the web root.
* If you are using Linux you can create a hard link instead, using the following command:
* ln requirements.php ../requirements.php
# JetBrains IDE
.idea
# Windows thumbnail cache
Thumbs.db
desktop.ini
debug.log
# Mac DS_Store Files
*.DS_Store
@alexaandrov
alexaandrov / arrayChangeFirstKeyCase.php
Last active June 7, 2018 12:10
Function that recursively changes the first character register of all keys in an array
<?php
/**
* Recursively changes the first character register of all keys in an array.
* @param array $array The array to work on
* @param int $case Either CASE_UPPER or CASE_LOWER (default)
* @return array Returns an array with its keys lower or uppercase.
*
* Inspired by http://php.net/manual/en/function.array-change-key-case.php
* @author Grigory Alexandrov <alexaandrov@gmail.com>
@alexaandrov
alexaandrov / wsl.sh
Last active April 11, 2019 07:59
WSL for vagrant in git bash
# Convert path from windows to linux
function lpwd()
{
pwd=$(pwd)
windowsHome=$(echo $HOME)
linuxHome="~"
lpwd=${pwd/$windowsHome/$linuxHome}
echo $lpwd
}
@alexaandrov
alexaandrov / rt.sh
Last active March 1, 2021 10:22
Response Time Site Utility
#/bin/sh
uri=$1
repeat=1
if [[ ! -z $2 ]]; then
repeat=$2
fi
while [ $repeat -gt 0 ]; do