# Theme and prefix routing

**URL:** https://discourse.cakephp.org/t/theme-and-prefix-routing/4620
**Category:** Need Help
**Created:** [July 24, 2018, 8:19pm UTC](https://discourse.cakephp.org/t/theme-and-prefix-routing/4620 "2018-07-24T20:19:38Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![devzone](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/devzone/32/1105_2.png) [@devzone](https://discourse.cakephp.org/u/devzone)
#### Post date: [July 24, 2018, 8:19pm UTC](https://discourse.cakephp.org/t/theme-and-prefix-routing/4620/1 "2018-07-24T20:19:38Z")

</div>

I have created new theme as Plugin following Cakephp 3.x documentation.

in my AppController i have condition to load different themes.

```
   // Layouts
   $this->viewBuilder()->setTheme('Legacy'); //default theme
   if (!is_null($this->request->getParam('prefix'))) {
       $prefix = explode('/', $this->request->getParam('prefix'))[0];
       switch ($prefix) {
           case 'c':
               $this->viewBuilder()->setTheme('Campaign');
               break;
           case 'admin':
               $this->viewBuilder()->setTheme('Admin');
               break;
        }
    }

```

my default route for admin prefix is:

```
Router::prefix('admin', function ($routes) {
    // All routes here will be prefixed with `/admin`
    // And have the prefix => admin route element added.
    $routes->connect('/', ['controller' => 'Users', 'action' => 'dashboard']);
    $routes->fallbacks('InflectedRoute');
});

```

but when i got in browser to [http://localhost:8180/admin/](http://localhost:8180/admin/)

i see only error:  
**Error: The view for UsersController::dashboard() was not found.**  
**Confirm you have created the file: “Admin/Users/dashboard.ctp” in one of the following paths:**  
**/var/www/myapp/src/Template/Admin/Users/dashboard.ctp**

my dashboard.ctp is in the Plugin folder plugins/Admin/src/Template/Users/dashboard.ctp

am i doing something wrong here ?  
should the theme views be placed in plugin folder as suggested in documentation or in  
/var/www/myapp/src/Template/THEMENAME/ …

---

<div class="post-metadata">

### Author: ![dash](https://avatars.discourse-cdn.com/v4/letter/d/7c8e57/32.png) [@dash](https://discourse.cakephp.org/u/dash)
#### Post date: [July 25, 2018, 7:30am UTC](https://discourse.cakephp.org/t/theme-and-prefix-routing/4620/2 "2018-07-25T07:30:00Z")

</div>

in that connect function write name instated of /

---

<div class="post-metadata">

### Author: ![mzm](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mzm/32/1107_2.png) [@mzm](https://discourse.cakephp.org/u/mzm)
#### Post date: [July 25, 2018, 2:18pm UTC](https://discourse.cakephp.org/t/theme-and-prefix-routing/4620/3 "2018-07-25T14:18:17Z")

</div>

Can you try like this?

```
Router::prefix('admin', function ($routes) {
    // All routes here will be prefixed with `/admin`
    // And have the prefix => admin route element added.
    $routes->connect('/', ['plugin'=>'admin','controller' => 'Users', 'action' => 'dashboard']);
    $routes->fallbacks('InflectedRoute');
});
```

---

<div class="post-metadata">

### Author: ![devzone](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/devzone/32/1105_2.png) [@devzone](https://discourse.cakephp.org/u/devzone)
#### Post date: [July 27, 2018, 8:34am UTC](https://discourse.cakephp.org/t/theme-and-prefix-routing/4620/4 "2018-07-27T08:34:00Z")

</div>

I don’t want to create complete admin plugin (controllers,plugins etc). I want to have only admin theme, meaning when i set the theme in my AppController i want that the template files are loaded from the theme/plugin folder templates as described in documentation.

Anyway i tried your suggestion, now getting Missing Controller exception.

`Error: Create the class UsersController below in file: /var/www/myapp/plugins/Admin/src/Controller/Admin/UsersController.php`

the path is very strange… why would i need to create Admin folder inside Admin’s plugin Controller ?  
seems to me that there is a problem with creating themes in 3x (as suggested in documentation - theme is now a plugin)

It works for me without prefixed routes (i set a theme and use the view templates from the Plugin folder.  
However if there is a prefixed route, it does not work as expected.
