Skip to content

Instantly share code, notes, and snippets.

<?php
if(isset($argv[1]) && $argv[1] !=null && isset($argv[2]) && $argv[2] !=null ){
$start_arr = explode('/',$argv[1]);
$end_arr = explode('/',$argv[2]);
$start_date = $start_arr[2].'-'.$start_arr[1].'-'.$start_arr[0];
$end_date = $end_arr[2].'-'.$end_arr[1].'-'.$end_arr[0];
@YasinPatel
YasinPatel / validation.js
Created July 19, 2017 07:06
Different custom validation in jquery validator
jQuery.validator.addMethod("alphanumeric", function(value, element) { // allow only alpha numric validation
return this.optional(element) || /^[a-zA-Z0-9]+$/.test(value);
});
jQuery.validator.addMethod("letterwithspaces", function(value, element) { // allow only latters with space validation
return this.optional(element) || /^[a-zA-Z]+$/.test(value);
});
jQuery.validator.addMethod("imagetype", function(value, element) { // allow image validation
return this.optional(element) || /^.*\.(jpg|png|jpeg|gif)$/i.test(value);
@YasinPatel
YasinPatel / module.php
Last active January 16, 2019 07:48
Module wise Error Page in Yii2
Yii::$app->errorHandler->errorAction = 'studconsult/default/error';
<?php
namespace app\modules\admin;
class Module extends \yii\base\Module
{
public $controllerNamespace = 'app\modules\admin\controllers';
@YasinPatel
YasinPatel / module.php
Last active July 17, 2017 08:01
Module wise login in yii2
<?php
namespace app\modules\admin;
class Module extends \yii\base\Module
{
public $controllerNamespace = 'app\modules\admin\controllers';
public function init()
{
@YasinPatel
YasinPatel / Load default values in yii2 in model
Created June 28, 2017 06:53
Load default values in yii2 in model
1. by model :
[['attribute', 'second_attribute'], 'default', 'value' => 'something_here'],
2. load attributes in model
$model = new Post();
$model->loadDefaultValues();
@YasinPatel
YasinPatel / web.php
Created June 6, 2017 09:20
Mail setting in Yii2
// SMTP settings to send mail in yii2
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
@YasinPatel
YasinPatel / web.php
Last active July 19, 2017 07:19
Generate custom crud template in yii2
// To create custom admin layout template , Go to config/web.php and add below lines
'modules' => [
'gii' => [
'class' => 'yii\gii\Module', //adding gii module
'allowedIPs' => ['127.0.0.1','192.168.1.*'], //allowing ip's
'generators' => [
'crud' => [ // generator name
'class' => 'yii\gii\generators\crud\Generator', // generator class
'templates' => [ //setting for out templates