yaf中路由有5種方式,這裡簡單實現正則路由(regex)。
假定場景,訪問yafok.com/d
,d代表數字,直接到商品詳情頁面.(product模組下的product控制器下的show方法),此方法接受乙個pid引數。
可以在對應控制器下通過
$paras=$this->getrequest()->getparams();
接受pid等引數
bootstrap.php中 ,首先註冊初始化配置[routes]
routes.product.type='regex'
routes.product.match='#^/([0-9]+)[\/]?$#'
routes.product.route.module='product'
routes.product.route.controller='product'
routes.product.route.action='show'
routes.product.map.1='pid'
public function _initconfig(yaf_dispatcher $dispatcher)
然後初始化路由
public function _initroute(yaf_dispatcher $dispatcher)
方法2:在路由初始化時,用陣列新增
以上兩種方法都行,實現效果如下:$router = $dispatcher->getinstance()->getrouter();
$route = new yaf_route_regex(
'/([0-9]+)/',
array('module'=>'product',
'controller' => 'product',
'action' => 'show'
),array("1"=>'pid')
);$router->addroute('product', $route);
貼一下目錄
自定義dialog的兩種方式
介紹自定義對話方塊 dialog 的兩種方式 方式一 首先自定義乙個自己想要設計的對話方塊的介面布局,我的是這樣的 然後在activity類中進行展示,這裡我寫了乙個showinputpwddialog方法 輸入密碼對話方塊 private void showinputpwddialog 方式二 可...
自定義異常的兩種方式
自定義異常的兩種方式 一 丟擲異常 def greet name,city if notisinstance name,str raise typeerror name must be str if notisinstance city,str raise typeerror age must be...
自定義View的兩種方式
一 xib自定義view 1.思路 2.關鍵 1 import23 class45 inte ce67 8 模型資料9 1113 14 15 通過模型資料來建立乙個view 16 1819 end 1 import 2 import 34 inte ce 5 property weak,nonato...