For Programming
6 subscribers
4 photos
1 video
12 links
Download Telegram
\Yii::$app->view->registerLinkTag(['rel' => 'icon', 'type' => 'image/png', 'href' => Url::to(['/favicon.png'])]);

Controllerdan turib browser tabga icon berish
'attribute' => 'status',
'format' => 'raw',
'filter' => Html::activeDropDownList($searchModel, 'status', ['1' => 'O\'qilmagan', '0' => 'O\'qilgan'], ['class' => 'form-control', 'prompt' => 'Barchasi']),

yii2 gridviewda search collumni dropdownli qilish
hozirgi vaqtga yana 20 daqiqa qo'shish

$time = 20;
echo $time = date("H:i", strtotime('+ ' . $time . ' minute')) . ":00";
before

public function insertMessage($response, $chat_id, $order_code_id)
{
$model = new MessageId();
$message_id = $response->result->message_id;
$model->message_id = $message_id;
$model->chat_id = $chat_id;
$model->order_code_id = $order_code_id;
return $model->save();
}

after

public function insertMessage($response, $chat_id, $order_code_id)
{
$model = new MessageId();
if ($response->ok === true) {
$message_id = $response->result->message_id;
$model->message_id = $message_id;
$model->chat_id = $chat_id;
$model->order_code_id = $order_code_id;
return $model->save();
}
}

foydalanuvchi botni bloklaganda responsedan message_idni topolmay qoladi shuning uchun response->ok dan true qaytsagina bu amallarni bajarish kerak
Forwarded from thelaziz
ahost da cron yozsa file ochib tashavotudi kamandelani shu kamandaga o'zgartirsela file ochib tashamasakan

wget -O /dev/null -q http://www.example.com/program/timecheck
yii2da updateAll funksiyasini ifni ichiga olish kerak emas sababi update qilishga malumot topolmasa return false qaytaradi
$output = preg_replace('/(<[^>]+) style=".*?"/i', '', $input);
$clients = Clients::find()->select('id')->where(['not', ['chat_id' => null]]);
SELECT `id` FROM `clients` WHERE NOT (`chat_id` IS NULL)
SELECT `id` FROM `clients` WHERE `chat_id` IS NOT NULL


hammasi bir hil natija beradi yani chat_id ni null emasligiga tekshiradi
if (count($array) > 0) {
// simple code...
}

if (!empty($array)) {
// simple code...
}

if (!!$array) {
// recommended code...
}
@ operatori o'zgaruvchi yo'q elon qilinmagan bolsa yoki qiymatlanmagan bo'lsa null qaytaradi
Controllerdagi kod

public function actionCreate()
{
if (Yii::$app->request->isAjax) {
$model = new Product();
$product_price = new ProductPrice();
$currency = Currency::find()->where(['status' => Currency::STATUS_ACTIVE])->asArray()->all();
$currency_list = ArrayHelper::map($currency, 'id', 'title');
$category = Category::find()->where(['status' => Category::STATUS_ACTIVE])->asArray()->all();
$category_list = ArrayHelper::map($category, 'id', 'title');
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
if ($model->load(Yii::$app->request->post())) {
$model->imageFile = $_FILES;
if ($model->Upload() && $model->save()) return ['status' => 'success'];
}
return [
'status' => 'error',
'content' => $this->renderAjax('_form.php',[
'model' => $model,
'product_price' => $product_price,
'currency_list' => $currency_list,
'category_list' => $category_list,
]),
];
}
}



Modeldagi kod


public function getExtension()
{
$extension = explode("/", $this->imageFile['imageFile']['type']);
return $extension[1];
}

public function Upload()
{
if ($this->validate()) {
$file_name = date("Y-m-d")."_".rand(1000, 9999) . '.' . $this->getExtension();
move_uploaded_file($this->imageFile['imageFile']['tmp_name'], 'uploads/images/' . $file_name);
$this->image = $file_name;
return true;
}
return false;
}


Jquerydagi kod


$(document).on("click", "#insert-product-form",function(){
var data = new FormData();
var form = $('#product-create-form').serializeArray();
$.each(form, function (key, input) {
data.append(input.name, input.value);
});
var file_data = $("#product-imagefile").prop("files")[0];
data.append("imageFile", file_data);
console.log(data)
$.ajax({
url: '/product/create',
dataType: 'JSON',
type: 'post',
data: data,
contentType: false,
processData: false,
success: function(response){
if (response.status == 'error') {
$('#exampleModal .modal-title').html('Tovar qo\'shish').css({fontSize: 23})
$('#exampleModal .modal-body').html(response.content)
} else if (response.status == 'success') {
$.pjax.reload('#id-pjax')
$(".close").trigger("click");
}
}
});
});



Ajax orqali file yuklanayotganda file malumotlari kelmay qoladi xattoki $_FILES o'zgaruvchisida ham shuning uchun manashu usulda malumotlarni saqlab olsa bo'ladi
For Programming
yii2 paginatsiya xatoliklari $disabledListItemSubTagOptions = ['class'=>'page-link']; $linkContainerOptions = ['class' => 'page-item']; $linkOptions = ['class' => 'page-link']; bo`sh massivlarni shular bilan to`ldirish kerak
pagination xatoligini bunday tuzatish xato o'rniga gridviewni o'zida berib ketgan yaxshi birinchi usulda butun proyektga tasir qilib ketadi. Mana bunday

'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'pager' => [
'class' => '\yii\widgets\LinkPager',
'linkOptions' => ['class' => 'page-link'],
'linkContainerOptions' => ['class' => 'page-item'],
'disabledListItemSubTagOptions' => ['class'=>'page-link']
],
Live stream started
Live stream finished (1 minute)
migratsiyada foregnkey va indexlarni o'chirishda avval foregnkey ochirilishi kerak bo'lmasam hatolik beradi
SERVERGA PHP O"RNATISH

sudo apt update
sudo apt upgrade

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

sudo apt install php8.1-fpm php8.1-cli php8.1-curl php8.1-pgsql php8.1-gd php8.1-mbstring php8.1-mysql php8.1-xml php8.1-zip php8.1-pdo

php -v php versiyasini ko'rish
php -m php modullarini ko'rish
SERVERGA MySQL O"RNATISH

sudo apt update
sudo apt install mysql-server

MySQL ni SOZLASH

sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'mynewpassword';
sudo mysql_secure_installation