標籤:base 建立 end 路徑 pre ons use on() str
建立controller
在application/目錄下建立controller目錄,然後接著在controller目錄下建立BaseController,繼承Controller //注:BaseController作用是全域controller公用方法庫
檔案名稱:BaseController.class.php
<?phpnamespace application\controller; use rapid\core\Controller;use rapid\library\rapid; class BaseController extends Controller{ //公用方法庫}
接著建立IndexController,繼承BaseController
<?phpnamespace application\controller;use rapid\library\rapid; class IndexController extends BaseController{ public function indexAction()
{
echo "RapidPHP 架構";
}}
簡單的控制前就建立完畢了,下面配置路由,找到 rapid/config/routing/ 目錄,裡面有兩個檔案
app.inc.php //控制器方法配置,允許路由調用的的方法,不允許的則不要配置
<?phpnamespace rapid\config\routing;use application\controller\IndexController;use rapid\config\constants\App;use rapid\config\constants\app\Routing;/** * 可以訪問的類,介面,不聲明則沒許可權訪問 */return array( IndexController::class => array( ‘indexAction‘ => array( Routing::METHOD_TYPE => App::APP_REQUEST_GET, //請求類型get請求 ), ));
uri.inc.php //路由地址配置
<?phpnamespace rapid\config\routing;use application\controller\IndexController;use rapid\config\constants\app\Routing;/** * 路由uri配置層一層外下匹配,直到匹配到停止 * 正則或路徑=>類,app.inc的對應類的元素名 */return array( ‘/^(\/|index)(|\.htm|\.html|\.php)$/‘ => array( Routing::CLASS_NAME => IndexController::class, Routing::APP_NAME => ‘indexAction‘ ), );
ok,訪問 / /index /index.htm /index.html /index.php 都可以訪問進去,致次,我們的第一個rapidPHP App就建立完畢了。
rapidPHP 1.1.0 - 建立第一個app