Welcome Guest, Not a member yet? Register   Sign In
better auto routing for controllers inside folders
#1

Hello,
I'm creating a standalone image manager module for my website.
I have a controller class with 8 public methods (so, 8 pages that might share the same private helpers and constants), but even if there is currently one file, I want to organize every container modules into a folder :

src/
├───Controllers/
│  │  someFiles.php
│  └───Img/
│          Img.php


The URL to access to the "image foobar preview page" (which is the "view" method with the argument "foobar" inside the Controllers/Img/Img.php class) is localhost:8080/Img/Img/view/foobar.
The URL is a bit big, so I want to change it to "localhost:8080/img/view/foobar" easily.

What I tried so far and don't work :
  • Renaming Img.php to Home.php. While it works for the index page (/img/ -> Home::index), the auto-routing don't work with a method (/img/view/foobar will result to View::foobar() instead of Home::view('foobar')).
  • Still rename Img.php to Home.php but move the Home.php::view($image)method into View.php::index($image). Again, this works well for an url like /img/view/, but not when it comes to an argument (img/view/foobar will result into View.php::foobar() instead of  View.php::index("foobar"))

Is there a way to achieve what I want, without making a route rule for every method inside the controller ?

Here is the source code of my controller as of today (commit 2df0b2f) : https://github.com/Kagescan/code.kagesca...mg/Img.php

Thanks in advance !
Actually learning CodeIgniter4 and creating a complex CMS system for fan-translations teams (Kagescan)
@LoganTann on GitHub // French // He-Him
Reply


Messages In This Thread
better auto routing for controllers inside folders - by ShinProg - 08-22-2021, 12:55 PM



Theme © iAndrew 2016 - Forum software by © MyBB