PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 3, 2022

[FIXED] Cakephp how to set root page from admin folder?

 February 03, 2022     cakephp, cakephp-4.x, php     No comments   

Issue

Routes.php

$routes->scope('/', function (RouteBuilder $builder) {
    $builder->connect('/', ['controller' => 'Users', 'action' => 'login']);
    $builder->connect('/pages/*', 'Pages::display');
    $builder->fallbacks();
});

File structure

enter image description here

How to add Admin login page as root page of the website?

Something like this

   $routes->scope('/Admin/UserController', function (RouteBuilder $builder) {
       $builder->connect('/Admin/UserController', ['controller' => 'Users', 'action' => 'login']);
   });

Solution

That's not how you're supposed to connect routes, you don't put stuff like UserController in your path, the path defines the URL format!

If you want to connect / to your admin prefixed controller, then you need to pass the prefix option in the route defaults accordingly, for example:

$routes->scope('/', function (RouteBuilder $builder) {
    // connect the URL `/` to `\App\Controller\Admin\UsersController::login()`
    $builder->connect('/', [
        'prefix' => 'Admin',
        'controller' => 'Users',
        'action' => 'login',
    ]);
    // shorthand variant of the above
    // $builder->connect('/', 'Admin/Users::login');

    $builder->connect('/pages/*', 'Pages::display');
    $builder->fallbacks();
});

See also

  • Cookbook > Routing > Connecting Routes


Answered By - ndm
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing