Friday 6 May 2016

Yii2 slect query in model

  $model = Employee::find()
              ->where(['e_name' => $id,'e_email'=>$email])
              ->all();
              return $model;
[Here Employee is table name]

Yii Time formating

// Config file
'formatter' => [
       'class' => 'yii\i18n\Formatter',
       'dateFormat' => 'd-M-Y',
       'datetimeFormat' => 'd-M-Y H:i:s',
       'timeFormat' => 'H:i:s',
       'timeZone'=>'asia/kolkata'],
//// Controller file on head
use yii\i18n\Formatter;
//cod in controller
$timekey = Yii::$app->formatter->asdateTime(date('U'));[write this whenever you want to use, Here formatter is depend of confing gile]

Yii Preety URL

// in Web config
    'urlManager'=>[
            'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
             'showScriptName' => false,   // Disable index.php
             'suffix'=>'.php',
              'rules' => array(
               
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
        ),
          
        ],

Yii2 encryt decrypt

//Controller header
use yii\base\Security;
//Controller code
echo Yii::$app->security->encryptByKey($timekey, "bsquaresoft");

Yii response json


// In controller action

\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
and then
$items = ['code'=>'1','message'=>'successful','model'=>$model];
        return $items;
[Here Items will be in json format]

Yii2 Mail

For more information  http://stackoverflow.com/questions/24995620/how-to-use-the-swiftmailer-in-yii2


http://yii-02.blogspot.in/2015/01/yii2-lesson-21-sending-emails-with.html

Nearest Location within 10 km in php

http://theoryapp.com/nearest-neighbor-search-by-distance-in-large-datasets-with-mysql/

For multiple json php ajax jquery

$link = mysqli_connect("localhost", "root", "", "direct_power");
$sql = "select * from table_1";
$result =  mysqli_query($link, $sql);

$arr = array();
$mon = array();

while($rows = mysqli_fetch_array($result))
{
$arr[] = $rows;
}
//header('Content-type: application/json');
//$arr[] = $rows;
$mon = ['about'=>'compnany','detail'=>$arr,'days'=>array('monday','tuesday','wednesday','thirsday')];
echo json_encode($mon,JSON_PRETTY_PRINT);
exit();

//Ajax jquery code
function test()
{
var form_data = $('#frm1').serializeArray();
console.log(form_data);
$.ajax({
type: "POST",
data: {
form_data:form_data
},

url: '../controller/table1_handller.php',
success: function(data) {
console.log(data);
var x = JSON.parse(data);
//console.log(x[0].name);
   //console.log(Object.keys(x ).length); // to cont json size pass only "parsed variable " here like 'x' not "data"
   $.each(x.detail, function (index, value) {
   $("#roll_no").prepend(value['name']);
});
   $.each(x.days, function (index, value) {
   $("#days").prepend(value);
});
}
}); 

slider when ajax request [AJAX,PHP,HTML]

// Css class for look when request going

#overlay {
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 999;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    display: none;
    text-align: center;
}



// HTML code for div

<div id="overlay">
<img id="loading-image" src="http://www.memegen.com/img/ajax-loader-99.gif" alt="Loading.." />
<span>Loading Please wait</span>
</div>



//jQuery code when page loading

$("form#data3").submit(function(event){
$("#overlay").show();//[show this class, This is important when request create]
event.preventDefault();
var formData = new FormData($(this)[0]);
if(filename == null )
{
alert("Please select file");
}
else
{

$.ajax({
url: 'upload.php',
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function (returndata) {
$("#overlay").hide();//[Hide this class, This is important when request finish]
$( "#roundedFour" ).prop( "checked", true);
var uploaded_file = $("#last_uploaded_url").val();
$(".add").html("http://localhost/Mobilize_Solutions/uploads/"+uploaded_file);

}
});
return false;
}
});