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

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

You have the crud and crud-view plugins that doest that.

Also 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);

1 Like

@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.

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?

Yes, however I make a generic class for each. CrudController that extends AppController and setup crud, and AppTable that setup search and a findIndex dummy finder.
Then every finder and table can start as an empty class

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

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

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