Cakephp仅与params相关联

时间:2016-09-15 08:24:39

标签: php cakephp cakephp-3.0

我需要创建一个自定义网址,例如http://example.com/type_of_institution/institutin_name

我在/routes.php中添加了以下几行

$routes->connect(
    '/:type/:name',
    ['controller' => 'Institutions', 'action' => 'view'],
    ['type' => '[a-z_]+', 'name' => '[a-z_]+', 'pass' => ['type','name']]
);

//in my controller
public function view($type,$name){
   this->autoRender = false;
}

我已尝试使用http://example.com/private_institution/test_institution,但我收到以下错误:

Error: [Cake\Routing\Exception\MissingControllerException] Controller class PrivateInstitution could not be found.

我改成

之后
$routes->connect(
        'institutions/:type/:name',
        ['controller' => 'Institutions', 'action' => 'view'],
        ['type' => '[a-z_]+', 'name' => '[a-z_]+', 'pass' => ['type','name']]
    );

http://example.com/institutions/private_institution/test_institution

合作

在Cakephp 3中,只有params制作一个url?(第一个例子)

0 个答案:

没有答案