Skip to content

Instantly share code, notes, and snippets.

@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 / 1C-sample
Created March 29, 2016 14:52
1С пример кода
&НаКлиенте
Функция РассчитатьПроцентНаценки(ЦенаЗакупки, ЦенаПродажи)
ПроцентНаценки = 0;
Если ЦенаЗакупки <> 0 Тогда
ПроцентНаценки = (ЦенаПродажи - ЦенаЗакупки) * 100 / ЦенаЗакупки;
КонецЕсли;
Возврат ПроцентНаценки;
КонецФункции
@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_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;
# JetBrains IDE
.idea
# Windows thumbnail cache
Thumbs.db
desktop.ini
debug.log
# Mac DS_Store Files
*.DS_Store
<?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
@alexaandrov
alexaandrov / laravel-nginx.conf
Last active March 22, 2024 18:49
laravel nginx virtual host config
server {
listen 80;
server_name laravel.loc;
root /vagrant/www/laravel.loc/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
@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>