本文介绍了扩展/修改 Zend Framework 有多容易?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始构建使用了一年的自定义 MVC 框架的第 2 版.它在许多项目中对我来说都非常有效,但我确实看到了改进的空间.它缺少一些主要功能,如 ACL、表单验证和缓存.尽管我很想自己构建这些部件,但我知道这实际上不是一个明智的决定.所以,我开始研究 Zend Framework 1.9.我真的很喜欢它的组件库是松散耦合的.但是,从不同的教程来看,似乎很冗长.我已经看到一些示例应用程序,我可以使用我自己的框架使用更少的代码来复制它们.因此,我想重新定义"其中的大部分内容,使其对 RAD 更加友好.因此,在我投入大量时间深入研究框架之前,我希望有人能为我阐明这个主题.我本质上是一个编码员,如果它有一个坚实的基础(我希望 ZF 有),那么花几个小时来调整和定制一些东西是没有问题的.

I've recently begun building version 2 of my year-old custom MVC framework. It's worked great for me on a number of projects, but I definitely see room for improvement. It's missing some major functionality like ACL, form validation, and caching. As much as I'd love to build those parts myself, I know that realistically it's not a smart decision. So, I've started looking at Zend Framework 1.9. I really like how its component library is loosely coupled. However, from looking at different tutorials, it seems very verbose. I've seen some sample applications that I could duplicate using less code with my own framework. As such, I'd like to "redefine" much of it to make it more RAD friendly. So before I invest a lot of time digging into the framework, I was hoping someone could shine some light on this subject for me. I'm a coder at heart, and have no problem spending hours upon hours tweaking and customizing something if it has a solid foundation (which I hope ZF has).

我应该注意到,我很高兴看到 Doctrine 可以与 ZF 集成.

I should note that I'm very happy to see that Doctrine can be integrated with ZF.

如果 ZF 不容易扩展,还有哪些其他框架(也有 ACL、表单验证、缓存)?我一直在研究 Symfony,但是整个 Configuration over Convention 的事情让我很困扰.

If ZF isn't easily extendable, what other frameworks are (that also have ACL, form validation, caching)? I've been looking at Symfony, but the whole Configuration over Convention thing bothers me a lot.

预先感谢您的任何意见.

Thanks in advance for any input.

编辑
为了回答 tharkun 的问题,我所说的易于扩展"的意思是我可以滚动我自己的类(可能会或可能不会扩展 ZF 类)并将它们打包在框架中,以便我可以轻松地为我自己的代码构建基础项目.

Edit
To answer tharkun's question, what I mean by 'easily extendable' is that I can roll my own classes (that may or may not extend ZF classes) and package them in the framework so that I can easily build a foundation of code for my own projects.

推荐答案

在流行的 PHP 框架中,ZF 无疑是最容易扩展的框架,尤其是因为松散耦合.

Among the popular PHP frameworks ZF is surely the one which is most readily extended, especially because of the loose coupling.

感谢您的澄清.

你所描述的正是 ZF 擅长的,但我想说这也正是 OOP 擅长的,所以我认为一个不支持这个的 OO 框架是垃圾箱的案例.

What you describe is exactly what ZF is good at but I'd say it is also exactly what OOP is good at so I would regard an OO framework that doesn't support this a case for the rubbish bin.

无论如何.使用 ZF,它通常以这样一种方式完成,即您将自己的库保持在与 ZF 文件夹结构平行的结构中.您可以使用 ZF 自动加载器并通过将它添加到命名空间来向自动加载器注册您的库文件夹.示例:

Anyways. With ZF it's normally done in a way that you keep your own library in a parallel structure to the ZF folder structure. You can use the ZF autoloader and register your library folder with the autoloader by adding it to the namespace. Example:

//this will be the only require needed for your whole application
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('Mylibrary_');

在 Mylibrary 中,您应该遵循 ZF 命名约定.假设您想扩展 Zend_Db_Table_Abstract 类.这个类在逻辑上位于 Zend/Db/Table/Abstract.php 下.您的库现在应该复制该结构:Mylibrary/Db/Table/Abstract.php.你会在那个文件中命名你的类:

In Mylibrary you should then follow ZF naming conventions. Say you want to extend the Zend_Db_Table_Abstract Class. This class is located logically under Zend/Db/Table/Abstract.php. Your library should now replicate that structure: Mylibrary/Db/Table/Abstract.php. And you would name your class in that file:

class Myproject_Db_Table_Abstract extends Zend_Db_Table_Abstract
{
    /*
    now you're ready to extend and override as much as you like.
    and as a bonus you'll not even hav to include your library files
    since your library is registered with the loader
    */
}

问这个问题的时候你有没有想过别的?

Did you have anything else in mind when asking this question?

这篇关于扩展/修改 Zend Framework 有多容易?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 01:19