<?php
/**
 * AJAX修改表情代码
 * @author yzxh24
 */
class EditCodeAction extends BaseAction
{
    public function run()
    {
        $code = trim(Yii::app()->request->getPost('code'));
        $id = intval(Yii::app()->request->getQuery('id'));
        
        $smile = Smiles::model()->findByPk($id);
        if (empty($smile))
        {
            echo '不存在的表情';
            Yii::app()->end();
        }

        $check = Smiles::model()->find('code=:code', array(':code'=>$code));
        if (!empty($check))
        {
            echo $code . '表情代码已经存在，请换一个';
            Yii::app()->end();
        }
        
        $smile->code = $code;
        $smile->save();
        Yii::app()->end();
    }
}