Download the PHP package miranj/craft-router without Composer

On this page you can find all versions of the php package miranj/craft-router. 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-router

Router

A Craft CMS plugin for using URL segments as filtering criteria on an entry query.

Contents

Why

Craft makes it straightforward to declare dynamic routes as regular expressions and redirect them to be handled by a template. However, the templates themselves remain dumb handlers. They may optionally be passed on some context in the form of named parameters but they have to do the heavy lifting of building the data set required for rendering the page.

This may not be a problem for pages with one or two variables, like a blog's year and month archives (e.g. blog/2015/01). The template would fetch the list of posts from craft.entries and narrow the range depending on if the year and month variables are set.

But what if the blog also added a category page (e.g. blog/camping)? And what if the category pages supported their own yearly and monthly archive pages (e.g. blog/camping/2014)? We would either end up duplicating the code to fetch posts by creating multiple copies of the archive template, or end up adding the logic to handle category, year, and month filters all in a single template and increasing its overall complexity.

The Router plugin attempts to solve this problem by taking on the job of filtering entries based on URL parameters. It adds a new template variable entries which can be configured to, for the URL blog/2015/01 contain blog posts published in January 2015, or for the URL blog/camping/2014 to show blog posts published in 2014 under the category "Camping".

Demo

We recorded a video (36 mins) about the plugin for Straight Up Craft. It talks about the problems that Router is trying to solve and includes a step-by-step tutorial + demo about using the plugin on the Craft Blog Starter project.

Usage

In order to create URL rules that automatically build an Entry Query based on the URL, you will need to create a router.php file in your config folder, adjacent to your existing routes.php file.

Example

Parameters

Each rule expects the following parameters:

segments [array]

Default: []
An array of optional URL segment rules. Example:

combineSegments [bool]

Default: true
Enables/disables support for URLs with segment combinations. When disabled, only one segment match will be allowed per URL. Example:

criteria [array]

Default: []
An array of filters for the Entry Query. Example:

template [string]

Default: ''
The template path used to render the request. Example:

A filter is activated when the corresponding trigger key (named parameter) is present in the route. Based on the type of filter, a set of conditions (criteria) are added to an Entry Query object. This is repeated for every activated filter, and the resulting Entry Query is passed on to the template as the entries variable.

Filter Types

The plugin currently supports the following different types of filters:

category

Adds a relatedTo criteria to the Category with the given slug, and any of its descendants. The Category’s search can be scoped by specifying a Category Group handle in the optional param group. The relation’s field can be specified using the optional param field. Set the filter’s includeDescendants to false if you do not wish descendant Categories to be included in the relatedTo criteria.

categories

Similar to the category filter but supports a comma separated list of slugs instead of just one slug.

entry

Adds a relatedTo criteria to the Entry with the given slug, and any of its descendants. The Entry’s search can be scoped by specifying a Section handle in the optional param section. The relation’s field can be specified using the optional param field. Set the filter’s includeDescendants to false if you do not wish descendant Entries to be included in the relatedTo criteria.

entries

Similar to the entry filter but supports a comma separated list of slugs instead of just one slug.

field

Adds a field criteria to the field specified by handle (required param).

month

Adds a numeric month criteria on the optional param field (which defaults to postDate).

search

Adds a search criteria. Criteria value can be overidden using the optional param value.

section

Adds a section criteria if the specified Section handle is valid. Section handle value can be overidden using the optional param value.

tag

Adds a relatedTo criteria to the Tag with the given slug. The Tag’s search can be scoped by specifying a Tag Group handle in the optional param group. The relation’s field can be specified using the optional param field.

tags

Similar to the tag filter but supports a comma separated list of slugs instead of just one slug.

type

Adds a type criteria if the specified EntryType handle is valid. EntryType handle value can be overidden using the optional param value.

uri

Adds a relatedTo criteria to the entry with the given URI, and any of its descendants. The Entry’s search can be scoped by specifying a Section handle in the optional param section. The relation's field can be specified using the optional param field. Set the filter's includeDescendants to false if you do not wish descendant Entries to be included in the relatedTo criteria.

uris

Similar to the uri filter but supports a comma separated list of URIs instead of just one URI.

year

Adds a date range criteria for the given year on optional param field (which defaults to postDate).

Installation

You can install this plugin from the Plugin Store or with Composer.

From the Plugin Store

Go to the Plugin Store in your project’s Control Panel and search for “Router”. Then click on the “Install” button in its modal window.

Using Composer

Open your terminal and run the following commands:

# go to the project directory
cd /path/to/project

# tell composer to use the plugin
composer require miranj/craft-router

# tell Craft to install the plugin
./craft plugin/install router

Requirements

This plugin requires Craft CMS 3 or 4. The Craft 2 version is availabe in the v0 branch.


Brought to you by Miranj


All versions of craft-router with dependencies

PHP Build Version
Package Version
Requires craftcms/cms Version ^3.7.0 || ^4.0
php Version ^7.2.5 || ^8.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 miranj/craft-router contains the following files

Loading the files please wait ....