service层有一些通用方法,例如GetModelName 有的没有。该方法在自己需要编写RestFul接口时要用到。建议将该方法写在Service类下,或者使用trait引入。
/** * 得到category model的全名. */ protected function actionGetModelName() { return get_class($this->_article->getByPrimaryKey()); }
好的,我先记录一下这个。
@Terry #1楼 另外 sql表里的创建时间和更新时间更新 建议在model层里使用timestampbehavior来进行。现在时间更新好像是放在block层的。
@dionyang #2楼 OK,放到model里面更透明一些。
这个等功能完善了,在回头优化下。
@Terry #3楼
namespace appserver\local\local_modules\mysqldb\customer; use yii\behaviors\TimestampBehavior; class Address extends \fecshop\models\mysqldb\customer\Address{ public function behaviors() { return [ [ 'class'=>TimestampBehavior::className(), 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => 'updated_at', 'value' => time() ] ]; } }
好的 附上代码