Как получить класс через название в строковой переменной?

|
biggy905 2022-06-25 22:30:24
yii2ru-409836.jpg
#offtop
2022-06-26 05:19:47
𝐈 𝐰𝐚𝐬 𝐰𝐢𝐭𝐡𝐨𝐮𝐭 𝐡𝐨𝐩𝐞 𝐮𝐧𝐭𝐢𝐥 𝐈 𝐰𝐚𝐬 𝐢𝐧𝐭𝐫𝐨𝐝𝐮𝐜𝐞𝐝 𝐭𝐨 𝐁𝐢𝐭𝐜𝐨𝐢𝐧 𝐢𝐧𝐯𝐞𝐬𝐭𝐦𝐞𝐧𝐭 𝐰𝐢𝐭𝐡 𝐡𝐢𝐦, 𝐡𝐞’𝐬 𝐭𝐡𝐞 𝐛𝐞𝐬𝐭 𝐭𝐡𝐞𝐫𝐞’𝐬
👇👇👇
https://t.me/joinchat/VtfOMUxsZJQ5YzIx
denfm87 2022-06-26 11:17:45
Подскажите, как заставить понимать decimal колонку базы, как float?
denfm87 2022-06-26 11:17:47
yii2ru-409841.jpg

denfm87 2022-06-26 11:20:22
Не понимаю почему его тут нету https://github.com/yiisoft/yii2/blob/master/framework/db/Schema.php#L630

yii2/Schema.php at master · yiisoft/yii2GitHub
Yii 2: The Fast, Secure and Professional PHP Framework — yii2/Schema.php at master · yiisoft/yii2
denfm87 2022-06-26 11:20:58
Придётся через DI переопределить класс и добавить в метод
denfm87 2022-06-26 11:21:51
Но, почему авторы yii2 не делают приведение decimal к float (phpType)
denfm87 2022-06-26 11:32:52
Если вдруг у кого ещё будет проблема с typeHint для поля decimal
То вот решение
namespace App\System\Extension;

use yii\db\mysql\Schema;

class MySQLSchema extends Schema
{
/**
* @param $column
* @return string
*/
protected function getColumnPhpType($column)
{
if ($column->type === self::TYPE_DECIMAL) {
return ‘double’;
}
return parent::getColumnPhpType($column);
}
}

В свою конфигурацию для контейнера:
‘definitions’ => [
# Добавляем поддержку DECIMAL как FLOAT (phpTypeCast)
Schema::class => [
‘class’ => \App\System\Extension\MySQLSchema::class
],
]

avboro 2022-06-26 17:03:16
Добрый день! кто знает про лексикографический порядок? Есть ли готовая функция в справочнике php?
giu_exe 2022-06-26 18:52:39
Hello everyone, i developed a system in wich i need to exchange notification between users.
I have the A user that books a doctor visit, when he does that a simple notification of booking will arrive to B (our doctor).
In the case B decides to delete the visit, he sends a notification to A to infrom him.
How can i realize that? I’m new with Yii2, please help me
iscarab 2022-06-26 19:01:25
giu_exe 2022-06-26 18:52:39
Hello everyone, i developed a system in wich i need to exchange notification between users.
I have the A user that books a doctor visit, when he does that a simple notification of booking will arrive to B (our doctor).
In the case B decides to delete the visit, he sends a notification to A to infrom him.
How can i realize that? I’m new with Yii2, please help me

You have to learn pure PHP programming before you learn Yii2, Laravel or any other framework.

giu_exe 2022-06-26 19:03:05
I know it
atcq_tt 2022-06-26 19:05:14
giu_exe 2022-06-26 19:03:05
I know it

did you pass the PHP certification exam?

giu_exe 2022-06-26 19:05:49
this is for an university exam
kantemirov_eduard 2022-06-26 20:54:05
giu_exe 2022-06-26 18:52:39
Hello everyone, i developed a system in wich i need to exchange notification between users.
I have the A user that books a doctor visit, when he does that a simple notification of booking will arrive to B (our doctor).
In the case B decides to delete the visit, he sends a notification to A to infrom him.
How can i realize that? I’m new with Yii2, please help me

Use «onesignal», good for your purpose

ax_lab 2022-06-27 13:03:55
Привет, как получить класс через название в строковой переменной?
Есть строка «app\models\Model», я хочу получить Model::class
predvoditelev 2022-06-27 13:04:39
ax_lab 2022-06-27 13:03:55
Привет, как получить класс через название в строковой переменной?
Есть строка «app\models\Model», я хочу получить Model::class

new $class();

ax_lab 2022-06-27 13:05:46
predvoditelev 2022-06-27 13:04:39
new $class();

Class name must be a valid object or a string
Stack trace: #0 /vendor/yiisoft/yii2/db/BaseActiveRecord.php(1243):

anton700 2022-06-27 13:06:53
ax_lab 2022-06-27 13:03:55
Привет, как получить класс через название в строковой переменной?
Есть строка «app\models\Model», я хочу получить Model::class

В yii2 еще есть Yii::createObject

predvoditelev 2022-06-27 13:10:50
ax_lab 2022-06-27 13:05:46
Class name must be a valid object or a string
Stack trace: #0 /vendor/yiisoft/yii2/db/BaseActiveRecord.php(1243):

попробуй \app\models\Model

|