codeigniter-4 - 过滤器在 Codeiginter 4 中不起作用
问题描述
我正在使用框架 Codeiginter 4(学习)。我正在使用过滤器来验证会话,但过滤器不起作用。你能帮助如何在 CI4 中使用过滤器。如果我没有登录需要加载登录页面......无需重定向到那个特定的控制器。
我的过滤器代码:
<?php
namespace App\Filters;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;
class Auth implements FilterInterface
{
public function before(RequestInterface $request, $arguments = null)
{
$session = session();
if(!$session->has('logged_user')){
return redirect()->to('/Login');
}
}
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
{
// Do something here
}
}
在配置\过滤器
public $aliases = [
'csrf' => CSRF::class,
'toolbar' => DebugToolbar::class,
'honeypot' => Honeypot::class,
'auth' => \App\Filters\Auth::class,
'noauth' => \App\Filters\NoAuth::class,
];
路由.php
$routes->get('dashboard','Dashboard::index',['filter' =>'auth']);
$routes->get('role/index','Role::index',['filter' =>'auth']);
请帮我解决这个问题。我很累但不为我工作
解决方案
推荐阅读
- php - 如何获取PHP中关联数组的两个多维数组之间的差异?
- node.js - 应该通过正文发送 null 或空字符串值吗?
- python - 如何使用 python 收集获取 url 并移动到详细的链接数据
- dialogflow-es - Dialogflow Essentials“培训”几天不工作。有什么解决方法吗?
- sql - 如何以逗号 (,) 字符分隔的字符串形式返回 XML 嵌套节点的行
- flutter - Flutter/Dart 中的多行字符串到单行字符串
- create-react-app - 如何修复 create-react-app 中的 immer.js 问题?
- microsoft-graph-api - 如何在 o365 Graph API 中获取访问令牌以进行投诉
- javascript - 发送的 SuiteCRM 电子邮件由收件人接收一次,但电子邮件将在已发送项目上显示两次
- python - 循环合法参数