bootphp/project

bootphp 的 Web 骨架应用程序

0.0.0 2017-07-11 13:19 UTC

This package is auto-updated.

Last update: 2024-09-17 02:02:15 UTC


README

简单轻量级的 PHP MVC 框架,提供所有稳定的功能,如路由(原生)、缓存(phpFastCache)、数据库(Redbeans & PDO)、模板(Smarty)、身份验证(基本、SSO & 自定义)、会话/角色等。

先决条件

设置

$ composer create-project bootphp/project my_project
$ cd my_project
$ composer update
$ composer require bootphp/rudrax

构建

  • 每当有任何控制器注解发生变化时,您需要点击此 URL
    http://local.piggy.com?RX_MODE_DEBUG=true&RX_MODE_BUILD=1&_display_errors_=2
    

工作吗?

  • 在您的浏览器中点击这些 URL 并查看您获得的输出
    http://local.piggy.com/welcome?name=Lucas
    http://local.piggy.com/api/data/7
    http://local.piggy.com
    

文档

文件夹结构

如果您使用了 create-project 命令,则此目录结构将为您自动创建。否则请手动创建,并确保构建文件夹具有正确的权限 0777

-app
  L controller  // Controller/URL Mapping for Project, name of file and class should match
  L model       //Models being Used in Porject
  L view        //Smart Templates
-config
  L project.properties //Project Properties
-build          // Build/Temporary Files created by Framwork, need write permissions
-src            // Folder for static files like javascript,html,css 
-lib            // composer library folder
-index.php
.htaccess
-composer.json  // set config->vendor-dir = lib

示例控制器 [app/controller/MyController.php]

namespace app\controller {

    class MyController extends AbstractController
    {
        /**
         * @RequestMapping(url="login",method="GET",type="template")
         * @RequestParams(true)
         */
        public function login($model,$username,$password)
        {
            if($username == "user1" && $password == "xDddfdfd"){
              $this->user->setValid(TRUE);
              $this->user->role = "USER";
              $model->assign("username", $username);
              return "welcome"; // 'welcome' is path of smarty tempalte file in view folder
            } else {
              $this->user->setValid(FALSE);
               $model->assign("error", "Wrong credentials");
              return "login"; // 'login' is path of smarty tempalte file in view folder
            }
        }
        
        /**
         * @RequestMapping(url="myprofile",method="GET",type="template")
         * @RequestParams(true)
         */
        public function myprofile($model)
        {
            if($this->user->isValid()){
              $model->assign("username", $this->user->uname);
              return "user/myprofile"; // 'user/myprofile' is path of smarty tempalte file in view folder
            } else {
              $this->user->setValid(FALSE);
               $model->assign("error", "You need to login to view this page");
              return "login"; // 'login' is path of smarty tempalte file in view folder
            }
        }
        
        /**
         * @RequestMapping(url="info/school/{category}",method="GET",type="json")
         * @RequestParams(true)
         */
        public function schoolinfo($category)
        {
            if($this->user->isValid()){
              return array( "success" => true, "id" => 23,"name"=>"DAV Public School");
            } else {
              return array("success" => false,"error"=> "You need to login to view this info");
            }
        }

    }
}

控制器注解选项

所有都是方法级别注解

  • @RequestMapping - URL 信息
    • url - 匹配的 URL 模式
    • method - 请求方法 [GET|POST|PUT|DELETE] - 如果指定则使用
    • type - 响应类型 [template|json|data] - 数据
    • auth - 如果 URL 访问需要基本认证 [TRUE|FALSE] - FALSE
    • cache - 如果响应可由服务器缓存 [TRUE|FALSE] - FALSE
    • guestcache - 仅对访客用户(用户无效)缓存 [TRUE|FALSE] - FALSE
  • @RequestParams - 如果要获取并使用控制器中的查询参数 [TRUE|FALSE] - FALSE
  • @Role - [用户定义值] - 如果指定则使用,具有匹配 $user->{role} 的用户将有权访问 API。

模型注解选项

类级别注解

  • @Model - [sessionUser] -
    • sessionUser - 如果使用,则该模型将用作默认会话用户,类必须扩展 app\model\AbstractUser

调整

要构建项目/清除缓存/重新构建注解 - 从浏览器中点击此 URL

    https:///?RX_MODE_BUILD=TRUE&RX_MODE_DEBUG=TRUE