Router's Register function
Permalink
I saw some sample codes that had Route::Register but when I tried it, it didn't work. No register method on the class. I checked the API and found Router instead so I used it.
So when I tried this code:
I get this error when launching the site:
Call to a member function add() on null
I think it's this part in the Register function causing the error:
But I don't know what I should pass in $rtHandle though.
So when I tried this code:
Router::register('/redpoint/foo', 'Concrete\Package\MyPackageName\MyClassName::testMe', null, array());
I get this error when launching the site:
Call to a member function add() on null
I think it's this part in the Register function causing the error:
$this->collection->add($rtHandle, $route);
But I don't know what I should pass in $rtHandle though.
Thank you!
I had been pulled away from this task to focus on other tasks and just visited this now. It's working now.
I have a clarification though. My mistake was I was using this
thinking that's the same as . When I tried your code, it didn't work at first because of that. My question is why did that happened? I thought the Route controller under Core\Routing was what "use Route" was pointing to?
I had been pulled away from this task to focus on other tasks and just visited this now. It's working now.
I have a clarification though. My mistake was I was using this
use \Concrete\Core\Routing\Route;
use Route;
Glad it worked out for you! :D
In your on_start function, add this code (or create the on_start function if it's not there yet):
You will be calling registerRoutes, which we also need to create.
As you can see, it's creating a request towards /product. This is your single page. It will use the "view" function within this single page, and passes 2 parameters named "id" and "slug". Within the product single page controller I had the view function like this:
The route also got a name, called "product". So you have a way to generate a URL based on this route handle. If you need help with that, I can send you some additional code. If you want to do things a different way, I suppose one of the core members can help you with that.