更正 PHP 模型之间关系的语法?
Correct PHP syntax for relation between models?
我有 2 个模型、汽车和品牌
当我想创建新车并设置值时,一切正常
$car->setName('Golf V');
$car->setYear('2015'); // setYear on $car
$car->setNote('This car has electric problems'); // setNote on $car
但是如果我想设置与其他 table 相关的品牌,则会出现错误:必须是 Salon\Models\Brand 的实例所有 ID 都存在,只有插入是问题,我试过的是:
$car->setBrand(\Salon\Models\Brand = $_['brand_id']);
$car->setBrand(\Salon\Models\Brand::getId()->$_['brand_id']);
这当然不正确,但谁能告诉我正确的语法?
我认为你应该先了解 SOLID 原则,才能解决这类问题。
你可以看看S.O.L.I.D特别是接口隔离原则
我有 2 个模型、汽车和品牌
当我想创建新车并设置值时,一切正常
$car->setName('Golf V');
$car->setYear('2015'); // setYear on $car
$car->setNote('This car has electric problems'); // setNote on $car
但是如果我想设置与其他 table 相关的品牌,则会出现错误:必须是 Salon\Models\Brand 的实例所有 ID 都存在,只有插入是问题,我试过的是:
$car->setBrand(\Salon\Models\Brand = $_['brand_id']);
$car->setBrand(\Salon\Models\Brand::getId()->$_['brand_id']);
这当然不正确,但谁能告诉我正确的语法?
我认为你应该先了解 SOLID 原则,才能解决这类问题。
你可以看看S.O.L.I.D特别是接口隔离原则