我有问题,不知道该怎么做。 此问题开始仅出现在托管上。我正在使用CakePHP 3。 关于每个动作' public_html'添加到地址行。像这样的东西(看截图): https://gyazo.com/8474d1dd4ba50397e7c444f71845205b
我什么都不能,因为在我提交并使用之后 $ this-> redirect([' action' =>' addnews']); 它将我重定向到普通页面而没有' public_html'在地址栏中,但我不能进行任何其他操作,因为不允许他们未经授权。
我的路线:
use Cake\Core\Plugin;
use Cake\Routing\Router;
Router::defaultRouteClass('DashedRoute');
Router::scope('/', function ($routes) {
// USER Actions //
$routes->connect('/register', ['controller' => 'Users', 'action' => 'register']);
$routes->connect('/registernotification', ['controller' => 'Users', 'action' => 'registerNotification']);
$routes->connect('/unregisternotification', ['controller' => 'Users', 'action' => 'unregisterNotification']);
$routes->connect('/addudid', ['controller' => 'Users', 'action' => 'addUdId']);
$routes->connect('/removeudid', ['controller' => 'Users', 'action' => 'removeUdId']);
// News Actions //
$routes->connect('/newslist', ['controller' => 'News', 'action' => 'newsList']);
$routes->connect('/getfromcategory', ['controller' => 'News', 'action' => 'getFromCategory']);
$routes->connect('/favorite', ['controller' => 'News', 'action' => 'favorite']);
$routes->connect('/addtofavorite', ['controller' => 'News', 'action' => 'addToFavorite']);
$routes->connect('/removefromfavorite', ['controller' => 'News', 'action' => 'removeFromFavorite']);
$routes->connect('/search', ['controller' => 'News', 'action' => 'search']);
$routes->fallbacks('DashedRoute');
});
Router::prefix('admin', function ($routes) {
$routes->connect('/', ['controller' => 'News', 'action' => 'login']);
$routes->connect('/:controller');
$routes->fallbacks('DashedRoute');
});
Plugin::routes();
My beforeFilter in NewsController:
public function beforeFilter(Event $event)
{
if ($this->request->prefix == 'admin') {
$this->Auth->deny();
$this->Auth->allow(['login', 'logout']);
$this->Auth->config([
'loginRedirect' => [
'controller' => 'News',
'action' => 'addnews'
],
'logoutRedirect' => [
'prefix' => false,
'controller' => 'News',
'action' => 'login',
],
'loginAction' => [
'controller' => 'News',
'action' => 'login',
],
'authenticate' => [
'Form' => [
'passwordHasher' => 'Default',
'fields' => ['username' => 'login', 'password' => 'pass'],
'userModel' => 'Administrators',
]
],
'flash' => [
'key' => 'auth',
'element' => 'error',
],
]);
}
}