##**控制器**
###*mvc样本*
* * * * *
namespace app[home]controller;
final class Index extends msqphpcorecontrollerController
{
public function index()
{
}
}
###*非mvc样本*
* * * * *
namespace app[home]index;
final class Controller extends msqphpcorecontrollerController
{
public function index()
{
}
}
###*控制器注*
* * * * *
+ **不推荐手动引入任何框架类文件,或者使用框架内的命名空间,避免各种架构调整,使用万能get或万能call实现基本需求**
>在
>library/msqphp/framework/core/controller/gets和call
>下配置
+ **逻辑层,不是实现层**
+ **逻辑层,不是实现层**
+ **逻辑层,不是实现层**
+ **尽量避免出现原生函数什么的,除非特别简单什么的**
+ **处理依赖action,读取依赖model,展示依赖view**
###*控制器get*
* * * * *
**(以下---->理解为等效)**
####基类使用
* * * * *
$this->基类名称 = 对应基类命名空间
$this->str ----> 'msqphpbasestrStr'
$this->json ----> 'msqphpbasejsonJson'
$this->基类名称::方法名(参数1, 参数2) = 调用对应基类对应方法
$this->str::random(32) ----> msqphpbasestrStr::random(32)
$this->json::encode($data) ----> msqphpbasejsonJson::encode($data)
//获得高安全的16位字符
$random = $this->str::random(16);
####核心类使用
* * * * *
$this->核心类名称 = 对应核心类实例(大多,部分同基类,为静态类)
$this->cookie ----> msqphpcorecookiecookie::getInstance();
$this->session ----> msqphpcoresessionSession::getInstance();
$this->cron ----> msqphpcorecronCron::getInstance();
使用
$this->cookie()->init()->key('test')->value('nihao')->set();
###*控制器call*
* * * * *
**(以下---->理解为等效)**
//获得字符串ip
$this->getIp() ----> msqphpbaseipIp::get();
//获得整数ip
$this->getIntIp() ----> msqphpbaseipIp::getInt();
//js弹框并跳转(未指定url,则后退到上个页面);
$this->alert(string $msg, string $url = '', $charset='utf-8') ----> msqphpbaseresponseResponse::alert($msg, $url, $charset);
//跳转
$this->jump(string $url, int $time = 0, string $msg = '') ---->
msqphpbaseresponseResponse::jump($url, $time, $msg);
###*控制器扩展*
* * * * *
####万能get
**library/msqphp/framework/core/controller/gets/**
下创建对应文件
####万能call
**library/msqphp/framework/core/controller/methods/**
下创建对应文件
###*控制器例:*
namespace apphomeuser;
class Controller extends msqphpcorecontrollerController
{
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');
}
}



