fecshop service一点建议

技术分享 · dionyang · 于 6年前 发布 · 2298 次阅读

service层有一些通用方法,例如GetModelName 有的没有。该方法在自己需要编写RestFul接口时要用到。建议将该方法写在Service类下,或者使用trait引入。

	/**
     * 得到category model的全名.
     */
    protected function actionGetModelName()
    {
        return get_class($this->_article->getByPrimaryKey());
    }
共收到 4 条回复
Fecmall#16年前 0 个赞

好的,我先记录一下这个。

dionyang#26年前 0 个赞

@Terry #1楼 另外 sql表里的创建时间和更新时间更新 建议在model层里使用timestampbehavior来进行。现在时间更新好像是放在block层的。

Fecmall#36年前 0 个赞

@dionyang #2楼 OK,放到model里面更透明一些。

这个等功能完善了,在回头优化下。

dionyang#46年前 1 个赞

@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()
            ]
        ];
    }
}

好的 附上代码

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics