栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP > php开源框架 > msqphp

控制器 - msqphp轻量级php7.1框架beta -1.9版本使用手册

msqphp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

控制器 - msqphp轻量级php7.1框架beta -1.9版本使用手册


##**控制器**

###*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');
}
}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/213944.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号