Ejemplo n.º 1
0
 /**
  * 运行MVC处理模型
  * @param $url_processor
  * @return None
  */
 function runMVC()
 {
     $mvc = $this->urlRoute();
     if ($mvc === false) {
         \Swoole\Http::status(404);
         return Swoole\Error::info('MVC Error', "url route fail!");
     }
     //check
     if (!preg_match('/^[a-z0-9_]+$/i', $mvc['controller'])) {
         return Swoole\Error::info('MVC Error!', "controller[{$mvc['controller']}] name incorrect.Regx: /^[a-z0-9_]+\$/i");
     }
     if (!preg_match('/^[a-z0-9_]+$/i', $mvc['view'])) {
         return Swoole\Error::info('MVC Error!', "view[{$mvc['view']}] name incorrect.Regx: /^[a-z0-9_]+\$/i");
     }
     if (isset($mvc['app']) and !preg_match('/^[a-z0-9_]+$/i', $mvc['app'])) {
         return Swoole\Error::info('MVC Error!', "app[{$mvc['app']}] name incorrect.Regx: /^[a-z0-9_]+\$/i");
     }
     $this->env['mvc'] = $mvc;
     $controller_path = self::$app_path . "/controllers/{$mvc['controller']}.php";
     if (!class_exists($mvc['controller'], false)) {
         if (!is_file($controller_path)) {
             \Swoole\Http::status(404);
             return Swoole\Error::info('MVC Error', "Controller <b>{$mvc['controller']}</b> not exist!");
         } else {
             require_once $controller_path;
         }
     }
     //服务器模式下,尝试重载入代码
     if (defined('SWOOLE_SERVER')) {
         $this->reloadController($mvc, $controller_path);
     }
     $class = $mvc['controller'];
     $controller = new $class($this);
     if (!is_callable(array($controller, $mvc['view']))) {
         \Swoole\Http::status(404);
         return Swoole\Error::info('MVC Error!' . $mvc['view'], "View <b>{$mvc['controller']}->{$mvc['view']}</b> Not Found!");
     }
     if (empty($mvc['param'])) {
         $param = null;
     } else {
         $param = $mvc['param'];
     }
     $method = $mvc['view'];
     $return = $controller->{$method}($param);
     //保存Session
     if ($this->session->open and $this->session->readonly === false) {
         $this->session->save();
     }
     //响应请求
     if ($controller->is_ajax) {
         header('Cache-Control: no-cache, must-revalidate');
         header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
         header('Content-type: application/json');
         $return = json_encode($return);
     }
     if (defined('SWOOLE_SERVER')) {
         return $return;
     } else {
         echo $return;
     }
 }
Ejemplo n.º 2
0
 function delmail()
 {
     if (empty($_GET['mid'])) {
         die;
     }
     $id = (int) $_GET['mid'];
     $_m = model('UserMail');
     $ms = $_m->get($id);
     //发信人
     if ($ms->fid == $this->uid) {
         if ($ms->mstatus == 5) {
             $ms->delete();
         } else {
             $ms->mstatus = 4;
             $ms->save();
         }
         return Swoole\JS::js_back('删除成功');
     } elseif ($ms->tid == $this->uid) {
         if ($ms->mstatus == 4) {
             $ms->delete();
         } else {
             $ms->mstatus = 5;
             $ms->save();
         }
         return Swoole\JS::js_back('删除成功');
     } else {
         Swoole\Http::response('Error!');
     }
 }