##**控制器**
###*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');
}
}
~~~
- 序言
- 框架
- 框架获取
- 框架安装
- 应用结构
- 框架结构
- 应用目录结构
- 框架流程
- 命名规范
- 核心思想
- 扩展
- 类组装
- 框架基类
- Arr
- Arr扩展函数
- Date基类
- Dir
- Dir基类扩展函数
- Dom基类
- File基类
- Str基类
- Str随机字符
- Str操作函数
- Str随机创建
- Html基类
- Header基类
- Filter基类
- 框架核心
- 路由
- 路由信息
- 路由安装样本
- 路由逻辑原理
- 路由方法匹配
- 路由分组
- 路由构建
- 路由限制
- 路由规则
- 路由多语,多主题
- 路由常量
- 路由扩展
- 路由例
- 路由真静态使用
- 智能加载
- Response基类
- 定时任务
- 框架主类
- 控制器
- model
- model样本
- model使用
- view
- view路径
- view方法
- view配置
- view使用
- view真静态
- view例
- view多主题
- 模版引擎
- 模版引擎之单句解析
- 模版引擎之foreach解析
- cache
- cache注意事项
- cache配置
- cache方法
- cache使用
- cache扩展
- cache处理类File配置
- cache处理类Apc,Apcu配置
- cache处理类memcache,memcached配置
- cookie
- session
- 框架扩展
- Upload类
- 测试
- 测试流程
- 测试文件编写
- 测试文件例-数组篇
- 测试类函数
- 测试类使用
- 测试注意事项
- 常用功能
- 读码须知
- 个人技巧或习惯
- 万能get,call,callStatic
- &&和||
- 变量值交换
- trait拼接
- 多语支持