我想尝试着写个小型PHP框架,现在卡在类自动加载和路由实现上了
我想尝试着写个小型PHP框架,现在卡在类自动加载和路由实现上了,有没有带我入门从0开始的资料啊??
回复内容:
我想尝试着写个小型PHP框架,现在卡在类自动加载和路由实现上了,有没有带我入门从0开始的资料啊??
http://lvwenhan.com/php/405.html 看看这个!!!
1.类自动加载
建议使用composer
或者看看这个 http://www.imooc.com/video/4847
2.路由看你需要什么样的了
类似laravel的:https://github.com/cutephp/route
类似Thinkphp的
看thinkphp框架中 ThinkPHP\Library\Think\Route.class.php 文件
剩下的可以看看这个问题
http://segmentfault.com/q/1010000000589502
每个程序员都有一个框架梦 我也有但是 还是看看别人的 用用别人的 真正自己有实力 有需求再自己去开发
php的类自动加载目前已经有非常好标准化了。请考虑composer,把这个融入到框架可以整合很多种不同人写的路由模块。
中文网:http://www.phpcomposer.com/
路由模块参考:https://packagist.org/packages/aura/router
php标准化组织:http://www.php-fig.org/
自动加载,去看看php的autoload ,还有个spl 的函数,来注册你自己写的自动加载函数。
路由的话,有几种方式,其中一种是pathinfo,还有最普通的querystring,再别的,基本就是这类的基础上实现。如果实现通过正则配置路由,来直接向action传递参数,那就要把正则写好了~
之前做php的时候自己试着写了个框架,也是把基本的自动加载,还有路由写好了,这两个写好,基本就是一个完整的MVC框架了,其余的就是增加一些类库,或者加入ORM
参考slim framework
自动加载交给composer
路由推荐Macaw
https://github.com/NoahBuscher/Macaw
推荐一个精简的Router库做路由控制器 https://github.com/lloydzhou/router,可以根据映射的handler自动从request获取变量,支持自定义error handler和hook。可以通过hook方便的定制参数过滤、登录检查等。
<code>(new Router()) ->error(405, function($message){ header('Location: /hello/world', true, 302); }) ->get('/hello/:name', function($name){ echo "Hello $name !!!"; }) ->execute(); </code>
造轮子这种事情嘛,多看下别人轮子怎么造的,比如CI这种框架,装载器和路由写的就挺优雅的。
。。。
你胡说什么啊,程序猿的事能叫抄么?那是借鉴
那你有什么思路?

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
