domain / controller / action / id如何编写它

时间:2014-09-19 09:35:13

标签: php cakephp routes

我有像这样的cakephp网址 domin.com/products/mobile/3 我想这样做像cakephp 对于产品ID,我想这样显示:domain.com/3
domian.com/products/nokiamobilesdomain.com/nokiamobiles

class productsController extends AppController{
    public function mobile($id){
        $this->set('nokia',$this->Product->findById($id));
        }
 public function nokiaMobiles(){

     $this->set('nokia',$this->Product->find('all'));

      }


}

1 个答案:

答案 0 :(得分:0)

路线第一个:

Router::connect(
    '/:id',
    'controller' => 'products', 'action' => 'mobile',
    array('id' => '[0-9]+')
);

第二名:

Router::connect(
    '/nokiamobiles',
    array('controller' => 'products', 'action' => 'nokiamobiles')
);

了解更多CakePHP Routes