paysera/fork-carpe-hora-ch-cms-expose-routing-plugin

此包的最新版本(0.0.1)没有可用的许可证信息。

symfony 1 暴露路由

0.0.1 2019-09-16 06:51 UTC

This package is auto-updated.

Last update: 2024-09-16 18:20:39 UTC


README

目标

chCmsExposeRoutingPlugin 是一个用于向客户端暴露路由定义的 symfony 1.(3|4) 插件。

如果你使用 symfony2,请查看 FriendsOfSymfony/FOSJsRoutingBundle

需求

使用此插件需要 jQuery。jQuery 不包含在此插件中,你必须自己包含它。

它是如何工作的?

启用

首先,在你的项目配置中启用插件

<?php
// config/ProjectConfiguration.class.php

public function setup()
{
  $this->enablePlugins(array('chCmsExposeRoutingPlugin'));
}

然后,在你的应用程序中启用 chCmsExposeRouting

# app/{your_app}/config/settins.yml

    enabled_modules:
      - chCmsExposeRouting

最后,发布资源

$ symfony plugin:publish-assets

完成!

更多配置

你可以在 routing.yml 中添加以下内容来 禁用脚本自动包含

app:
  ch_cms_expose_routing:
    register_scripts: false # you will have to register scripts manually

你可以在 routing.yml 中添加以下内容来 禁用路由自动声明

app:
  ch_cms_expose_routing:
    register_routes: false # you will have to register script route manually

然后以这种方式注册你的路由

my_custom_route_name:
  url: /my/url/route.js
  params: { module: chCmsExposeRouting, action: index }

注册你的公开路由

使路由可公开

你唯一需要做的就是添加一个 app_expose 选项

// app/{your_app}/config/routing.yml

# this route will be exposed if auto_discover is true
my_route_to_expose:
  url:  /foo/:id/bar
  params: { action: foo, module: bar }
  options:
    app_expose: true

# this route will NEVER be exposed
my_secret_route:
  url:  /foo/:id/bar/1
  params: { action: foo, module: bar }
  options:
    app_expose: false

# this route will be exposed if forced, but not autodetected
a_default route:
  url:  /foo/:id/bar/2
  params: { action: foo, module: bar }

强制路由公开

在你的应用程序配置(app.yml)中添加以下内容

app:
  ch_cms_expose_routing:
    routes_to_expose:
      - my_first_route_to_expose
      - another_route

公开所有可公开的路由

如果你想公开所有带有 app_expose 选项为 true 的路由,只需在应用程序配置(app.yml)中添加以下内容

app:
  ch_cms_expose_routing:
    auto_discover: false

对公开参数的定制过滤

在你的应用程序配置(app.yml)中添加以下内容

app:
  ch_cms_expose_routing:
    params_blacklist:
      - module
      - action
      - my_param

在浏览器中访问路由

就像调用 Routing.generate('route_id', /* your params */) 一样简单。

Routing.generate('route_id', {id: 10});
// will result in /foo/10/bar
Routing.generate('route_id', {"id": 10, "foo":"bar"});
// will result in /foo/10/bar?foo-bar

$.get(Routing.generate('route_id', {"id": 10, "foo":"bar"}));
// will call /foo/10/bar?foo=bar

文档

测试套件

你可以通过运行 JS 测试套件 来帮助我们提高代码质量。如果你发现任何错误,请 报告问题

待办事项

  • 缓存 JS 路由
  • 添加简单的调用服务器的方式使用 sf_method 和 csrf_token