{"id":16329986,"url":"https://github.com/luin/php-lugit-framework","last_synced_at":"2025-07-04T18:38:59.689Z","repository":{"id":66160840,"uuid":"1914768","full_name":"luin/php-lugit-framework","owner":"luin","description":"简单优雅的PHP前端框架。","archived":false,"fork":false,"pushed_at":"2011-12-12T12:59:52.000Z","size":330,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-31T10:36:07.306Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-06-18T06:34:39.000Z","updated_at":"2019-08-13T14:46:46.000Z","dependencies_parsed_at":"2023-02-19T23:25:16.351Z","dependency_job_id":null,"html_url":"https://github.com/luin/php-lugit-framework","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luin%2Fphp-lugit-framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luin%2Fphp-lugit-framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luin%2Fphp-lugit-framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luin%2Fphp-lugit-framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luin","download_url":"https://codeload.github.com/luin/php-lugit-framework/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238212397,"owners_count":19434955,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T23:18:04.660Z","updated_at":"2025-02-11T00:31:17.345Z","avatar_url":"https://github.com/luin.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 开始 #\nLugit提供简单优雅的方法帮助你实现PHP开发，需要PHP5.0以上的版本支持。\n\n# URL映射 #\nLugit使用PATHINFO模式，如：\n\nhttp://localhost/index.php/controllername/actionname/parameter0/parameter1/parameter2/\n\n建议使用rewrite将上述URL写成\n\nhttp://localhost/controllername/actionname/parameter0/parameter1/parameter2/\n\n对于Apache服务器可以在app文件夹下建立.htaccess文件，内容如下：\n\n    RewriteEngine on\n    RewriteCond $1 !^(index\\.php|favicon\\.ico|robots\\.txt)\n    RewriteRule ^(.*)$ index.php/$1 [L]\n\n更多内容请参见Apache服务器文档。\n\n## Controller、Action与Parameter ##\nLugit将URL映射为Controller、Action和Parameter。\n\n如URL: http://localhost/people/tom/book/comment/\n\n对应的Controller为people，Action为tom，Parameter[0]为book，Parameter[1]为comment\n\n如果缺少Action则默认为index, 缺少Controller同理\n\n如URL: http://localhost/people/\n\n对应的Controller为people，Action为index\n\n如URL: http://localhost/\n\n对应的Controller为index，Action为index\n\n# 第一个示例: Tom的书评 #\n要处理URL: \n\nhttp://localhost/people/tom/book/comment/\n\n需要在app目录下的controllers文件夹下建立PeopleController.php文件，内容如下：\n\n    \u003c?php\n    class PeopleController extends Controller\n    {\n        public function tomAction()\n        {\n            //$this-\u003eparameters[0] == 'book'\n            $this-\u003esetVar('p0', $this-\u003eparameters[0]);\n            //或 $this-\u003evars-\u003ep0 =$this-\u003eparameters[0];\n\n            //$this-\u003eparameters[1] == 'comment'\n            $this-\u003esetVar('p1', $this-\u003eparameters[1]);\n        }\n    }\n\n在views下建立people文件夹，在里面建立tom.phtml文件，内容如下：\n\n    \u003chtml\u003e\n        \u003chead\u003e\u003ctitle\u003eHello tom!\u003c/title\u003e\u003c/head\u003e\n        \u003cbody\u003e\n            \u003cp\u003ep0 is: \u003c?php echo $this-\u003evars-\u003ep0; ?\u003e\u003c/p\u003e\n            \u003cp\u003ep1 is: \u003c?php echo $this-\u003evars-\u003ep1; ?\u003e\u003c/p\u003e\n        \u003c/body\u003e\n    \u003c/html\u003e\n\n## 问题: 其他人的书评 ##\n设想网站的用户会有很多，所以会有很多如下的网址：\n\nhttp://localhost/people/tom/book/comment/\n\nhttp://localhost/people/luin/book/comment/\n\nhttp://localhost/people/chen/book/comment/\n\n...\n\n我们可以在PeopleController.php里塞满以人名命名的方法，但在Lugit里有更好的解决方案：\n\n    \u003c?php\n    class PeopleController extends Controller\n    {\n        public function adaptAction($people)\n        {\n            $this-\u003esetVar('people', $people);\n\n            //$this-\u003eparameters[0] == 'book'\n            $this-\u003esetVar('p0', $this-\u003eparameters[0]);\n\n            //$this-\u003eparameters[1] == 'comment'\n            $this-\u003esetVar('p1', $this-\u003eparameters[1]);\n        }\n    }\n\n对应地，在views/people文件夹下建立adapt.phtml，内容为：\n\n    \u003chtml\u003e\n        \u003chead\u003e\u003ctitle\u003eHello \u003c?php echo $this-\u003evars-\u003epeople; ?\u003e!\u003c/title\u003e\u003c/head\u003e\n        \u003cbody\u003e\n            \u003cp\u003ep0 is: \u003c?php echo $this-\u003evars-\u003ep0; ?\u003e\u003c/p\u003e\n            \u003cp\u003ep1 is: \u003c?php echo $this-\u003evars-\u003ep1; ?\u003e\u003c/p\u003e\n        \u003c/body\u003e\n    \u003c/html\u003e\n\n## 关于adapt ##\n当Controller或Action不能确定时可以使用adapt。\n\n比如要处理URL: \n\nhttp://localhost/tom/1/\n\nhttp://localhost/peter/8/\n\nhttp://localhost/peter/17/\n\n我们只要在controllers文件夹下建立AdaptController.php文件: \n\n    \u003c?php\n    class AdaptController extends Controller\n    {\n        public function adaptAction($num)\n        {\n            $this-\u003esetVar('number', $num);\n            $this-\u003esetVar('people', $this-\u003econtrollerName);\n        }\n    }\n\n在views文件夹下建立adapt/adapt.phtml进行处理即可。\n\n# 处理POST \u0026 GET #\n在Lugit中处理POST和GET的方式是一样的，如http://localhost/sample/?people=tom：\n\n    \u003c?php \n    class SampleController extends Controller\n    {\n        public function indexAction()\n        {\n            $this-\u003erequest-\u003epeople == 'tom'; //true\n        }\n    }\n\n## 过滤输入 ##\nLugit提供了优雅的方法过滤输入:\n\n    \u003c?php \n    class SampleController extends Controller\n    {\n        public function indexAction()\n        {\n            $var_people = $this-\u003erequest-\u003efilter('trim', 'Class::staticMethod')-\u003epeople;\n        }\n    }\n\n相当于:\n\n    \u003c?php \n    class SampleController extends Controller\n    {\n        public function indexAction()\n        {\n            $var_people = $this-\u003erequest-\u003epeople;\n            $var_people = trim($var_people);\n            $var_people = Class::staticMethod($var_people);\n        }\n    }\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluin%2Fphp-lugit-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluin%2Fphp-lugit-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluin%2Fphp-lugit-framework/lists"}