create() 공개 정적인 메소드

写入数据
public static create ( array $data = [] )
$data array 数据数组
 /**
  * 注册处理
  */
 public function do_register()
 {
     $username = I('username');
     $password = I('password');
     $repassword = I('repassword');
     if (empty($username)) {
         $this->error('用户名不能为空');
     }
     if (empty($password)) {
         $this->error('密码不能为空');
     }
     if ($password != $repassword) {
         $this->error('确认密码错误');
     }
     //检测用户是否已注册
     $model = new Model('User');
     $user = $model->where(array('username' => $username))->find();
     if (!empty($user)) {
         $this->error('用户名已存在');
     }
     $data = array('username' => $username, 'password' => md5($password), 'created_at' => time());
     if (!($model->create($data) && $model->add())) {
         $this->error('注册失败!' . $model->getDbError());
     }
     $this->success('注册成功,请登录', U('login'));
 }
예제 #2
0
 public function create($data = '', $type = '')
 {
     $data = parent::create($data, $type);
     if (!empty($data['attribute'])) {
         $ma = M('GoodsAttribute');
         if ($ma->create($data['attribute'])) {
         } else {
         }
     }
     return $data;
 }
예제 #3
0
 public function create($data = '', $type = '')
 {
     $data = parent::create($data, $type);
     if (!empty($data)) {
         foreach ($data as $key => $val) {
             if (is_array($data[$key])) {
                 $this->data[$key] = implode(',', $data[$key]);
             }
         }
     }
     return $data;
 }
 /**
  * 留言处理
  */
 public function do_post()
 {
     $this->checkLogin();
     $content = I('content');
     if (empty($content)) {
         $this->error('留言内容不能为空');
     }
     if (mb_strlen($content, 'utf-8') > 100) {
         $this->error('留言内容最多100字');
     }
     $model = new Model('Message');
     $userId = session('user.userId');
     $data = array('content' => $content, 'created_at' => time(), 'user_id' => $userId);
     if (!($model->create($data) && $model->add())) {
         $this->error('留言失败');
     }
     $this->success('留言成功', U('Index/index'));
 }
예제 #5
0
파일: Storage.php 프로젝트: cjango/cwms
 /**
  * 上传文件
  * @param  string $name    input name
  * @param  array  $options 扩展配置
  * @return array|boolean
  */
 public function upload($name = '', $options = [])
 {
     $File = Request::instance()->file($name);
     // 检查是否有该文件,如果上传过,直接返回文件信息
     $info = $this->where('hash', $File->hash())->find();
     if ($info) {
         return ['file_id' => $info->id, 'path' => ltrim($info->path, '.')];
     }
     // 合并扩展选项
     $config = Config::get('storage');
     if (is_array($options) && !empty($options)) {
         $config = array_merge($config, $options);
     }
     // 校验文件是否允许上传
     if (!$File->check($config)) {
         $this->error = $File->getError();
         return false;
     } else {
         // 保存的规则
         $File->rule(function ($file) {
             $rule = explode('/', $file->getMime())[0] . '/';
             $rule .= date('Y-m/d');
             $rule .= '/' . $file->hash();
             $rule .= '.' . strtolower(pathinfo($file->getInfo('name'), PATHINFO_EXTENSION));
             return $rule;
         });
         // 上传文件
         $info = $File->move($config['path'], true, $config['replace']);
         if ($info) {
             $data = ['type' => explode('/', $info->getMime())[0], 'name' => rtrim($info->getInfo('name'), '.' . $info->getExtension()), 'ext' => $info->getExtension(), 'hash' => $info->hash(), 'path' => ltrim($info->getPathname(), '.'), 'size' => $info->getSize()];
             // 保存文件信息
             if ($insert = parent::create($data)) {
                 return ['file_id' => $insert->id, 'path' => ltrim($insert->path, '.')];
             } else {
                 $this->error = '数据保存失败';
                 return false;
             }
         } else {
             $this->error = $File->getError();
             return false;
         }
     }
 }