简体   繁体   English

创建我自己的PHP框架

[英]Creating my own PHP Framework

I'm planning on creating a small framework for a dynamic site. 我打算为动态网站创建一个小框架。 When creating a framework is there a standard or code of conduct which should I conclude ? 在创建框架时,是否存在标准行为准则 ,我应该得出结论?

Other than a license for use, there is no standard documentation you are required to include. 除了使用许可之外,您不需要包含标准文档。 As for how to build the framework, as you are writing the lowest level components of the code, you get to decide how the files are built and used. 至于如何构建框架,在编写代码的最低级别组件时,您可以决定如何构建和使用文件。 Just create some PHP files and allow people to use them. 只需创建一些PHP文件并允许人们使用它们。

Taking a look at how existing frameworks are structured is a good way to get started. 看看现有框架的结构是一个很好的入门方式。 CodeIgniter is nicely commented and simple enough to understand, so that would be a good project to read through to get started. CodeIgniter很好地评论并且很容易理解,所以这将是一个很好的项目,可以通过阅读来开始。

Decide whether you framework is loosely-coupled or full-flowed MVC framework 确定您的框架是松散耦合还是全流MVC框架

Loosely-coupled framework is util/library based like Zend/Symfony, where you just provide all the classes and interfaces that a developer can use but you do not force a specific request-response flow. 松散耦合的框架是基于类似Zend / Symfony的util /库,您只需提供开发人员可以使用的所有类和接口,但不强制执行特定的请求 - 响应流。

Full-flowed provides and usually forces the developer to use the request flow that it has established, like CakePHP, CodeIgniter or Kohana. 全流程提供并通常强制开发人员使用它已建立的请求流,如CakePHP,CodeIgniter或Kohana。

p/s: sorry I don't know the actual terms for the framework categories. p / s:抱歉,我不知道框架类别的实际条款。

Decide whether your framework is general purpose or targetted to specific use 确定您的框架是通用的还是针对特定用途的

General purpose is like Zend/Symfony/CakePHP where the framework is not designed with specific use in mind but rather to create a website/application. 一般用途就像Zend / Symfony / CakePHP,其中框架的设计没有特定的用途,而是创建一个网站/应用程序。 Specific use framework is like e-commerce, CMS or blog where it is designed to create a website for a very specific purpose. 具体使用框架就像电子商务,CMS或博客一样,旨在为特定目的创建网站。

You can have a look at coding standards , as well as designpatterns (especially the MVC pattern ). 您可以查看编码标准以及设计 模式 (尤其是MVC模式 )。

Here's a good tutorial which should get you started building your own PHP framework . 这是一个很好的教程,可以让你开始构建自己的PHP框架

A good practice is to look at other PHP frameworks like: 一个好的做法是查看其他PHP框架,例如:

  • Zend Framework Zend框架
  • Code Igniter 代码点火器
  • Yii 警予
  • Symphony 交响乐
  • ... ...

See list here for more PHP frameworks. 有关更多PHP框架,请参阅此处的列表。

There is some good advice regarding PHP standards here: http://www.phptherightway.com . 这里有一些关于PHP标准的好建议: http//www.phptherightway.com The site advises style recommendations known as PSR-0, PSR-1, et al. 该网站建议称为PSR-0,PSR-1等的风格推荐。

There is no standard per se. 本身没有标准。 Usually you would roll out your own framework - or any product really - to combat an existing problem that persists within all of the existing frameworks. 通常,您会推出自己的框架 - 或任何真正的产品 - 来解决在所有现有框架中存在的现有问题。 However, if it is purely for educational purposes, I would suggest you build a framework around the problems you envisage you will have. 但是,如果它纯粹是出于教育目的,我建议你围绕你设想的问题建立一个框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM