来源:
http://kevinvaughan.com/
BaseApp介绍
BaseApp is a PHP5 application layer core built upon the power of Zend Framework. It serves two purposes:
1) 快速配置基于 Zend Framework的网站
By implementing the following (as of version 1.0.0a), basic web application can begin much faster:
A core modular structure for the MVC implementation that Zend Framework provides
Integrating Smarty Templating System as the basic viewer in a way that is compatible with the current Zend View
Integration of Xend_Layout for easy common template usage
Configuration through Zend Config XML
Application logging through Zend Log
Automatic autoloading and relative path references for quick deployment
A basic content structure with search engine friendly URLs
phpdoc for easier navigation through code
Immediate future integration plans include an ORM layer, implementation of the Zend_Auth and Zend_ACL modules. If you have ideas that would make BaseApp better, or have made modifications that you think would benefit everyone, I'd love to hear from you. Just shoot an email over to kevin at kevinvaughan dot com.
2) Zend Framework技术的实例应用
While spending time in #zftalk on irc.freenode.net and on the ZF forums, many questions about the above implementations are asked repeatedly and there have been very few up-to-date specific code examples to point people towards. By providing BaseApp as a Zend Framework example, and continuing to integrate more pieces of Zend Framework and other commonly used PHP5 resources into it, I hope to encourage the adoption of PHP5 and the better development practices that come along with it.
开始应用!
下载BaseApp and start playing with the power of Zend Framework!
Inside BaseApp, Part 1 - Zend Framework and the Bootstrap
This entry is about the use of Zend Framework and BaseApp, an application layer built on top of the framework libraries.
One of the things I noticed as I was getting started with the Zend Framework libraries was the smell coming from all of the bootstrap files... a lot of setting of variables, adding directories to this or that, creating various objects for random tasks, and a growing urge to do more and more setup in this bootstrap. This is BAD practice for a few reasons, but here are the two big ones for me:
可维护- did we not learn from php4? Non-OOP code just gets worse and worse over time. It gets unorganized, it gets unfocused, and soon the bootstrap, just like the index.php scripts of old, begin to do too much for their role.
可再用 - which sounds like a better idea: copying the code over and modifying the section that you want to act differently? or extending a class and only writing new code where its applicable? If you found yourself nodding in approval to the first option, buy this book for good insight into why the second option will make your life much easier.
BaseApp minimizes the bootstrap to a very simple form: set the application path, instantiate the main application class, call any special configuration methods of that object, then execute the main method of the application object. In the included example index.php, this is 5 lines of code. The application object, BaseApp_Loader, handles all of the specific setup that you otherwise see in bootstrap files.
什么是BaseApp_Loader?它能做什么? 为什么比固有的bootstrap好?
XML 配置 - Uses Zend_Config_Xml to load an application level configuration file. Now if you want to launch a second copy of a site, for example, you can use the same exact code libraries and point at different configuration file to use different databases, etc. By using an xml configuration and capturing exceptions through the main application setup process, simple errors like typos won't bring your site crashing to 500 Internal Server Error.
基于配置的方法 - Each type of configuration is split off into its own method within BaseApp_Loader, so if you want to setup logging to do something other than Zend_Log, or configure database usage differently than the default Zend_DB implementation, you can override the individual method in an extension of the BaseApp_Loader class. Each of these methods receives a Zend_Config object rather than referencing the application's config directly, allowing for easy overrides by subclasses while minimizing the impact of the underlying structure.
Zend_View可选择 - Included in the default implementation are Zend_View and BaseApp_View_Smarty (a Smarty based view). BaseApp allows you to decide what view you want to use in a way that is flexible, and you can add your own if you want (by following BaseApp_View_Smarty as an example, if you need).
容易注册 - For modules, views, log control, database control, helpers and more. Utilizing these powerful constructs provided by the Zend Framework libraries is extremely easy using the BaseApp_Loader's methods or overriding them with your own.
基本应用程序目录架构
为了初学者,以下是 BaseApp基本目录架构. More in-depth documentation (including inline documentation) is in the works for the first version.
./application/modules => 模块目录框架Each module in the modules directory has a main Module class that extends the BaseApp_Module abstract class. If an implementing BaseApp_Module class exists somewhere within your include_path structure (in any subdirectory), you can reference it as a module entry point in the main BaseApp configuration. The constructor can be used to initialize any module specific settings. Each module should have the standard /controllers, /models, /views directory outlined in the Zend Framework documentation.
./cache => autoloader和Smarty的缓存文件夹
The cache directory (and subdirectories) are for storing cached information. Specifically, class script locations for the magic __autoload function and compiled Smarty templates are stored in these directories. They should be writable by the web server.
./configurations => 配置文件夹Central repository for configurations. The BaseApp.xml configuration file is stored in here, and contains various location, module and log configuration options.
./html =>网站文件夹
Storage for the .htaccess file and the main index.php script, as well as static resources (images, css, javascripts, etc.). Note that this index.php does an extremely basic startup of the BaseApp as the complexity of the typical "bootstrap" is encapsulated by the main BaseApp class.
./library => Application, Zend以极第三方库The BaseApp libraries and other libraries such as Smarty are contained in this folder.
./logs =>应用日志文件夹Like ./cache, a directory for storing logs. The initial configuration has the main application log stored in this directory. The directory should be writable by the web server.Kevin Vaughan2007-08-11
同时在这里也可以下载:[attach]88[/attach]