标签:framework

浏览模式: 标准 | 列表 | 图文
Yiiframework为每个module单独指定db连接

Yiiframework为每个module单独指定db连接

Yii的module功能确实很方便,但现在的问题在于,我需要为每个module单独指定一个数据库连接,这样我就可以将不同的系统整合在一起了。找了不少资料,好象都没有这样类似的功能。master/slave之类倒是有不少类似的整合方案的。

测试了一下,发现可以这样操作,即在全局配置文件中的module里为module加上components中加上db,然后就基本OK了。但即使这样,你还是会发现不太正常,会提示db不存在,其实需要在这个db数组中加上class=>CDBconnection就一切OK了。会自动加载的哦。(烂桔在这里帮了不少忙)

然后数据连接就是Yii::app()->getModules('modulename')->db。【不过他在这里说的是findModules,我看了一下,getModules就直接可以用了。HOHO】

如果你有master和slave,也可以按照这样的配置,然后再在onBeforeFind方法里设定db=Yii::app()->getModules('module')->readerDb之类的。并在onAfterFind后再置 db为write的链接。(感谢HM提出方案)

如果有多个slave,又想使用同一个slave缓存,则可以先随机取得slave的名称。然后存入session,然后再指定链接。这样,每一个用户使用的slave就会是唯一的。其实提高了效率(感谢神仙提出来)

ExtJs 备忘录

ExtJs 备忘录

这个,当然不是我写的。我用的更多的应该是jQuery,相对于JS这方面来说,jQuery框架我用的是最多的。
在jQuery没有出来之前,用过一阵子的prototype,只是现在用的少了。
mootools是一点都没有碰过,dojo亦然。extJS和yui也同样只是稍看了一遍而己。为了ExtJS我还专门买了本书,只是却几乎没有翻过。

看到这个备忘录,就想着先收藏下来,留着以后慢慢看,这样也并不错啊。。。
这个系列一共九篇,讲了表单,表格和页面搭建,还是比较有用的。即使是初学者也可以迅速上手,当然如果不深究的话,终究只是于处应用阶段,属于知其然不知其所以然。。。

1.  ExtJs 备忘录(1)—— Form表单(一) [ 控件使用 ]
2.  ExtJs 备忘录(2)—— Form表单(二) [ 控件封装 ]
3.  ExtJs 备忘录(3)—— Form表单(三) [ 数据验证 ]
4.  ExtJs 备忘录(4)—— Form表单(四) [ 数据提交 ]
5.  ExtJs 备忘录(5)—— GirdPanl表格(一)[ 基本用法 ]
6.  ExtJs 备忘录(6)—— GirdPanl表格(二)[ 搜索分页 ]
7.  ExtJs 备忘录(7)—— GirdPanl表格(三)[ 统计|查看、修改单行记录 ]
8.  ExtJs 备忘录(8)—— 管理界面搭建和其他部分控件介绍
9.  ExtJs 备忘录(9)—— Ext常用属性、方法小结 [系列完]

随便看看吧。了解一下也好,毕竟熟悉了之后,用EXTJS做界面还是很漂亮的,当然,如果写的不好,内存吃起来也是很漂亮的。

ZF 1.9.4 出来了

ZF 1.9.4 出来了

ZendFramework的更新速度不可谓不快,记得5月份的时候它还是1.7.8左右,如今 刚过去5个月,却已经是1.9.4了。
虽然说这几个月,发生了很多事,比如PHP5.3的推出、ZDE 7.1测试版推出等,ZF的速度也太快了吧?

changelog:http://framework.zend.com/changelog/1.9.4

quickstart:http://framework.zend.com/docs/quickstart

using zf and smarty

using zf and smarty

使用zend framework开发时,可以采用第三方模版,比如smarty,在网上找了很多资料,一般来说是两种

1、扩展view

2、使用Zend_Registry,在初始化的时候加载smarty,然后在输出的时候使用Zend_Registry::get('smarty')->display();

使用第二种方式的话,我当然是没有什么说的了。我这里说的是使用第一种方案。

在第一种方案中,官方有例子,页面地址为:http://framework.zend.com/manual/en/zend.view.scripts.html,写上一个类,调用Zend_View_Interface,写上相同的函数就可以了。。

官方有源码,我这里就不贴了。我把官方的例子写一下:

//Example 1. In initView() of initializer.
$view = new Zend_View_Smarty('/path/to/templates');
$viewRenderer =
new Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer'); //使用此例子时,请将new去掉,静态方法不需要new
$viewRenderer->setView($view)
->setViewBasePathSpec($view->_smarty->template_dir)
->setViewScriptPathSpec(':controller/:action.:suffix')
->setViewScriptPathNoControllerSpec(':action.:suffix')
->setViewSuffix('tpl');

//Example 2. Usage in action controller remains the same...
class FooController extends Zend_Controller_Action
{
public function barAction()
{
$this->view->book = 'Zend PHP 5 Certification Study Guide';
$this->view->author = 'Davey Shafik and Ben Ramsey'
}
}

//Example 3. Initializing view in action controller
class FooController extends Zend_Controller_Action
{
public function init()
{
$this->view = new Zend_View_Smarty('/path/to/templates');
$viewRenderer = $this->_helper->getHelper('viewRenderer');
$viewRenderer->setView($this->view)
->setViewBasePathSpec($view->_smarty->template_dir)
->setViewScriptPathSpec(':controller/:action.:suffix')
->setViewScriptPathNoControllerSpec(':action.:suffix')
->setViewSuffix('tpl');
}

以上是官方的example。不过,如果按第一个例子测试,是会出错的。。。

请看第4行。。。静态方法居然用了new。(应该是粗心吧。不过我昨天是直接复制的,死活报错,也没有仔细看,丢人啊)写这篇 文章,主要也就是提醒一下,这个例子有点问题。

顺便说一下,由于官方的例子里,是把$_smarty写成了protected,那么,其实在外面是不能够被直接引用的。要么写一个__get方法,要么,把属性改为public吧

不过,在使用smarty后,你会发现,你原来的layout功能不能完全使用了,为什么呢?因为,在原来的layout里面,代码都是类似于这样:

<?php
$this->layout()->title;
?>

大致是这样的代码,这个,可不能用在smarty中。虽然在smarty中也可以用标签来调用PHP代码,但这毕竟不是一个好办法。

不过还好,又有牛人写了一个很牛叉的例子。LOOK:http://anders.tyckr.com/2008/03/12/implementing-zend-layout-and-smarty-using-zend-framework-mvc/,不过这个例子我还没有全部看完,先贴上来。以后慢慢看,应该会用在项目中吧?

不然,我就用不了layout了,除非我放弃这个东西。。哈哈

Zend Framework 1.8.0 Released

1.8版本的公布,应该是ZF推动框架和代码标准化的步骤之一吧。随着加入ZF开发的人越来越多,ZF的功能越来越强大,但代码也越来越庞大了。

新版本主要是有两个特色功能:1是快速构建项目开发,利用cli程序来进行快速推荐,2是简化了云计算的操作(这主要应该是ZF和amazon的合作导致的吧?)

快速构建项目的功能,应该是比较让用户开心的,虽然zs6已经能够创建ZF项目,但还是有很多controller,action,model需要用户一一去创建,这,虽然不复杂,也如果多的话,也很繁琐。如今 ,1.8也让你解放出来了,看图上的命令行界面,你应该知道新版本是多么的方便了吧?(顺便说一下,现在国内的thinkPHP,QeePHP都有类似功能的工具推出,这可是国内走在了前端,他们都是一年前就有推出哦)

本次更新对Zend_Loader_Autoloader作出了更新,它与Zend_loader::autoload()不太一样,是一次新的改进。具体我也不翻译了,可以自己看一下代码就清楚了。这主要是对SPL的autoload所不能解决问题的一些改进,比如类名前缀等

云计算也是此次的亮点,但我一般用不了amazon的东西,所以我也不想翻译这些东西了。相信国内也用不了这些,哈哈

最后的更新,请看英文版最后的:Other Contributions,看看里面是不是有你想要的东西。

I'm pleased to announce the Zend Framework 1.8.0 release, the first in our 1.8 series of releases. This release marks the culmination of several long-standing projects, as well as a formalization of many of our recommended practices.

There are two major stories in this release: first, the addition of several components designed to provide and promote Rapid Application Development; second, two offerings that make using Zend Framework in the cloud easier.

Download it now!

Rapid Application Development

1.8.0 marks the first public release of Zend_Tool. At its simplest, Zend_Tool provides a command-line script that can be used to ease many common project-related tasks: setting up the project tree, adding controllers, actions (and related view scripts), model classes, etc. More advanced users can create their own tool providers that can then be directly invoked from that script -- or even create their own RPC endpoints so as to expose the tooling on the web or via a web service.

As an example of it in action, check out this screenshot:

zf.sh Help Screen

In a related vein, 1.8 also introduces Zend_Application, which provides a standard and object oriented method for bootstrapping applications. Bootstraps may define their own initialization resources, or draw upon some common plugins to do their work. Additionally, resources may be bootstrapped individually, allowing you to utilize a common bootstrap with multiple gateway scripts tailored for different tasks.

One dependency of Zend_Application is Zend_Loader_Autoloader. Zend_Loader_Autoloader is a replacement for Zend_Loader::autoload(), and solves many of the issues users have reported with that solution. Additionally, it provides the ability to manage a stack of namespaced autoloaders, working around some minor issues of the SPL's autoloader as well as providing opportunistic matching of namespace prefixes to match your classes quickly. A subcomponent, Zend_Loader_Autoloader_Resource provides a simple mechanism for mapping classes to the filesystem when the directory structure may not exactly correspond to the class name. By using an autoloader by default, you can help keep your code more performant as well as leave class resolution out of your code -- greatly epediting application development.

Note: the Zend Framework Quick Start has been updated to use Zend_Tool and Zend_Application. It's an excellent introduction to these components as well as Zend Framework's MVC in general.

Cloud Computing

Web 2.0 applications have many demands not seen in traditional web applications. One of these is the need for distributed storage, and another is the need to scale horizontally on demand as traffic to your site spikes.

Amazon has provided solutions to both of these problems for several years now with its Simple Storage Service (S3) and Elastic Compute Cloud (EC2), respectively.

Amazon S3 provides web services developers may use to store and retrieve data. The service is distributed, and thus highly scalable, reliable, and fast. Zend_Service_Amazon_S3 provides an object oriented approach to the service, as well as a PHP streams wrapper -- both designed to make working with S3 from your PHP applications a simple matter.

Amazon EC2 provides a web service to allow launching and managing server instances within Amazon's data centers. These server instances may be used at any time for any length of time -- allowing you to scale your site only when you need to handle extra traffic, or run your services entirely from the EC2 platform.

Other Contributions

The number of community contributions and bug fixes for 1.8.0 has been phenomenal. Below is a list of the primary feature additions for the release.

  • Zend_Tool, contributed by Ralph Schindler
  • Zend_Application, contributed by Ben Scholzen and Matthew Weier O'Phinney
  • Zend_Loader_Autoloader and Zend_Loader_Autoloader_Resource, contributed by Matthew Weier O'Phinney
  • Zend_Navigation, contributed by Robin Skoglund
  • Zend_CodeGenerator, by Ralph Schindler
  • Zend_Reflection, Ralph Schindler and Matthew Weier O'Phinney
  • Zend Server backend for Zend_Cache, contributed by Alexander Veremyev
  • Zend_Service_Amazon_Ec2, contributed by Jon Whitcraft
  • Zend_Service_Amazon_S3, Justin Plock and Stas Malyshev
  • Incorporated Dojo 1.3
  • Added support for arbitrary Dojo Dijits via view helpers
  • Zend_Filter_Encrypt, contributed by Thomas Weidner
  • Zend_Filter_Decrypt, contributed by Thomas Weidner
  • Zend_Filter_LocalizedToNormalized and _NormalizedToLocalized, contributed by Thomas Weidner
  • Support for file upload progress support in Zend_File_Transfer, contributed by Thomas Weidner
  • Translation-aware routes, contributed by Ben Scholzen
  • Route chaining capabilities, contributed by Ben Scholzen
  • Zend_Json expression support, contributed by Benjamin Eberlei and Oscar Reales
  • Zend_Http_Client_Adapter_Curl, contributed by Benjamin Eberlei
  • SOAP input and output header support, contributed by Alexander Veremyev
  • Support for keyword field search using query strings, contributed by Alexander Veremyev
  • Support for searching across multiple indexes in Zend_Search_Lucene, contributed by Alexander Veremyev
  • Significant improvements for Zend_Search_Lucene search result match highlighting capabilities, contributed by Alexander Veremyev
  • Support for page scaling, shifting and skewing in Zend_Pdf, contributed by Alexander Veremyev
  • Zend_Tag_Cloud, contributed by Ben Scholzen
  • Locale support in Zend_Validate_Int and Zend_Validate_Float, contributed by Thomas Weidner
  • Phonecode support in Zend_Locale, contributed by Thomas Weidner
  • Zend_Validate_Db_RecordExists and _RecordNotExists, contributed by Ryan Mauger
  • Zend_Validate_Iban, contributed by Thomas Weidner
  • Zend_Validate_File_WordCount, contributed by Thomas Weidner

In addition, we recorded well over 200 bug fixes for this release.

Please join me in a hearty round of congratulations and acknowledgment of all contributors who helped make this release possible through code contributions, feedback, testing, documentation, translations, and issue reports!

9 个基于JavaScript 和 CSS 的 Web 图表框架

CB纯粹是一堆程序员发泄的地方,因此,在上面不可避免的会出现一些好的东西,比如这个:9 个基于JavaScript 和 CSS 的 Web 图表框架

图表,我个人还是觉得用FLASH来做比较好,比较有动感,而且现在所有浏览器都支持FLASH。它还是比较有前途的。FLASH和JS在运行的时候占用CPU应该是JS相对较高吧?FLASH图表还是有一些很不错的。比如open flash chart,就是一个开源的FLASH图片控件。

不过,标题是JS的,我当然还是把CB原文贴过来喽:http://www.cnbeta.com/articles/79418.htm

原文如下:

新闻来源:woork.blogspot.com
jQuery, MooTools, Prototype 等优秀的 JavaScript 框架拥有各种强大的功能,包括绘制 Web 图表,使用这些框架以及相应插件,我们可以非常轻松地实现曲线图,圆饼图,柱状图等 Web 图表的绘制,而不必象以往那样通过复杂的 Flash 技术实现。本文介绍了9个优秀的基于 JavaScript 与 CSS 的 Web 图表框架。
jQuery, MooTools, Prototype 等优秀的 JavaScript 框架拥有各种强大的功能,包括绘制 Web 图表,使用这些框架以及相应插件,我们可以非常轻松地实现曲线图,圆饼图,柱状图等 Web 图表的绘制,而不必象以往那样通过复杂的 Flash 技术实现。本文介绍了9个优秀的基于 JavaScript 与 CSS 的 Web 图表框架。
1. Flot


Flot 是一个纯粹的 jQuery JavaScript 绘图库,可以在客户端即时生成图形,使用非常简单,支持放大缩小以及鼠标追踪等交互功能。该插件支持 IE6/7/8, Firefox 2.x+, Safari 3.0+, Opera 9.5+ 以及 Konqueror 4.x+。使用的是 Safari 最先引入的 Canvas 对象,目前所有主流浏览器都支持该对象,除了 IE, 因此在 IE中使用 JavaScript 进行模拟。这里有一些实例。
2. JS Charts


JS Charts 是一个免费的基于 JavaScript 的图表生成器,表格绘制非常简单,几乎不需要编码,也不需要插件和服务器模块,使用XML 或 JavaScript 数组缓存数据。
3. TableToChart
TableToChart 是一个 MooTools 脚本,可以将 HTML Table 对象中存储的数据绘制成图表。你可以使用 table 标签生成图表,柱状图,曲线图,圆饼图等。
4. PlotKit
PlotKit 是一个 JavaScript 绘图库,支持 HTML Canvas 标签,也支持 SVG。
5. Yahoo UI Charts Control


YUI Charts Control 可以在网页上将表格数据转换为图表,支持柱状图,曲线图以及圆饼图。支持 DataSource 工具,可设置的轴,鼠标盘旋提示,图表组合,以及皮肤等功能。
6. ProtoChart


ProtoChart 是一个基于 Prototype 和 Canvas 标签的开源库,这个库深受 Flot, Flotr, Plotkit 等启发,支持曲线图,柱状图,圆饼图等,可以在同一个图表上显示多套数据,支持可定制的图例,网格,边界以及背景图。支持 IE6/7, Firefox 2/3 以及 Safari,甚至支持 iPhone.
7. EJSChart


EJSChart 支持鼠标追踪,鼠标事件,按键追踪与事件,缩放,滚动,交互等功能,将用户体验上升到一个新高度。支持曲线图,面积图,离散图,圆饼图,柱状图等形式,拥有完备文档的属性和方法可以帮助实现很好的定制。
8. fgCharting
fgCharting 是一个很出色的 jQuery 插件,支持多种图形。
9. Pure Css Data Chart


以往的数据展示往往通过 flash 实现,现在,我们可以通过纯粹的 CSS 实现类似的功能。CSSGlobe 有一个非常实用的教程帮你实现基于 CSS 的绘图,甚至不需要 JavaScript。

本文国际来源:http://woork.blogspot.com/2009/03/useful-scripts-to-plot-charts-in-web.html
中文翻译来源:COMSHARP CMS 官方网站

使用ZendFramework的时候打印SQL

使用ZendFramework的时候打印SQL

在使用ZendFramework开发的时候,会遇到要对SQL进行优化的处理,但是从ZEND的DB类里并没有找到输出SQL的方法,唯一看到的输出也是在SELECT类里面有一个__toString()的方法,但这个方法也只能输出SELECT的语句,对于Insert,Update,Delete之类的语句并不能处理。

开始的时候,很郁闷,后来问HaoHappy,因为他是国内第一批翻译ZF手册的人,果然我一问,他一下子就说,有一个Profiler类可以解决。
翻开手册,Zend_Db_Profiler,里面果然有操作。。(注:类名是凭记忆的,以下内容也是凭记忆写出来的)

1、在DB的CONFIG里面把profiler打开,如果没有打开,则需要用$profiler = $db->getProfiler();然后 $profiler->setEnable(true); (好象记错了,请看手册,我这里只说解决方法)

2、然后有一个设置 Profiler 的filter条件的,可以设定select,insert,update,delete的操作。

3、然后根据官方的例子,对SQL进行输出(手册上的例子,只是输出了执行时间最长的SQL哦)。如果需要每条都输出,你得在那个 if 判断外把sql 存储下来,即 $query->getQuery();

4、根据手册,还可以输出到fireBug和利用FirePHP来进行类似的debug,但我试了一下没有成功( QEE 支持 firePHP ,不知道是否借鉴了ZEND的这个功能,猜测而己 )

纯粹是一个记录,顺便感谢一下HaoHappy

ZF在ubuntu下的运行

ZF在ubuntu下的运行

ZEND FRAMEWORK要想正常的在ubuntu的AMP平台下运行 ,得打开apache的rewrite模块。这和windows下面把rewrite前的注释去掉可不一样。

进入命令行:a2enmod rewrite

会提示你成功打开rewrite模块

然后:

/etc/init.d/apache2 force-reload

重新加载一下,不过,这样还是不能成功的,因为默认的virtualhost中 有一个参数的值默认为NONE,要改成ALL

运行 :

vim /etc/apache2/sites-enabled/000-default

修改

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
把AllowOverride None 的 None 改为 All

然后

/etc/init.d/apache2 restart

OK,现在运行ZEND的例子,正常了吧,呵呵

zf的paginator的疑问

zf的paginator的疑问

如果按照ZEND的手册,在使用Zend_Paginator类的时候有两种方法,一种是直接new,一种是用factory
当然,用factory是很方便的。只需要Zend_Paginator::factory( $array )就行了
可是,如果这个array很大怎么办?它没有说。。
即使是new Zend_Paginator( Zend_Db_xxx ?$array )[不记得括号中是哪个abstract了],如果数据量大,他也没办法的呀??

今天白天我试着一下子查询了1W多条,立马死掉。
我看网上的例子,大多是要么直接传结果,要么是传 ZEND_DB的查询对象进去。但结果集都不大的,所以顺利运行 了。我不知道结果集是上万的时候会怎么样,呵呵

最后我是采用了先COUNT出总数,然后用range生成一个大数组传组 Zend_Paginator::factory() ,因为我看他里面的计数是用count的,所以我对factory的数组参数就直接传了这个range出来的数组给它。

结果,成功了,看来,这也就可以了。只是方法有点妖而己。。

记录一下,备忘一下。

Config文件
[paginator]
page.pagemax = 10
page.pagestart = 1
page.itemperpage = 25

在文件里

<?php
//...前面略
$request = $this->_request ;
$currentPage = $request->getParam('page');
$result = $table->fetchAll( ... 条件 );
$resultCount = $table->getCount( ... 条件 ); //文件自己实现
$resultCountArray = range( 1, $resultCount ); //到底是从0到resultCount-1好,还是直接从1到$resultCount好,我没有仔细测试过

$paginator = Zend_Paginator::factory( $resultCountArray );
$paginator->setCurrentPage( $currentPage )
->setItemPerPage( 25 ) //这个方法可能写错了,我是凭记忆写的,请看手册
->setPageRange( 10 );
$this->view->paginator = $paginator;

部分参数在获取失败的情况下,会直接从Config文件里读取,这里就不详细写了,大致应该是:

<?php
//.....略
$config = new Zend_Config_Ini('...path...' , 'paginator' ); //即Config中[]包含的文字

$pageMax = $config->page->pagemax ;
//取出来的每条数据都是对象了
PHP框架:Treacle 介绍

PHP框架:Treacle 介绍

群友Bopo自己开发了一个PHP的framework。Bopo从认识到现在,大概也有四五年的时间了吧,不过这个框架的年龄并不是特别长,大概只有2年多左右。最早这个框架BOPO是自己做项目的时候一点点的做的,但后来他终于有想法将它逐步扩大成为了一个框架。

最初看到框架的时候,还是一个雏型,现在,比以前好多了,所提供的支持也多了很多。让我们来看看这个糖浆究竟有些什么。

Treacle 是个什么呢?

Treacle 为开发者轻松、快捷的创建应用程序提供帮助。Treacle 框架简单、清晰,容易理解和学习,并且有完全中文化的文档和丰富的示例程序降低学习成本。

Treacle 有什么特点?

  • 完全跨平台
  • 完全支持 PHP5
  • 不倚赖特别的 PHP 扩展模块
  • 简单、容易理解的 MVC 模型
  • 丰富的助手对象和组件
  • 开放源代码,完全中文化的注释和文档
  • 商业公司提供技术支持

如何获取技术支持?

您可以通过参与我们的论坛来获得技术支持。
官方网址:http://www.treacle.cn/

可能现在有些简陋,但是期待一下吧。