我正在尝试设置一个可以被cron作业调用的控制器操作。我有一个控制器,它运行在http://chill.test的Homestead中,运行在modules/chill/controllers/NotificationController中。
当调用url http://chill.test/actions/chill/notifications/index时,我得到一个本机浏览器登录屏幕。控制器扩展了craft\web\Controller并覆盖了$allowAnonymous。
控制器看起来像这样:
<?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:
{
"error": "Your request was made with invalid credentials."
}有什么关于如何绕过登录弹出窗口的想法,或者我设置错了吗?
发布于 2021-01-13 08:59:06
我通常设置一个模块,然后使用Crafts注册路由
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',
],
];
}
);
}https://stackoverflow.com/questions/65202637
复制相似问题