Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我的模块不工作并显示错误页面_Php_Drupal_Drupal 8_Drupal Modules - Fatal编程技术网

Php 我的模块不工作并显示错误页面

Php 我的模块不工作并显示错误页面,php,drupal,drupal-8,drupal-modules,Php,Drupal,Drupal 8,Drupal Modules,我为Drupal8.9制作了一个模块 在我的/user/ID/tasks页面上,我有以下错误: 该网站遇到意外错误。请稍后再试。 TypeError:参数1传递给 Drupal\Core\Access\AccessResult::allowedIfHasPermission()必须 实现接口Drupal\Core\Session\AccountInterface,字符串 给予,召唤 /var/www/www-example-com/web/modules/custom/task\u notif

我为Drupal8.9制作了一个模块

在我的
/user/ID/tasks
页面上,我有以下错误:

该网站遇到意外错误。请稍后再试。 TypeError:参数1传递给 Drupal\Core\Access\AccessResult::allowedIfHasPermission()必须 实现接口Drupal\Core\Session\AccountInterface,字符串 给予,召唤 /var/www/www-example-com/web/modules/custom/task\u notify/src/Controller/tasknifyusercontroller.php 第19行 Drupal\Core\Access\AccessResult::allowedIfHasPermission()(第116行) core/lib/Drupal/core/Access/AccessResult.php)

我在模块中做错了什么

<?php

namespace Drupal\task_notify\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Session\AccountInterface;

class TaskNotifyUserController extends ControllerBase {

  public function Tasks() {
    return [
      '#theme' => 'task_notify_user_template',
    ];
  }

  public function taskAccess(AccountInterface $account) {
    return AccessResult::allowedIf($account->id() == $this->currentUser()->id())
      ->orIf(AccessResult::allowedIfHasPermission('administer users'));
  }

}

正如文档所指出的,函数

Drupal\Core\Access\AccessResult::allowedIfHasPermission(AccountInterface $account, $permission)
需要两个参数,第一个是您需要权限的帐户,第二个是您希望验证的权限

参数

$account:要检查其权限的帐户

字符串$permission:要检查的权限

资料来源:

因此,您的代码应该是:

公共功能任务访问(AccountInterface$account){
返回AccessResult::allowedIf(
$account->id()==$this->currentUser()->id()
)->奥里夫(
AccessResult::allowedIfHasPermission(
$account,“管理用户”
)
);
}

正如文档所指出的,函数

Drupal\Core\Access\AccessResult::allowedIfHasPermission(AccountInterface $account, $permission)
需要两个参数,第一个是您需要权限的帐户,第二个是您希望验证的权限

参数

$account:要检查其权限的帐户

字符串$permission:要检查的权限

资料来源:

因此,您的代码应该是:

公共功能任务访问(AccountInterface$account){
返回AccessResult::allowedIf(
$account->id()==$this->currentUser()->id()
)->奥里夫(
AccessResult::allowedIfHasPermission(
$account,“管理用户”
)
);
}

请将代码粘贴到问题中。许多人不会关注链接,不管他们在表面上看起来如何正常。与将链接粘贴到您的代码相比,您应该将代码粘贴到此处-这样可能会得到更好的响应。第一个参数需要是
AccessResult::allowedifhasphomission($account,'manager users')中的
$account
对象
@baikho我不明白我应该在问题中粘贴什么代码。许多人不会关注链接,不管他们在表面上看起来如何正常。与将链接粘贴到您的代码相比,您应该将代码粘贴到此处-这样可能会得到更好的响应。第一个参数需要是
AccessResult::allowedifhasphomission($account,'manager users')中的
$account
对象
@baikho我不明白我应该做什么我更新了我的代码但它不起作用我收到一个错误
RuntimeException:Callable“Drupal\task\U notify\Controller\TaskNotifyUserController::taskAccess”需要“$user”参数的值。在Drupal\Component\Utility\ArgumentsResolver->handleUnresolvedArgument()(core/lib/Drupal/Component/Utility/ArgumentsResolver.php的第142行)中。
您在路径中忘记了它,或者忘记了传递正确的参数,以便正确运行。很抱歉,这是我的第一个模块。你能在完整的文件中给出答案吗?因为对我来说,更新代码似乎很好,但它不起作用。我遇到了一个错误
RuntimeException:Callable“Drupal\task\U notify\Controller\TaskNotifyUserController::taskAccess”需要“$user”参数的值。在Drupal\Component\Utility\ArgumentsResolver->handleUnresolvedArgument()(core/lib/Drupal/Component/Utility/ArgumentsResolver.php的第142行)中。
您在路径中忘记了它,或者忘记了传递正确的参数,以便正确运行。很抱歉,这是我的第一个模块。你能把答案和完整的文件放在一起吗?因为对我来说,这似乎很好