Skip to content

Instantly share code, notes, and snippets.

View umidjons's full-sized avatar
🏠
Working from home

Umid umidjons

🏠
Working from home
View GitHub Profile
@umidjons
umidjons / ctimestamp-behavior-yii.php
Created February 25, 2014 05:50
Yii: CTimestampBehavior example to automatically set create and update datetimes
<?php
/**
* This is the model class for table "news_comments".
*
* The followings are the available columns in table 'news_comments':
* @property string $id
* @property integer $news_id
* @property string $author
* @property string $text
@umidjons
umidjons / form-prevent-resend-data-yii.php
Last active August 29, 2015 13:56
Yii: Prevent resending form data on page refresh by using CController::refresh() method
<?php
public function actionAddComment( News $news )
{
$comment = new NewsComments();
if ( isset( $_POST[ 'NewsComments' ] ) )
{
$comment->attributes = $_POST[ 'NewsComments' ];
$comment->news_id = $news->id;
// if user authorized, then get name directly from the user model
@umidjons
umidjons / RegisterForm.php
Created March 3, 2014 05:41
Yii: User registration, roles & privileges
<?php
class RegisterForm extends CFormModel
{
public $username;
public $password;
public $password_repeat;
public $email;
private $_identity;
@umidjons
umidjons / News.php
Created March 6, 2014 03:56
Yii: sort and filter related table column in CGridView
<?php
class News extends CActiveRecord
{
public $author_search;
public function rules()
{
return [
// ...
[ 'id, title, text, author_id, author_search', 'safe', 'on' => 'search' ],
@umidjons
umidjons / linear-gradient.styl
Created March 6, 2014 04:01
Stylus: mixin for linearGradient
linearGradient($startColor, $endColor)
background $startColor
background -moz-linear-gradient(top, $startColor 0%, $endColor 100%)
background -webkit-gradient(linear, left top, left bottom, color-stop(0%, $startColor), color-stop(100%, $endColor))
background -webkit-linear-gradient(top, $startColor 0%, $endColor 100%)
background -o-linear-gradient(top, $startColor 0%, $endColor 100%)
background -ms-linear-gradient(top, $startColor 0%, $endColor 100%)
background linear-gradient(to bottom, $startColor 0%, $endColor 100%)
filter unquote("progid:DXImageTransform.Microsoft.gradient(startColorstr='" + $startColor + "', endColorstr='" + $endColor + "', GradientType = 0)")
@umidjons
umidjons / yii-clips.php
Last active August 29, 2015 13:57
Yii: using clips - captured output (CClipWidget example)
<?php
/* @var MyController $this */
$this->beginWidget( 'CClipWidget', [ 'id' => 'sidebar' ] ); // start clipping with id
// here are some useful & common outputs...
$this->endWidget(); // stop clipping
// somewhere else use clip:
echo $this->clips[ 'sidebar' ];
@umidjons
umidjons / yii-change-password-if-not-empty.php
Created March 6, 2014 10:28
Yii: change user's password if new one typed (not empty), otherwise do not change
<?php
class User extends CActiveRecord
{
public function rules()
{
return [
[ 'username, email', 'required' ],
[ 'password', 'required', 'on' => 'insert, changePassword' ], // require on insert, also on changePassword scenarios
[ 'email', 'length', 'min' => 3, 'max' => 128 ],
[ 'email', 'email' ],
@umidjons
umidjons / cgridview-custom-button-customize-buttons.php
Created March 7, 2014 05:49
Yii: Custom button on CGridView, configure CButtonColumn buttons
<?php $this->widget( 'zii.widgets.grid.CGridView', array(
'id' => 'news-grid',
'dataProvider' => $model->search(),
'filter' => null,
'itemsCssClass' => 'table table-striped table-hover table-condensed', // twitter bootstrap table
'template' => '{items}{pager}', // no summary
'columns' => [
'id',
'title',
[
@umidjons
umidjons / _search.php
Created March 7, 2014 05:59
Yii: Advanced search form with Twitter Bootstrap controls/components
<?php
/* @var $this NewsController */
/* @var $model News */
/* @var $form CActiveForm */
?>
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle collapsed" href="#collapseOne" data-toggle="collapse" data-parent="#accordion">
@umidjons
umidjons / ejui-date-time-picker.md
Last active August 29, 2015 13:57
Yii: using EJuiDateTimePicker example

Download EJuiDateTimePicker from Github repo Extract extension into ext.juidatetimepicker folder. Enable auto-loading:

<?php
'import'     => [
    // ...
    'ext.juidatetimepicker.EJuiDateTimePicker',
],