手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表分类:PHP Framework

thinkPHP与Ucenter的连接注意事项

这其实是一个老问题,凡是使用ThinkPHP与Ucenter通讯的程序都需要注意一点。。

ThinkPHP定义了一个基类为Base类,而Ucenter也同样定义了一个基类Base类。
ThinkPHP一开始就加载了BASE类,而Ucenter在使用mysql连接的的时候,就会加载BAse类。因此,凡是使用thinkphp的程序,请把ucenter的连接方式从mysql改为空,即,改用post方式通信 。

Over

其实,关于这个BUG,我很早就在discuz论坛提过了。当然也在ThinkPHP论坛提过。但事实上,都没有什么解决方案。而我更推崇的应该是ucenter进行变化。。呵呵

原文我发在了:UCAPI.COM,然后我再去挖挖坑,看看DZ和TP论坛以前是怎么回复的。。

原来,在DZ,根本就没有人理我:http://www.discuz.net/thread-1204869-1-1.html,这是当时说的两个BUG:

http://www.discuz.net/thread-1204869-1-1.html
  1. 1、1.5版的XML解析器可能有问题,我在使用uc_user_login的时候,无法解析,把老版的xml.class.php拷进去,问题解决。也没有仔细看问题在何处。  
  2.   
  3. 2、不算BUG的BUG,由于我使用框架进行开发,自己有个基类为base,在使用MYSQL通讯的时候,它默认加载了uc_client库中的base类,造成类重载错误  
  4. 建议uc_client中的所有类以“uc_”开头,避免与其他系统产生冲突。  

TP论坛我是在群里提的。。。没记录了。唉。。

 

初用thinkphp的widget

widget最早的应用应该是vista了。。但WEB上的就说不准谁是最早应用的。。。

ThinkPHP从很早的版本里就有支持了,但,我却一直没有用过,依稀记得yblog在用widget的时候,好象ThinkPHP那时候还没有正式支持。。

我这次使用,其实也算是个意外,在对thinksns二次开发的时候,有些页面需要经常重用,不得己,只能使用widget了。

随便看了一下,如果仅仅只是用来显示一些简单的页面,那么widget还是很方便的就能够被使用了。thinkphp2.0的手册中也有介绍。。

最简单的用法莫过于在Lib目录下,新建一个widget目录。然后放上一个class文件,最后附上一个基本同名的模版就行了。。

PHP代码
  1. <?php  
  2.   
  3. class RightSlideWidget extends Widget  
  4. {  
  5.     function render($data){  
  6.         return $data;  
  7.     }  
  8. }  
在同目录下放置一个RightSlide.html就行了。。该html的解析与你使用的模版引擎有关,一般情况下,还是使用TP的模版了。。

在正式的模版中使用【我是指使用TP的情况下】,直接{:W('RightSlide',array('data'=>1))}就可以了。

很简单吧。

Tags: thinkphp, widget

Zend framework quickstart -> create project

仍然是quickstart的内容之一:create project

Create Your Project

In order to create your project, you must first install Zend Framework.

为了创建您的ZF项目,你必须先安装ZF框架

Install Zend Framework

The easiest way to get Zend Framework along with a complete PHP stack is by installing Zend Server. Zend Server has native installers for Mac OSX, Windows, Fedora Core, and Ubuntu, as well as a universal installation package compatible with most Linux distributions.

最简单安装ZF的方法就是安装ZendServer,ZendServer可以安装在苹果系统,windows, fedora,ubuntu,而且支持大多数的linux操作系统 。

After you have installed Zend Server, the Framework files may be found under /Applications/ZendServer/share/ZendFramework on Mac OSX, C:\Program Files\Zend\ZendServer\share\ZendFramework on Windows, and /usr/local/zend/share/ZendFramework on Linux. The include_path will already be configured to include Zend Framework.

在你安装完zendserver后,如果您是使用MAC系统,你将在/Applications/ZendServer/share/ZendFramework目录下找到框架文件,windows平台的话,是在, C:\Program Files\Zend\ZendServer\share\ZendFramework目录中,而linux平台则在/usr/local/zend/share/ZendFramework目录中。同时include_path也已经被配置好支持ZF框架了。

Alternately, you can download the latest version of Zend Framework and extract the contents; make a note of where you have done so.

当然你也可以直接下载ZF的最新版本并解压到你想使用的目录中

Optionally, you can add the path to the library/ subdirectory of the archive to your php.ini's include_path setting.

或者,你也可以把library这个目录加载到你的php.ini中的include_path设置中。

That's it! Zend Framework is now installed and ready to use.

这时候,ZF框架就已经被安装好并能够被使用了。

 

zf Command Line Tool ZF命令行工具
  1. In your Zend Framework installation is a bin/ subdirectory, containing the scripts zf.sh and zf.bat for Unix-based and Windows-based users, respectively. Make a note of the absolute path to this script.  
  2. 在你的ZF安装目录下,有两个可执行文件:zf.sh和zf.bat,他们分别对应着Unix平台和windows平台。记录下这个文件的绝对路径  
  3.   
  4. Wherever you see references to zf.sh or zf.bat, please substitute the absolute path to the script. On unix-like systems, you may want to use your shell's alias functionality: alias zf.sh=path/to/ZendFramework/bin/zf.sh.  
  5. 当你想要引用这zf.sh或者zf.bat文件 的时候,请先设置它的详细路径。例如在Unix平台下,你可以使用shell功能来进行替代:alias zf.sh=path/to/ZendFramework/bin/zf.sh  
  6.   
  7. If you have problems setting up the zf command-line tool, please refer to the manual.  
  8. 如果你还对ZF命令行工具有疑问,那就只能查看官方的手册了  

Open a terminal (in Windows, Start -> Run, and then use "cmd"). Navigate to a directory where you would like to start a project. Then, use the path to the appropriate script, and execute one of the following:

 

打开终端(在windows下面为:开始->运行->输入cmd),转到你想要创建项目的子目录中,开始就可以开始使用你刚才设置的路径来运行那两个script之一了。

 

XML/HTML代码
  1. # Unix:  
  2. % zf.sh create project quickstart  
  3.   
  4. # DOS/Windows:  
  5. C:> zf.bat create project quickstart  

Running this command will create your basic site structure, including your initial controllers and views. The tree looks like the following:

 

运行了这个命令,你将会得到ZF框架的项目的最基本结构,包含了初始化后的控制和和视图(controllers and vews),这个树形结构类似如下:

XML/HTML代码
  1. quickstart  
  2. |-- application  
  3. |   |-- Bootstrap.php  
  4. |   |-- configs  
  5. |   |   `-- application.ini  
  6. |   |-- controllers  
  7. |   |   |-- ErrorController.php  
  8. |   |   `-- IndexController.php  
  9. |   |-- models  
  10. |   `-- views  
  11. |       |-- helpers  
  12. |       `-- scripts  
  13. |           |-- error  
  14. |           |   `-- error.phtml  
  15. |           `-- index  
  16. |               `-- index.phtml  
  17. |-- library  
  18. |-- public  
  19. |   `-- index.php  
  20. `-- tests  
  21.     |-- application  
  22.     |   `-- bootstrap.php  
  23.     |-- library  
  24.     |   `-- bootstrap.php  
  25.     `-- phpunit.xml  

 

At this point, if you haven't added Zend Framework to your include_path, we recommend either copying or symlinking it into your library/ directory. In either case, you'll want to either recursively copy or symlink the library/Zend/ directory of your Zend Framework installation into the library/ directory of your project. On unix-like systems, that would look like one of the following:

在这点中,如果你没有将ZF框架加入到你的 include_path ,我们推荐你将它 COPY或者 symlinking到你的 library目录下。两种方法其中都是将library/Zend 目录 链至你的项目。在unlx系统中,它大致是这样操作的:

XML/HTML代码
  1. # Symlink:  
  2. % cd library; ln -s path/to/ZendFramework/library/Zend .  
  3.   
  4. # Copy:  
  5. % cd library; cp -r path/to/ZendFramework/library/Zend .  

On Windows systems, it may be easiest to do this from the Explorer.

 

在windows平台下,直接在资源管理器中就能够操作完毕。

Now that the project is created, the main artifacts to begin understanding are the bootstrap, configuration, action controllers, and views.

项目创建完毕后,the main artifact【不知道如何翻译】先了角解一下:bootstrap,configuration,action,controllers和views

The Bootstrap

Your Bootstrap class defines what resources and components to initialize. By default, Zend Framework's Front Controller is intialized, and it uses the application/controllers/ as the default directory in which to look for action controllers (more on that later). The class looks like the following:

Bootstrap类定义了资源和构成的初始化。默认情况下ZF只初始化了Front Controller【前端操作器】,它使用了 application/controllers 作为默认目录,在该目录里有着controller控制类的文件。bootstrap最初是这样的:

PHP代码
  1. class Bootstrap extends Zend_Application_Bootstrap_Bootstrap  
  2. {  
  3. }  

As you can see, not much is necessary to begin with.

就你看到的内容来说,好象没有多少是必需的。

Configuration

While Zend Framework is itself configurationless, you often need to configure your application. The default configuration is placed in application/configs/application.ini, and contains some basic directives for setting your PHP environment (for instance, turning error reporting on and off), indicating the path to your bootstrap class (as well as its class name), and the path to your action controllers. It looks as follows:

ZF本身的配置是极少的,你通常需要为你自己的项目进行单独配置。默认的配置文件是/application/configs/application.ini,在文件中定义了一些PHP环境变量(如error_reporting的打开与否)和bootstrap类的路径(甚至是bootstrap类的名称),以前你的控制器的路径,内容如下:

XML/HTML代码
  1. ; application/configs/application.ini  
  2.   
  3. [production]  
  4. phpSettings.display_startup_errors = 0  
  5. phpSettings.display_errors = 0  
  6. includePaths.library = APPLICATION_PATH "/../library"  
  7. bootstrap.path = APPLICATION_PATH "/Bootstrap.php"  
  8. bootstrap.class = "Bootstrap"  
  9. resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"  
  10.   
  11. [staging : production]  
  12.   
  13. [testing : production]  
  14. phpSettings.display_startup_errors = 1  
  15. phpSettings.display_errors = 1  
  16.   
  17. [development : production]  
  18. phpSettings.display_startup_errors = 1  
  19. phpSettings.display_errors = 1  
Several things about this file should be noted. First, when using INI-style configuration, you can reference constants directly and expand them; APPLICATION_PATH is actually a constant. Additionally note that there are several sections defined: production, staging, testing, and development. The latter three inherit settings from the "production" environment. This is a useful way to organize configuration to ensure that appropriate settings are available in each stage of application development.

关于这个文件的必须要注意一些事。首先,当你使用ini格式的配置文件时,你可以直接引用常量,如APPLICATION_PATH就是一个常量。另外,还有一些选择器是默认定义过的:production,staging,testing和defelopment。后面三个设置都是从production的环境变量中扩展的。这样,你就可以很好的为你的项目开发进行适当的配置。

 

 

 原文:http://framework.zend.com/docs/quickstart/create-your-project

有点长,写的也乱。先写这么多,下次补全。

其实不太想翻译这个,毕竟太初级了。。。我想翻译的是这个:http://devzone.zend.com/tag/PHP101

但是翻译现在这个QuickStart是可以让我在言语组织上学习点东西。先为我想翻译的东西打点基础吧。

 

 

 

 

 

 

zend framdwork quick start

最近重操旧业,看起了zend framework,如今的1.9x与以前不一样了。所以,把ZF的quick start逐步翻译一下,权当复习和温故了。

原文地址:http://framework.zend.com/docs/quickstart/create-a-model-and-database-table

ZF & MVC Introduction

Zend Framework

Zend Framework is an open source, object oriented web application framework for PHP 5. ZF is often called a 'component library', because it has many loosely coupled components that you can use more or less independently. But Zend Framework also provides an advanced Model-View-Controller (MVC) implementation that can be used to establish a basic structure for your ZF applications. A full list of Zend Framework components along with short descriptions may be found in the components overview. This QuickStart will introduce you to some of ZF's most commonly used components, including Zend_Controller, Zend_Layout, Zend_Config, Zend_Db, Zend_Db_Table, Zend_Registry, along with a few view helpers.

Using these components, we will build a simple database-driven guest book application within minutes. The complete source code for this application is available in the following archives:

zend framework 介绍

ZF是一个开源且面向对象的,支持PHP5的WEB应用框架。ZF通常被叫做“组件库”,因为他拥有很多松耦合的组件,因此你可以在应用中或多或少的独立使用它们。但ZF更多的是为你的ZF应用提供了一个高级的MVC架构【??翻译不来了】所有的ZF组件列表,你可以从 组件预览 页进行查看。而这个QuickStart会给你的ZF最通常使用的组件进行介绍,如Zend_Controller,Zend_layout,Zend_Config,Zend_Db,Zend_Db_table,Zend_Registry,以及一些视图助手【这个应该是讲View的,但不知道怎么翻译好。现在终于明白那些翻译书的朋友们的痛苦之处了。明知道啥意思就是说不出口,还是词汇量少啊】

Model-View-Controller

So what exactly is this MVC pattern everyone keeps talking about, and why should you care? MVC is much more than just a three-letter acronym (TLA) that you can whip out anytime you want to sound smart; it has become something of a standard in the design of modern web applications. And for good reason. Most web application code falls under one of the following three categories: presentation, business logic, and data access. The MVC pattern models this separation of concerns well. The end result is that your presentation code can be consolidated in one part of your application with your business logic in another and your data access code in yet another. Many developers have found this well-defined separation indispensable for keeping their code organized, especially when more than one developer is working on the same application.

MVC

那么我们就来讲讲什么是MVC了以及你对于MVC来说,最关心的是什么。MVC虽然只是三个单词的开始每个字母组成的新词,然而他已经成为了网页程序的标准设计模式了。而且,有充分的理由证明,大多数的网络程序代码都被归于以下三种分类之一:表达方式【?】,商业逻辑 和数据访问层。MVC模式则能够使你们将关注点进行分离。最终你的表示代码只占你的商业逻辑的一小部分,同样数据访问层也是这样。大多数开发人员发觉这能够使得他们保持代码分离并且条理清晰,尤其是在同一项目中有多名开发人员时。

翻译的很迷惘。。。

其实上面的大意无非就是MVC结构使得程序员可以将更多的精力放在业务逻辑上,而不是将大量的精力浪费在表现层和数据访问上。

不过,虽然翻译的很乱,但我还是多少又理解了一点这方面的知识。MVC如今已经被很多人所接受,很多招聘上也都写着,熟悉MVC模式开发。其实,如果真正项目已经按着MVC模式开发的话,那么招聘进去的人,又有多少是同时对于这三个方面进行开发的呢?

Model - View - Controller,在ZF框架中也是很分离的。看框架的 application目录就很清楚了。除了module和config目录外,剩下的就是:controllers,models和views目录了。。由此可见,基本上也分得比较清楚了

Tags: zend

老王梳理的Zend Framework Bootstrap机制

以下是老王梳理的内容,bootstrap对于ZF来说非常重要,很大一部分人的程序损耗,都在这里。。。。

原文地址:http://hi.baidu.com/thinkinginlamp/blog/item/419f36d34b68c40a3af3cfc9.html

说点题外话,单就框架而言,对我而言使用CakePHP要比使用Zend Framework顺手得多,不过最近CakePHP陷入了多事之秋,Phpnut,Gwoo,Nate彻底闹僵,Gwoo和Nate选择离开,据坊间传闻他们已经开始另立门户,稍后会释出一个CakePHP的衍生框架:Lithium。虽然CakePHP官方已经表态会一如既往的继续前进,但毫无疑问在众多开发者眼中,CakePHP的前景已经不再明朗,其是否能继续保证PHP框架领头羊的地位也越发充满疑问。

之所以说了这么多题外话,就是为了说明一点,对于广大PHPer而言,过多局限于一种框架之上本身就是一种强耦合,未来是不可预期的。所以我打算在继续使 用CakePHP的同时,适当向Zend Framework倾斜,如果Lithium不错的话,也会在我未来学习计划之中占有一席之地。

言归正传,新版的Zend Framework引入了Zend_Application,把Bootstrap进行的规范化的封装,一个典型的Application的Bootstrap文件大致如下:

PHP代码
  1. class Bootstrap extends Zend_Application_Bootstrap_Bootstrap  
  2. {  
  3.     protected function _initAutoloader()  
  4.     {  
  5.         $autoloader = new Zend_Application_Module_Autoloader(array(  
  6.             'namespace' => 'Application',  
  7.             'basePath' => APPLICATION_PATH,  
  8.         ));  
  9.   
  10.         return $autoloader;  
  11.     }  
  12. }  

在Bootstrap中,所有以_init开头的方法被当做资源方法自动运行,如果方法有返回值的话,还会被作为资源保存。资源方法不是唯一配置资源的方 式,为了避免重复编码,框架包含了若干现成的资源插件,可以在配置文件里通过简单设置就可以达到相应的功能,一个典型的配置文件如下所示:

PHP代码
  1. return array(  
  2.     'bootstrap' => array(  
  3.         'path' => APPLICATION_PATH . '/Bootstrap.php',  
  4.     ),  
  5.     'resources' => array(  
  6.         'modules' => array(),  
  7.         'frontController' => array(  
  8.             'controllerDirectory' => APPLICATION_PATH . '/controllers',  
  9.             'moduledirectory' => APPLICATION_PATH . '/modules',  
  10.         ),  
  11.     ),  
  12. );  

resources部分的modules和frontController就是资源插件。其中modules资源开启了系统的模块功能。比如说你有一个admin模块的话,那么对应的也可以有一个它自己的Bootstrap类:

PHP代码
  1. class Admin_Bootstrap extends Zend_Application_Module_Bootstrap  
  2. {  
  3. }  

需要说明的一点是Modules的Bootstrap里一般不再需要类似前面的_initAutoloader资源方法,这是因为从父类 Zend_Application_Module_Bootstrap里已经通过继承自动执行了以模块名为命名空间的Autoloader操作。

在使用Modules的Bootstrap时,有一点需要注意的是系统会把所有模块的所有资源方法统统初始化一遍,打个比方来说,如果你有一个Blog模 块,还有一个Forum模块,每个模块使用各自独立的数据库配置,都有一个自己的_initDb方法,那么即便是我们单独访问Blog或者Forum中一 个模块,系统还是会把两个数据库都连接一遍,这无疑是低效的。但也不能就此认为这是Zend Framework的设计错误,问题的根源在于我们划分模块的粒度大小,如上所示,Blog和Forum不应该以Module的形式存在,而应该以 Application的形式存在。如此一来仅需要在Application层次的Bootstrap中执行一次数据库连接即可。

Zend Framework的文档虽然看似详细,但很多细节都没有说明,比如说View助手缺省就会加载,这一点可以在 Zend_Controller_Front中看到对Zend_Controller_Action_Helper_ViewRenderer的调用,所 以最好在使用时自己扎到源代码里查阅。

Tags: bootstrap, zf