Symfony查询友好的Url

时间:2017-04-10 10:11:03

标签: php symfony routing

我正在尝试使用类似应用程序中的Symfony 3.1.1创建一个库存控制应用程序。

客户希望所有网址都具有此模式

域名/供应商/ 2

(其中2是数据库中供应商的ID)

目前,我获得的网址类似于

域/供应商?ID = 2

我一直在查看旧项目的文档,symfony页面和这里,但是我无法理解如何进行路由,因为项目是另一个的分支我受限于保留尽可能多的代码

所有代码都从Bundle扩展,所以为了创建一个列表,它调用了这个函数(我现在没有覆盖或向SupllierController添加任何东西):

 <a href="{{ path('app_supplierproduct_list', { id : row.id }) }}" class="btn btn-default">
            Productos
        </a>

控制器调用的列表非常简单,我所做的所有更改都与创建一个按钮有关,我试图获取该函数的编号:

public function buildList(ListBuilderInterface $builder, array $options)
    {
        $builder
            ->setEntity('AppBundle:SupplierProduct')
            ->setMode('normal', 'modal')
            ->addField('products', 'entity', [
                'label'             => 'Producto',
                'class'             => 'AppBundle:Product',
                'choice_label'      => 'name',
                'query_builder' => function (EntityRepository $er) {
                    return $er->createQueryBuilder('e')
                    ->orderBy('e.name', 'ASC');
                },
            ])
            ->addField('supplier', 'entity', [
                'label'             => 'Proveedor',
                'class'             => 'AppBundle:Supplier',
                'choice_label'      => 'name',
                'query_builder' => function (EntityRepository $er) {
                    return $er->createQueryBuilder('e')
                    ->orderBy('e.name', 'ASC');
                },
            ])      
            ->addField('name', 'text', [
                'label'             => 'Nombre en el Proveedor',
            ])
            ->addField('code', 'text', [
                'label'             =>  'Código en el Proveedor',
            ])
            ->addFilter('name', 'text', [
                'label'             => 'Nombre en el proveedor',
            ])
            ->addFilter('sku', 'text', [
                'label'            =>   'Código interno del proveedor'
            ])
            ->addFilter('updatedAt', 'date', [
                'label'             => 'Última Modificación'
            ])            
            ->addFilter('supplier', 'entity', [
                'label'             => 'Proveedor',
                'class'             => 'AppBundle:Supplier',
                'choice_label'      => 'name',
                'query_builder' => function (EntityRepository $er) {
                    return $er->createQueryBuilder('e')
                    ->orderBy('e.name', 'ASC');
                },

            ])
            ->addFilter('customer', 'entity', [
                'label'             => 'Cliente',
                'class'             => 'AppBundle:Customer',
                'choice_label'      => 'name',
                'query_builder' => function (EntityRepository $er) {
                    return $er->createQueryBuilder('e')
                    ->orderBy('e.name', 'ASC');
                },
            ])
        ;
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'list_supplierproduct';
    }

SupplierProductList(我试图打电话)是:

app_supplier_customer:
    resource: "@AppBundle/Controller/SupplierCustomerController.php"
    type:     annotation

app_supplier_customer:
    resource: "@AppBundle/Controller/SupplierCustomerController.php"
    type:     annotation

app_supplier_customer:
    resource: "@AppBundle/Controller/SupplierCustomerController.php"
    type:     annotation

app_supplier_product:
    resource: "@AppBundle/Controller/SupplierProductController.php"
    type:     annotation

app_supplier_customer:
    resource: "@AppBundle/Controller/SupplierCustomerController.php"
    type:     annotation

app_sale:
    resource: "@AppBundle/Controller/SaleController.php"
    type:     annotation

app_product:
    resource: "@AppBundle/Controller/ProductController.php"
    type:     annotation

app_group:
    resource: "@AppBundle/Controller/GroupController.php"
    type:     annotation

app_customer:
    resource: "@AppBundle/Controller/CustomerController.php"
    type:     annotation

app_brand:
    resource: "@AppBundle/Controller/BrandController.php"
    type:     annotation

odin_form_filemanager:
     path:  /filemanager/
     defaults: { _controller: OdinFormBundle:FileManager:show }

odin_panel:
    resource:       '@OdinPanelBundle/Controller'


odin_panel_login_check:
    path:           /login/check


odin_panel_logout:
    path:           /logout
    app:
        resource: '@AppBundle/Controller/'
        type:     annotation

路由文件:

let touchedNode: SKNode = overlay.atPoint(location)

1 个答案:

答案 0 :(得分:0)

出于文档目的而完成:

最后,我意识到Controller Action在注释块中未将id作为参数接收。