-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to set Router for single Blog post #70
Comments
To pass a value in using the URL, first you need to specify it in a route. For example, in the front controller:
The regular expression needs to match whatever the variable needs to contain, so for example if it's a numeric ID, This will match URLs like blogs/show/123 for example. Then, to get the value of the variable in the controller, you have to use the route_params property. At the moment the framework doesn't support action method arguments. So for example:
Action method arguments are coming in a future version of the framework. (no ETA at the moment) |
Hello Dave |
Thank you very much, Dave |
Hi Dave
Blog.php (model)
index.php (front controller) Thanx in advance |
First you need to specify the name of the variable when you specify the route:
Then in the controller action, you can get the value of this from the URL like this:
You then need to pass this to your model method, and use it in a WHERE clause in your SQL, so the record selected is based on the value from the URL. |
Good day sir |
@sidekick-xx thank you so much for your kind words! If you have any questions when you're on the course, please don't hesitate to ask in the Q&A section of the course. |
Hi Dave
Firstly, thank you very much for such a great project. I'm quite new to PHP MVC architecture and I'm stuck displaying single items for the blog system I'm practising on. I can add items to db using forms and display them as a list. Everything works perfect, so far. Except for displaying a single item. I get "Message: 'No route matched.'". My code is below and I hope you can advise me. Thanx in advance.
Blogs.php (controller):
`/**
* Display a single Blog post
*
* @return void
*/
public function showAction($blogsID) {
Blog.php (model):
`/**
* Show single blog post
*/
blogs.twig (view) readmore link below:
<a id="readMore" href="/blogs/{{ blog.blogsAlias }}" class="btn btn-success">ReadMore</a><?php ?>
index.php (front controller):
// Blog Links $router->add('blogs', ['controller' => 'Services\Blogs', 'action' => 'index']); $router->add('blogs/new', ['controller' => 'Services\Blogs', 'action' => 'new']); $router->add('blogs/show/index', ['controller' => 'Services\Blogs', 'action' => 'show']);
The text was updated successfully, but these errors were encountered: