How to validate sunday date or skip sunday date in php


Hi Friends
I was working on yii2 framework project in which i as working on delivery date in which it should skip shipping or delivery date on sunday as saturday is also working day,so i came up with idea to validate the number of delivery day from current day by validating sunday in that number of date and add one day if it comes across Sunday.
Example:
<?php
for ($i = 0; $i < $maxShiping; $i++) {
if(date('l', time() + 86400 * $i)=='Sunday'){
$maxShiping = $maxShiping+1;
}
}

Advertisements
Tagged with: , , , , , , , ,
Posted in php

yii2 generate pdf and attach in mail using kartik-v


Hi friends

While i was working with yii2 advanced project for my client,so i was intergrating the kartik-v mailer and pdf package.so while working on ecommerce for triggering mail on order place for customer and support,i came up with solution so i going to share experience here.

First config the common/config/main-local.php with mail setting like:

mailer’ => [
‘class’ => ‘yii\swiftmailer\Mailer’,
‘viewPath’ => ‘@common/mail’,
/ / 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’,
‘username’ => ‘xxxxx@gmail.com’,
‘password’ => ‘xxxxxxxx’,
‘port’ => ‘587’,
‘encryption’ => ‘tls’,
//’useFileTransport’ => true,
],
],

 

And in controller function use this code:

 

$pdf = new Pdf([
// set to use core fonts only
‘mode’ => Pdf::MODE_CORE,
// A4 paper format
‘format’ => Pdf::FORMAT_A4,
// portrait orientation
‘orientation’ => Pdf::ORIENT_PORTRAIT,
‘cssInline’ => ‘.kv-heading-1{font-size:18px}body {color: #333333;}
th { vertical-align: top; background-color: rgb(60, 61, 58); color: #ffffff; }
td { vertical-align: top; }’,
// set mPDF properties on the fly
‘options’ => [‘title’ => ‘Quotation’],
// call mPDF methods on the fly
‘methods’ => [
‘SetHeader’=>[”],
‘SetFooter’=>[‘{PAGENO}’],
]
]);
$mpdf = $pdf->api;
$mpdf->WriteHTML($content); //pdf is a name of view file responsible for this pdf document
$path = $mpdf->Output(Yii::getAlias(‘@frontend’).’/web/uploads/pdf/’.$quotation.’.pdf’, ‘F’);// THIS WILL SAVE THE FILE IN PATH

$emailSend = Yii::$app->mailer->compose([‘html’ =>’order_confirm_customer’],[‘cartModelExist’=>$cartModelExist,’update_model_order’=>$update_model_order,’customer_detail’=>$customer_detail])
->setFrom([“XXX@MAIL.COM”])
->setTo($email)
->setSubject($subject)
->attach(Yii::getAlias(‘@frontend’).’/web/uploads/pdf/’.$quotation.’.pdf’);
return $emailSend->send();

 

Tagged with: , , , , , , , , , ,
Posted in yii2

How to split full name from model into firstname and lastname in yii2 view and concat to save in yii2 model


First create a model of the table using GII tool in yii2,then by using CRUD option in GII create MVC file ,which has create,update function in controller and add rules in model like

[[‘first_name’,’last_name’], ‘trim’],
[[‘first_name’,’last_name’], ‘required’],
[[‘first_name’,’last_name’], ‘string’, ‘max’ => 50],

And variable above rules like

public $first_name;
public $last_name;

As the controller render update.php in view folder,the update file render _form.php

In  _form.php

I added the php code to split username into first name and last name

$parts = explode(” “, $model->name);
$lastname = array_pop($parts);
$firstname = implode(” “, $parts);

$model->first_name = $firstname;
$model->last_name = $lastname;

And the form fields like

<?= $form->field($model, ‘first_name’)->textInput([‘maxlength’ => true]) ?>
<?= $form->field($model, ‘last_name’)->textInput([‘maxlength’ => true]) ?>

In model concat the firstname and lastname into $model->name to save.

$model->name = $this->first_name.’ ‘.$this->last_name;
return $model->save();

 

 

Tagged with: , , , , , , , , , ,
Posted in yii2

My new experience with jquery


Disable the all  input fields with unique (ID) like numbers  in table :

$(“#table_id  input[type=’text’][id=” + id + “]”).prop({
disabled: true
});

Disable the all  Select fields with unique (ID)  like numbers in table :

$(“select[id=” + id + “]”).prop({
disabled: true
});

Change the placeholder text in input field of table by unique (ID) like numbers :

$(“#table_user_lists input[type=’text’][name=’user_name’][id=” + id + “]”).attr(‘placeholder’, user_name);

jquery change function by name attribute of array:

$(‘input[name =”name[]”]’).change(function () { });

Enable the select of unique (ID) on each:

$(“#table_id *[id]”).each(function () {
if ($(this).attr(‘id’) == id) {
$(this).prop(‘disabled’, false);
}
});

Tagged with: , , , , , , , ,
Posted in javascript and jquery

Find mysql_query issue


Paste the code below mysql_query or mysqli_query to find correct issue,recently i used it in project and found that table itself not exited in database.

if (!$res) {
printf(“Error: %s\n”, mysqli_error($this->conn));
exit();
}

Tagged with: , , , , , ,
Posted in php
Follow Tutorial on WordPress.com
categories
Calendar
November 2017
M T W T F S S
« Sep    
 12345
6789101112
13141516171819
20212223242526
27282930  
Follow me on Twitter
Blog Stats
  • 76,471 hits
%d bloggers like this: