树枝和功能的问题

时间:2015-10-26 00:58:00

标签: php function authentication twig slim

我正在尝试检查权限级别,但唯一有效的功能是Int...,当func sumOf(numbers: Int...) -> Int { var sum = 0 for number in numbers { sum += number } return sum } sumOf() sumOf(42, 597, 12) auth.perm_one等相同时..用户具有权限级别数据库中的10个。

我已在下面发布了所有相关代码。

中间件文件:

perm_two

用户文件:

perm_three

我试图实现这个目标:

<?php

namespace BSA\Middleware;

use Slim\Middleware;

class BeforeMiddleware extends Middleware
{
    public function call()
    {
        $this->app->hook('slim.before', [$this, 'run']);

        $this->next->call();
    }

    public function run()
    {
        if (isset($_SESSION[$this->app->config->get('auth.session')])){
            $this->app->auth = $this->app->user->where('id', $_SESSION[$this->app->config->get('auth.session')])->first();
        }

        $this->app->view()->appendData([
            'auth' => $this->app->auth,
            'baseUrl' => $this->app->config->get('app.url')
        ]);
    }
}

1 个答案:

答案 0 :(得分:1)

我明白了。以下是受影响函数的新代码:

public function hasPermission($permission)
{

    $perm_level = intval($this->perm_level);
    $permission = $permission - 1;

    if ($perm_level > $permission) {return true;} else {return false;}

}