Skip to content

Instantly share code, notes, and snippets.

View maximishchenko's full-sized avatar

Maxim Ishchenko maximishchenko

  • Russia
View GitHub Profile
@maximishchenko
maximishchenko / YII_photo_nophoto.php
Created September 17, 2015 17:17
Yii if image exist show image else show nophoto.png
<?php
echo !empty($model-><field>) && file_exists(Yii::getPathOfAlias('webroot.images')."<PATH>".$model-><field>) ? CHtml::image(Yii::app()->baseurl."<PATH>".$model-><field>,"",array("style"=>"width:50px;height:50px;align:center;")) : CHtml::image(Yii::app()->baseurl."/<PATH>/no_img.png","",array("style"=>"width:50px;height:50px;align:center;"));
?>
@maximishchenko
maximishchenko / Yii_delete_file_when_delete_record.php
Last active September 17, 2015 18:30
Yii delete uploaded file when delete record from database
<?php
// Add to current model
protected function beforeDelete()
{
if (parent::beforeDelete()) {
// file_field_name - db field that contains name of uploaded file
if ($this-><file_field_name>)
// webroot.images - path to images forlder (such as Yii::app()->baseurl."/images/")
// if using another forder name (for example: /upload/) - Yii::getPathOfAlias('webroot.upload')
@unlink(Yii::getPathOfAlias('webroot.images') . "DIRECTOTY_SEPARATOR" . $this-><file_field_name>);
@maximishchenko
maximishchenko / YII_single_file_upload_create_and_update.php
Last active September 17, 2015 21:43
Yii upload single file (action "create" and "update")
<?
// There and next:
// webroot.images - path to images forlder (such as Yii::app()->baseurl."/images/")
// if using another forder name (for example: /upload/) - Yii::getPathOfAlias('webroot.upload')
// file_field_name - db field that contains name of uploaded file
// DIRECTORY_SEPARATOR - separator, such as "/" or included folders
// PATH_TO_IMAGE_FOLDER - full path to folder with images
// Previously added CImageHandler and Fancybox extensions
// CImageHandler:
@maximishchenko
maximishchenko / Yii_link_inside_GridView.php
Created September 17, 2015 21:18
Yii link inside GridView
@maximishchenko
maximishchenko / Yii_delete_link_like_Bootstrap_button.php
Created September 17, 2015 22:52
Yii delete link like Bootstrap Button
@maximishchenko
maximishchenko / Yii_multiple_delete_with_delete_files.php
Last active September 18, 2015 10:04
Yii Multiple Delete Records with delete files
<?php
// There and next:
// ids - the id's of GridView's checkbox column
// <grid-id> - the id's of GridView
// View code
$this->widget('bootstrap.widgets.TbButton', array(
'label'=>'Удалить',
'type'=>'danger',
@maximishchenko
maximishchenko / Yii_ajax_loading_example.php
Created September 18, 2015 12:00
Yii add ajax loading indicator
<?php
$this->widget('bootstrap.widgets.TbButton', array(
'label'=>'<ButtonName>',
'type'=>'ButtonType',
'buttonType'=>'ajaxButton',
'encodeLabel'=>true,
'url'=>Yii::app()->createUrl('/<module>/<controller>/<action>'),
'ajaxOptions'=>array(
// Method - POST (for $_POST requests) or GET (for $_GET requests)
@maximishchenko
maximishchenko / Yii_link_to_div.php
Created September 20, 2015 08:50
Yii link to div (custom place on page)
@maximishchenko
maximishchenko / Install_Yii2_create_application
Created October 1, 2015 10:46
Install Yii2 into Linux-server and create an application
# SSH-session
# Install Composer to /bin directory
php -r "readfile('https://getcomposer.org/installer');" | php -- --filename=composer --install-dir=/bin
# Install composer plugin to work with Bower
composer global require "fxp/composer-asset-plugin:~1.0.0"
// Go to www-folder
cd /www-folder
@maximishchenko
maximishchenko / MS_SQL_2008_backup_table_into_another_new_table.sql
Created October 21, 2015 10:58
MS SQL 2008 backup table into another new table
/******
SELECT * INTO [db_name].[db_prefix].[new_table_name] FROM [db_name].[db_prefix].[old_table_name]
Example:
******/
SELECT * INTO [test].[dbo].[VRD_CarSaleContractFilePathNew] FROM [test].[dbo].[VRD_CarSaleContractFilePath]