Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Programming With Yii2: Routing and URL Creation
Dec 13, 2016 @ 12:15:02

The TutsPlus.com site has posted the next article in their "Programming with Yii2" series, this time focusing on the routing and URL creation in the application and how the requests get to the intended functionality (in controllers).

In today's tutorial, I'll review routing and URL creation in Yii. When a browser request arrives at your Yii application's index.php file, it must be parsed to determine which controller and method to call. That's routing. The reverse process of linking to parts of your application is URL creation, which is best done programmatically.

Yii provides a lot of flexibility in managing routing and generating links. Follow me as I review the basics.

He starts with a bit of background on the URL manager that comes built in to the Yii2 framework and how the routes are defined. He then starts in by defining some of the desired routes for the application and how to set them up in the main configuration file (including defaults). The tutorial also includes configuration examples of "pretty URLs", and outputting custom URLs using the "Url" helper.

tagged: programming yii2 series routing url creation tutorial

Link: https://code.tutsplus.com/tutorials/programming-with-yii2-routing-and-url-creation--cms-26869

Laravel News:
Route improvements are coming to Laravel 5.4
Dec 07, 2016 @ 10:12:31

The Laravel News site has a quick new post about some routing improvements that are coming in the next larger release of the framework , Laravel v5.4:

As Laravel 5.4 development continues, two new improvements are coming to your routes, better route caching for large applications and fluently registering routes.

The route caching updates will help performance with larger applications, reducing the parsing time required to locate and push a request to the right location. The "fluent" route improvements basically allow for the definition of some things, like middleware or route names, as a part of the route definition rather than after the fact. Examples of this are included in the post.

tagged: laravel routing improvement v54 cache fluent registration

Link: https://laravel-news.com/route-improvements

Matt Stauffer:
Routing changes in Laravel 5.3
Jul 28, 2016 @ 09:36:05

In another of his series of posts about the upcoming version of the Laravel framework (v5.3) Matt Stauffer focuses in on some of the changes in routing that are coming down the line.

The last few versions of Laravel have showed the way routing works shifting around a bit. This is usually a sign that we're feeling some sort of pain—something feels off—but haven't found the perfect solution yet. In 5.3, we may have found it.

He starts by looking at some of the routing changes that happened when v5.2 was released including the change away from two groups ("web" and "api"). In v5.3 the major change is the location of the routes definitions containing all of the routes in your application. In the update, this relocation (into a directory) allows you to define multiple route configurations that can be individually changed based on features rather than one global place. He also includes an example of how you can set up your RouteServiceProvider to load in custom configurations as well.

tagged: laravel v53 routing changes directory multiple files configuration

Link: https://mattstauffer.co/blog/routing-changes-in-laravel-5-3

Loïc Faugeron:
The Ultimate Developer Guide to Symfony - Routing
Feb 17, 2016 @ 10:38:40

Loïc Faugeron has posted the next part of his "Ultimate Developer Guide" series covering individual Symfony components. In this new article he details the routing component.

In this guide we explore the standalone libraries (also known as "Components") provided by Symfony to help us build applications. We've already seen: HTTP Kernel and HTTP Foundation [and the] Event Dispatcher. We're now about to check Routing and YAML.

He starts with a basic overview of the component and what kind of top-level handling it provides. He describes the UrlMatcherInterface and its role in the routing process and a simple collection of Route instances that implement it. Then he gets into the YAML component, providing a simple example defining the routes for your application. He shows how it's converted from the YAML structure into a PHP-based (array) output and is then dumped into a RouteCollection to define the resulting routes.

tagged: symfony routing ultimate developer guide tutorial series yaml

Link: https://gnugat.github.io/2016/02/17/ultimate-symfony-routing.html

Abdul Malik Ikhsan:
Using Routed Middleware class as Controller with multi actions in Expressive
Jan 06, 2016 @ 11:54:38

In this post to his site Abdul Malik Ikhsan shows you how to use a middleware class that does some extra routing as a "controller" in your Zend Expressive application.

If you are familiar with frameworks with provide controller with multi actions functionality, like in Zend Framework 1 and 2, you may want to apply it when you use ZendExpressive microframework as well. Usually, we need to define 1 routed middleware, 1 __invoke() with 3 parameters ( request, response, next ). [...] What if we want to use only one middleware class which facilitate [multiple] pages?

He shows how to take a sample route configuration for an "album" endpoint and handle it via an AbstractPage class that performs a bit of reflection on the request to route things the right way. Then the "controller" is created by extending this abstract class and functions are defined for each action, complete with access to the request, response and next middleware objects.

tagged: zend zendexpressive routing middleware controller reflection actions tutorial

Link: https://samsonasik.wordpress.com/2016/01/03/using-routed-middleware-class-as-controller-with-multi-actions-in-expressive/

Laravel Podcast:
Episode 18 - Laravel 5 Routing, the War over PHP Annotations, and The Secret Weapon
Oct 20, 2014 @ 11:05:05

The Laravel Podcast has released their latest episode, Episode #18: Laravel 5 Routing, the War over PHP Annotations, and The Secret Weapon(tm). Join hosts Shawn McCool, Taylor Otwell and Jeffrey Way as they talk all things Laravel.

In this episode, we discuss new Laravel 5 features including annotated routing and middlewares. We discuss some motivations and guiding forces that make Laravel what it is. Also, hints about Jeffrey and Taylor's secret new project. The referenced article by @everzet can be found here: http://everzet.com/post/99045129766/introducing-modelling-by-example.

You can listen to this latest episode either by using the in-page audio player, by downloading the mp3 or by subscribing to their feed.

tagged: laravel podcast ep18 routing annotations secretweapon

Link: http://www.buzzsprout.com/11908/212256-episode-18-laravel-5-routing-the-war-over-php-annotations-and-the-secret-weapon-tm

SitePoint PHP Blog:
Fast PHP Routing with PHRoute
Aug 08, 2014 @ 12:16:28

The SitePoint PHP blog has a new post by Francesco Malatesta showing how to use the PHPRoute routing library to handle routing of requests quickly and easily.

PHRoute is an interesting package: it’s a fast regular expression based router that you can easily implement in small to medium projects. However, it’s not just very fast: there are filters, filter groups and named routes. You can also use a basic controllers system if things are getting bigger. That said, today we will see how to use it and how to implement its features in a sample project. Also, we are going to see what’s under the hood: PHRoute is a result of many experiments and tests by different people.

Once installed (via Composer), he shows you how to use it in a simple project that manages book information, including authors and categories. He includes some code examples showing how to set up some simple routes and handle the execution of a closure to fulfill the request. He also shows how to work with parameters in routes, using different verbs, working with filters and working with route grouping. The post ends with a look at using controllers with the routing, making it easier to create more modular architectures.

tagged: routing phproute tutorial introduction

Link: http://www.sitepoint.com/fast-php-routing-phroute/

Paul Jones:
Action-Domain-Responder, Content Negotiation, and Routers
Jul 18, 2014 @ 10:17:57

In his latest post Paul Jones comes back to his proposed application structure, the idea of Action-Domain-Responder, and answers some questions about where content negotiation happens and routing.

While talking about Action-Domain-Responder on the Crafting Code Tour, one of the common questions I got was: “Where does content negotiation happen?” My response was always: “Where does it happen in Model-View-Controller?” That opened up a discussion on how content negotiation is a tricky bit that can go in different places, depending on how you want the concerns separated, and is not a problem specific to ADR.

He goes on and tries to answer the question a bit better, pointing out that "it's a problem for everyone" isn't really good enough to take action on. He works through the different pieces of the ADR pattern, trying to reason out where the right fit is. He suggests a "first filter" on the Controller level, more specifically at the Router level. That's not to say that the Router needs to know about content handling, but it does need to know how to pass that information on.

tagged: action domain responder content negotiation routing

Link: http://paul-m-jones.com/archives/6020

Routing Overview & Basics in Symfony 2
Apr 17, 2014 @ 12:10:12

If you're relatively new to using the Symfony2 framework, you might be wondering about some of the things happening during requests to your application. One of these things is the routing and handling of each request. In this new post from NetTuts.com they introduce you to the foundations of Symfony2 routing in a screencast.

In the last video, I said we'd take a look at controllers next, but I actually feel it may be easier to learn the framework in a slightly different order. Instead, we're going to learn about the basics of Symfony 2 routing, to give our applications clean and pretty URLs and make it easy to manage our applications URLs and links. We're not going to get too detailed, as Symfony's routing can do quite a bit, but we'll at least cover what we need to know by keeping it straight and to the point.

The screencast is a bit less than 10 minutes long and provides an overview of the routing, how it interacts with bundles and controllers. There's also a bit about using annotations to help define routing information directly in the controller.

tagged: routing basics symfony2 introduction screencast demo

Link: http://code.tutsplus.com/tutorials/routing-overview-basics-in-symfony-2--cms-20754

Master Zend Framework:
HowTo Use Child and Segment Routes to Build Simple Routing Tables
Apr 03, 2014 @ 11:15:05

Matthew Setter has a new post to his Master Zend Framework site today showing you how to use child and segment routes to create a routing table in your Zend Framework v2 application. These routes are "sub-routes" underneath a main route defined in the main router configuration.

Routing is one of the key requirements in modern applications, especially in Zend Framework 2; but they shouldn’t be overly-complicated. Today, we’re going to look at how to build a routing table, simply and easily using child and segment routes. [...] But how would we do that? Gladly, it’s quite simply, using a combination of [the] two route types: Segment and Child Routes. I’ve made a complete example, which’s available in this Gist. Feel free to skip straight to that. But otherwise, let’s step through the annotated version together.

He sets the stage with an example in a "writing pipeline" application that helps him predict his income from his freelance writing. He describes the main controllers and the routing configurations they might share. In his example code, he shows how to define the routes and modify them to use segments and child routes to handle constraints. There's also a section about extracting out the segments from the route.

tagged: child segment routes tutorial routing zendframework2

Link: http://www.masterzendframework.com/tutorial/child-and-segment-routes