Welcome Guest, Not a member yet? Register   Sign In
Controller with index($id) method with parameter

Is it possible to have a Controller with the index() method that accepts a parameter?
e.g. controller called "Listjob" with method index($jobid) in such a way to allow this URL to work


I have no custom routes set in app/Config/Routes.php and router setup is default

PHP Code:

The only way to make it work has been to abandon index($jobid) and just change its name from index to a different one , I used "show"
but now as you may guess I have to browse to


I also have tried to add a custom route

PHP Code:

but again no success

Thank you for nay hint regarding this

(This post was last modified: 08-25-2021, 07:06 AM by captain-sensible.)

i add a route for a "get request like"
$routes->get('(:any)', 'Pages::showme/$1');

Pages is a class I created and showme is one of class Pages methods.
SO in the first part of your route /listjob/$something is a url which for full would be something like : http://domain.com/listjob/$something

where $something represents a changing end bit of url

but on the right , it doesn't look as if your referencing any class or method

you could directly call method index method on a class if its define

but your route should be something like mine.

Quickest way to play would probably be to edit home controller and add a method

Try this
below : $routes->get('/', 'Home::index');

add route :

$routes->get('/(:any)', 'Home:test/$1');

Find the controller Home.php in app/Controllers and edit

add appropriately between class { and } :

public  function  test($something)

echo $something;

then on your url http://yourapp/vegetables

and see if "vegetables gets returned

PHP Code:
  public function _remap()
        return $this->index();

(This post was last modified: 08-25-2021, 01:29 PM by Corsari.)

Thank you

yes, it works

thank to your hint , I went back to read the Routing section in the guide and the last two examples (like your) do the job

and I've done like this

PHP Code:

I was doing the route wrong instead of "::" I was using "/"

(This post was last modified: 08-26-2021, 01:46 AM by captain-sensible.)

glad its working :: is a scope resolution operator and / makes it a path or url

Theme © iAndrew 2016 - Forum software by © MyBB