# Virtualize/Emulate/Catch-All PHP files in /templates directory

**URL:** <https://discourse.cakephp.org/t/virtualize-emulate-catch-all-php-files-in-templates-directory/8162>\
**Category:** Need Help\
**Created:** [August 2, 2020, 10:41am UTC](https://discourse.cakephp.org/t/virtualize-emulate-catch-all-php-files-in-templates-directory/8162 "2020-08-02T10:41:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeterVARGA](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/petervarga/32/1928_2.png) [@PeterVARGA](https://discourse.cakephp.org/u/PeterVARGA)\
**Post date:** [August 2, 2020, 10:41am UTC](https://discourse.cakephp.org/t/virtualize-emulate-catch-all-php-files-in-templates-directory/8162/1 "2020-08-02T10:41:42Z")

</div>

Our project has around 15+ exactly equal data table index pages which show the content of a database table and provide the _Edit/Delete/Add_ functionality.

I can put lot of the equal code into a PHP file which is then _included_ by each `index.php` in the corresponding directory. Even this would minimize a lot of repeated code I am wondering if there is a possibility to make it more general.

My intention is that these `index.php` files do **NOT** exist and when they are accessed with `www.example.com/users` | `www.example.com/data1` | `www.example.com/data2` and so on, a _hook_ delivers the content of the personalized HTML file on the fly. Which table is accessed is described in the URL - this is just a simple parse task.

**My question:**  
Is there some of the described functionality? It would be some kind of a `catch-all` functionality for certain pages.

**Note** : More or less it should work like PhpMyAdmin. The PMA _engine_ displays standardized a table/database provided in the URL. BUT, of course, I am not writing another PMA, it’s just an example how I expect it to work.

I am working with CakePHP 4.1.0

---

<div class="post-metadata">

**Author:** ![raul338](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/raul338/32/69_2.png) [@raul338](https://discourse.cakephp.org/u/raul338)\
**Post date:** [August 2, 2020, 6:29pm UTC](https://discourse.cakephp.org/t/virtualize-emulate-catch-all-php-files-in-templates-directory/8162/2 "2020-08-02T18:29:01Z")

</div>

You have the [crud](https://github.com/FriendsOfCake/crud) and [crud-view](https://github.com/FriendsOfCake/crud-view) plugins that doest that.

Also [cakephp-csvview](https://github.com/FriendsOfCake/cakephp-csvview) for csv exports.

Basically all you have is a template, that reacts base on the variables that you pass on the view. You can make your custom ViewClass (in `src/View`), in there set the template and others things you may want. In the controllers simply set the variables, and call `$this->viewBuilder()->setClass(MyCustomListView::class);`

---

<div class="post-metadata">

**Author:** ![PeterVARGA](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/petervarga/32/1928_2.png) [@PeterVARGA](https://discourse.cakephp.org/u/PeterVARGA)\
**Post date:** [August 3, 2020, 11:11am UTC](https://discourse.cakephp.org/t/virtualize-emulate-catch-all-php-files-in-templates-directory/8162/3 "2020-08-03T11:11:22Z")

</div>

@raul338 Thank you very much my friend. It looks indeed like this is what I was looking for. Allow me some time to check it out and I will post here for sure my feedback.

---

<div class="post-metadata">

**Author:** ![PeterVARGA](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/petervarga/32/1928_2.png) [@PeterVARGA](https://discourse.cakephp.org/u/PeterVARGA)\
**Post date:** [August 3, 2020, 6:51pm UTC](https://discourse.cakephp.org/t/virtualize-emulate-catch-all-php-files-in-templates-directory/8162/4 "2020-08-03T18:51:12Z")

</div>

I am studying it. Do I understand it correctly I still need for each database table I want to view at least the \*Controller.php file?

---

<div class="post-metadata">

**Author:** ![raul338](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/raul338/32/69_2.png) [@raul338](https://discourse.cakephp.org/u/raul338)\
**Post date:** [August 4, 2020, 1:04pm UTC](https://discourse.cakephp.org/t/virtualize-emulate-catch-all-php-files-in-templates-directory/8162/5 "2020-08-04T13:04:56Z")

</div>

Yes, however I make a generic class for each. `CrudController` that extends `AppController` and setup crud, and `AppTable` that setup [search](https://github.com/FriendsOfCake/search/) and a `findIndex` dummy finder.  
Then every finder and table can start as an empty class

```auto
public class TagsController extends CrudController {
}
public class TagsTable extends AppTable {
}

```

If I were to setup custom filters I would setup in a few lines

```auto
public class UsersControllers extends CrudControllers
{
   public function index() {
      $this->Crud->action()->setConfig('findMethod', 'active');
      return parent::index(); // $this->Crud->execute();
   }
   // view, add, edit, delete are inherited from CrudController
}

```

and on each the table you setup validation options, relations, etc
