ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
##**控制器** ###*mvc样本* * * * * * ~~~ <?php declare(strict_types = 1); namespace app[\home]\controller; final class Index extends \msqphp\core\controller\Controller { public function index() { } } ~~~ ###*非mvc样本* * * * * * ~~~ <?php declare(strict_types = 1); namespace app[\home]\index; final class Controller extends \msqphp\core\controller\Controller { public function index() { } } ~~~ ###*控制器注* * * * * * + **不推荐手动引入任何框架类文件,或者使用框架内的命名空间,避免各种架构调整,使用万能get或万能call实现基本需求** >在 >library/msqphp/framework/core/controller/gets和call >下配置 + **逻辑层,不是实现层** + **逻辑层,不是实现层** + **逻辑层,不是实现层** + **尽量避免出现原生函数什么的,除非特别简单什么的** + **处理依赖action,读取依赖model,展示依赖view** ###*控制器get* * * * * * **(以下---->理解为等效)** ####基类使用 * * * * * ~~~ $this->基类名称 = 对应基类命名空间 /** * @example */ $this->str ----> '\msqphp\base\str\Str' $this->json ----> '\msqphp\base\json\Json' $this->基类名称::方法名(参数1, 参数2) = 调用对应基类对应方法 /** * @example */ $this->str::random(32) ----> \msqphp\base\str\Str::random(32) $this->json::encode($data) ----> msqphp\base\json\Json::encode($data) /** * @example */ //获得高安全的16位字符 $random = $this->str::random(16); ~~~ ####核心类使用 * * * * * ~~~ $this->核心类名称 = 对应核心类实例(大多,部分同基类,为静态类) /** * @example */ $this->cookie ----> \msqphp\core\cookie\Cookie::getInstance(); $this->session ----> \msqphp\core\session\Session::getInstance(); $this->cron ----> \msqphp\core\cron\Cron::getInstance(); 使用 /** * @example */ $this->cookie()->init()->key('test')->value('nihao')->set(); ~~~ ###*控制器call* * * * * * **(以下---->理解为等效)** ~~~ //获得字符串ip $this->getIp() ----> \msqphp\base\ip\Ip::get(); //获得整数ip $this->getIntIp() ----> \msqphp\base\ip\Ip::getInt(); //js弹框并跳转(未指定url,则后退到上个页面); $this->alert(string $msg, string $url = '', $charset='utf-8') ----> \msqphp\base\response\Response::alert($msg, $url, $charset); //跳转 $this->jump(string $url, int $time = 0, string $msg = '') ----> \msqphp\base\response\Response::jump($url, $time, $msg); ~~~ ###*控制器扩展* * * * * * ####万能get **library/msqphp/framework/core/controller/gets/** 下创建对应文件 ####万能call **library/msqphp/framework/core/controller/methods/** 下创建对应文件 ###*控制器例:* ~~~ <?php declare(strict_types = 1); namespace app\home\user; class Controller extends \msqphp\core\controller\Controller { public function login(string $username, string $password) { //获得user处理类 $action = new Action(); //不合法则提示 $action->validator($username,$password) || $this->alert('用户名或密码不合法'); //获得模型 $model = new Model(); //得到用户id,不存在则提示 0 === ($user_id = $model->getUserId($username,$action->getType($username))) && $this->alert('用户名不存在'); //得到密码和盐 $info = $model->getSoltAndPassword($user_id); unset($model); //密码检验 $action->passwordEncrypt($password,$info['user_salt']) === $info['user_pswd'] || $this->alert('密码错误'); unset($action); //session cookie 设置 $cookie_value = ['id'=>$user_id,'password'=>$password,'ip'=>$this->getIntIp()]; //cookie设置 $this->cookie->init()->key('user')->value($cookie_value)->expire(86400)->httponly()->set(); //跳转到首页 注:url是自己定义的一个常量,不是框架所产生的. $this->jump(URL.'index/index'); } } ~~~