Download the PHP package craftsnippets/craft-named-routes without Composer

On this page you can find all versions of the php package craftsnippets/craft-named-routes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package craft-named-routes

Named routes plugin for Craft CMS 5.x

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

    cd /path/to/project
  2. Then tell Composer to load the plugin:

    composer require craftsnippets/craft-named-routes
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Craft named routes.

Usage

This plugin allows you to get a URL of routes set in config/routes.php from within Twig templates - you will no longer need to hardcode routes structure in your markup.

In order to use the plugin, you will need to give your route an additional name attribute. Here is an example of a route that creates a user profile page:

As you can see, we gave route name userRoute. To get URL of route in Twig template, you need to use craft.namedRoutes.getUrl function. Pass it route name and array or route tokens:

This will output URL looking like "http://website.com/users/11".

Here are the parameters received by craft.namedRoutes.getUrl function:

You can also get URI instead or URL by using getUri() method:

This will return URI "users/11".

Regexp rules of tokens

The last parameter of the function requires a bit of explanation. If route token has regexp rule provided (like <user_id:\d+> - which would only accept digits), the plugin by default will throw an exception if the provided token value does not match this rule. This behavior can be overwritten by setting the third parameter of the function to false.

One of the use cases for this can be providing URL for redirectInput when adding entry from frontend, and our entry uses custom route. Poperties of the new entry can be used in redirectInput - for example, this URL will have {id} replaced with ID of added entry:

So, if our route looks like this:

Passing {id} as entry_id token value will cause an error, because string {id} does not matches \d+ rule which accepts only digits. That's why you need to set the third parameter of a function to false in such a situation.

Craft CMS routing documentation

More information about routes can be found in Craft documentation.

Disclaimer

Brought to you by Piotr Pogorzelski

Plugin icon made by Law Xin Yi.


All versions of craft-named-routes with dependencies

PHP Build Version
Package Version
Requires craftcms/cms Version ^5.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package craftsnippets/craft-named-routes contains the following files

Loading the files please wait ....