承接 atk14/sluggish-router 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

atk14/sluggish-router

Composer 安装命令:

composer require atk14/sluggish-router

包简介

Base class for ATK14 routers generating nice looking URLs with slugs

README 文档

README

Base class for ATK14 routers generating nice looking URLs with slugs

It can handle "detail" URLs for models that have method getSlug($lang) and static method GetInstanceBySlug($slug,&$lang). You can find both in the Atk14Catalog.

Basic usage

Router class:

<?php
// file: config/routers/articles_router.php
class ArticlesRouter extends SluggishRouter {

  var $patterns = [
    "en" => ["index" => "/articles/", "detail" => "/articles/<slug>/"],
    "cs" => ["index" => "/clanky/", "detail" => "/clanky/<slug>/"],
    "sk" => ["index" => "/sk/clanky/", "detail" => "/sk/clanky/<slug>/"],
  ];
  
  // var $model_class_name = "Article"; // by default determined automatically according to the router's class name
  // var $target_controller_name = "articles"; // by default determined automatically according to the router's class name
}

Loading router:

<?php
// file: config/routers/load.php
Atk14Url::AddRouter("ArticlesRouter"); // the default namespace ("")
Atk14Url::AddRouter("blog","ArticlesRouter"); // loading ArticlesRouter also into namespace blog

In a template:

{a controller="articles" action="detail" id=123}Here is the article{/a}<br>
{a controller="articles" action="index"}Show all articles{/a}

Rendered HTML:

<a href="/articles/why-is-the-atk14-so-cool/">Here is the article</a><br>
<a href="/articles/">Show all articles</a>

An easier way to set the routes:

<?php
// file: config/routers/articles_router.php
class ArticlesRouter extends SluggishRouter {

  var $patterns = [
    "en" => "articles", // same as ["index" => "/articles/", "detail" => "/articles/<slug>/"]
    "cs" => "clanky", //  same as ["index" => "/clanky/", "detail" => "/clanky/<slug>/"]
    "sk" => "sk/clanky", // same as ["index" => "/sk/clanky/", "detail" => "/sk/clanky/<slug>/"]
  ];
}

Setting only detail routes:

<?php
// file: config/routers/articles_router.php
class ArticlesRouter extends SluggishRouter {

  var $patterns = [
    "en" => "/articles/<slug>/", // same as ["detail" => "/articles/<slug>/"]
    "cs" => "/clanky/<slug>/", //  same as ["detail" => "/clanky/<slug>/"]
    "sk" => "/sk/clanky/<slug>/", // same as ["detail" => "/sk/clanky/<slug>/"]
  ];
}

Fallback route

A fallback route for all the unlisted languages can be specified using the asterisk symbol.

<?php
// file: config/routers/articles_router.php
class ArticlesRouter extends SluggishRouter {
  var $patterns = [
    "*" => ["index" => "/<lang>/articles/", "detail" => "/<lang>/articles/<slug>/"],
  ];
}

Installation

Use the Composer to install SluggishRouter.

cd path/to/your/project/
composer require atk14/sluggish-router

Testing

composer update --dev
cd test
../vendor/bin/run_unit_tests

Licence

SluggishRouter is free software distributed under the terms of the MIT license

统计信息

  • 总下载量: 34.62k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-12-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固