首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法调用Craft 3模块的操作

无法调用Craft 3模块的操作
EN

Stack Overflow用户
提问于 2020-12-09 00:14:15
回答 1查看 213关注 0票数 1

我正在尝试设置一个可以被cron作业调用的控制器操作。我有一个控制器,它运行在http://chill.test的Homestead中,运行在modules/chill/controllers/NotificationController中。

当调用url http://chill.test/actions/chill/notifications/index时,我得到一个本机浏览器登录屏幕。控制器扩展了craft\web\Controller并覆盖了$allowAnonymous。

控制器看起来像这样:

代码语言:javascript
复制
<?php
namespace Chill\Controllers;

use Craft;
use craft\web\Controller;

class NotificationsController extends Controller
{
    protected $allowAnonymous = true;

    /*
     * Call via: http://chill.test/actions/chill/notifications/index
     */
    public function actionIndex(){

        Craft::$app->getDeprecator()->log("Chill", "Testing the error logging on index action", 'notifications.log');

        return 'Welcome to the NotificationsController actionIndex() method';
    }
}

另外,通过Paw调用url,并在报头中设置application/json,我得到了以下401-response:

代码语言:javascript
复制
{
  "error": "Your request was made with invalid credentials."
}

有什么关于如何绕过登录弹出窗口的想法,或者我设置错了吗?

EN

回答 1

Stack Overflow用户

发布于 2021-01-13 08:59:06

我通常设置一个模块,然后使用Crafts注册路由

代码语言:javascript
复制
private function _registerSiteRoutes()
{
     Event::on(UrlManager::class, UrlManager::EVENT_REGISTER_SITE_URL_RULES,
         function (RegisterUrlRulesEvent $event) {
             $event->rules[] = [
                 'class' => 'yii\rest\UrlRule',
                 'controller' => ['api/' => 'my-module/api/v1/base'],
                 'extraPatterns' => [
                      'GET notifications' => 'notifications',
                 ],
             ];
         }
     );
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65202637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档