Find us on facebook

Jun 25, 2014

Add a field that is not a table field into grid in YII

public $date;
public $time;
public $datetime;
public $order_type;

public function attributeLabels()
{
return array(
'datetime' =>'Delivery/Collection Date & Time',
'order_type' =>'Order Type',
etc...
); }

protected function afterFind() {
parent::afterFind();
//$delivery_date_new = strstr($this->delivery_date, '+', true);

if(strpos($this->delivery_date,'+') !== false){
$pieces = explode(" ", $this->delivery_date);
$timenew=explode(":", $pieces[1]);
$this->time=$timenew[0].":".$timenew[1];
$this->date = $pieces[0];
$this->datetime=$this->date." ".$this->time;
}else{
$this->time = $this->dilivery_time;
$this->date = $this->delivery_date;
$this->datetime=$this->delivery_date." ".$this->dilivery_time;
}
if ($this->delivery_type == 0)
{
$this->order_type = "Takeaway";
} elseif ($this->delivery_type == 1) {
$this->order_type = "Delivery";
} else {
$this->order_type = "Table";
}



return $this;
}

Web Service to send user profile details to Android IOS - YII

public function actionGetUserProfileData() {
   
 $this -> layout = false;
 header('Content-type: application/json');

  $uid = $_GET['uid'];
 
   $profiles = Profiles::model()->findByPk($uid);
    $userProfileData = array(
    'firstname'    => $profiles->firstname,
    'street_address'  => $profiles->street_address,
    'city'     => $profiles->city,
    'contact_no'   => $profiles->contact_no,
    'country_code'   => $profiles->country_code,
   
   );



 echo CJSON::encode($userProfileData);
 Yii::app() -> end();


}

Web Service to update data in DB with Android or IOS - YII

public function actionGetGcm() {

try {

if ((isset($_POST['token'])) && !empty($_POST['token'])&&(isset($_POST['customer_id'])) && !empty($_POST['customer_id'])) {

$token = $_POST['token'];
$customer_id = $_POST['customer_id'];
$Pda = new Pda;
$Pda -> gcm_token = $token;
$Pda -> customer_id = $customer_id;
$Pda -> save();
if($Pda->save()){
$msg = CJSON::encode(array( array('success' => "success", 'message' => 'exception','pda_id'=>$Pda->id)));
echo $msg;
}else{
$msg = CJSON::encode(array( array('success' => "false", 'message' => 'exception')));
echo $msg;
}
}

} catch (Exception $exc) {
$msg = CJSON::encode(array( array('success' => "false", 'message' => 'exception')));
echo $msg;
}

}

Can test function using  http://www.hurl.it/

array_multisort

$sortArray = array();

foreach($displays as $display){
foreach($display as $key=>$value){
if(!isset($sortArray[$key])){
$sortArray[$key] = array();
}
$sortArray[$key][] = $value;
}
}

$orderby = $groups[0];

array_multisort($sortArray[$orderby],SORT_DESC,$displays);
print_r($sortArray);exit;

Jun 6, 2014

Restore a large MySQL database using cmd in Windows machine

First open the cmd

Change the directory to mysql installed directory's bin. Mine is
D:/wamp/bin/mysql/mysql5.5.24/bin

D:/wamp/bin/mysql/mysql5.5.24/bin> mysql -u root -p

mysql> create database mydb;
mysql> use mydb;
mysql> source db_backup.sql;

For dump file
mysql> source db_backup.dump;

OR
First open the cmd

Change the directory to mysql installed directory's bin. Mine is
D:/wamp/bin/mysql/mysql5.5.24/bin

D:\wamp\bin\mysql\mysql5.5.24\bin>mysql -u root -p testing1 < D:\test2.sql

OR (For file type :File MySQL dump 10.13  Distrib 5.1.73, for redhat-linux-gnu (x86_64))
First open the cmd

Change the directory to mysql installed directory's bin. Mine is
D:/wamp/bin/mysql/mysql5.5.24/bin

D:\wamp\bin\mysql\mysql5.5.24\bin>mysql -u root testing1<test