zend framework router

2009-09-11 3:36 pm

zend framework 的 router很强大,今天用了一下觉得挺不错了,主要对SEO有很大的帮助,

拿上来分享一下:

在boostrap里面加载router,如:

    protected function _initRouter()
    {
        $ctrl  = Zend_Controller_Front::getInstance();
        $router = $ctrl->getRouter();
        $route = new Zend_Controller_Router_Route(
            'ranking/:date',
            array('module' => 'default',
                  'controller' => 'interface',
                  'action' => 'ranking',
            )
        );
        $router->addRoute('ranking', $route);
    }

在控制器里面直接$this->_getParam('date', NULL);就可以了,上面只是一个测试,没有实际的意义。
在seo中规范路径,用html格式等会给用户或者spider都带来很好的帮助。

推荐(0)
收藏

Zend Framework在firebug里面调试

2009-09-04 3:28 pm

其实应该很多同学都用过firephp这个firefox的插件(https://addons.mozilla.org/en-US/firefox/addon/6149 ),
能给在线上输出调试信息一些便利。
其实zend framework也整合了这个东西,所以使用zend的同学也可以不用去下载firephp的库而直接使用firephp(当然在firefox安装这个插件还是要的)。

使用方法:

$writer = new Zend_Log_Writer_Firebug();
$logger = new Zend_Log($writer);
$logger->info($log);

输出的信息不会在html里面,所以普通的用户是看不到调试的信息的,其实信息是输出在header中了,


然后通过firephp能看到:

规整的数据,这样可以不必把log写到文件中再去刷新文件,可以更规整,更方便一些。

推荐(0)
收藏

优化zend framework require_once

2009-07-10 6:18 pm

其实这个只是官方给的文档中照做而已,这里只是记录一下,详细可以参考官方文档。

% cd path/to/ZendFramework/library
% find . -name '*.php' -not -wholename '*/Loader/Autoloader.php' -print0 |
  xargs -0 sed --regexp-extended --in-place 's/(require_once)/// 1/g'

然后在index.php加入autoload

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

注销index.php里面的//require_once 'Zend/Application.php'; 因为已经有autoload了,
还需要修改application以包含Bootsrap.php,因为这个文件并不在include_path下,当然如你加入这个路径就不用了,但是我认为为这一个文件不值得,还是修改吧,把library/Zend/Application.php中292行的注销取消即可。
应该可以看到autoload的情况了。介绍一个分析autoload情况的工具,php的inclued的pecl。使用非常简单,稍后附上使用方法。

推荐(0)
收藏

zend framework strategy 策略模式

2009-03-19 5:17 am

策略模式strategy有点类似if/else语言,用以实现不同的程序逻辑,特别如在初始化不同程序逻辑。
比如zend framework中的Resource。

定义资源接口:

  1. 1
  2. 2
  3. 3
  4. 4
  1. interface Zend_Application_Resource_Resource
  2. {
  3. public function __construct($options = null);
  4. public function init();

抽象类实现接口:

  1. 1
  2. 2
  3. 3
  1. abstract class Zend_Application_Resource_ResourceAbstract implements Zend_Application_Resource_Resource
  2. {
  3. public function __construct($options = null)

不同程序逻辑实现(Resource):

  1. 1
  2. 2
  3. 3
  4. 4
  1. class Zend_Application_Resource_Layout
  2. extends Zend_Application_Resource_ResourceAbstract
  3. {
  4. public function init()

不同程序逻辑实现(View):

  1. 1
  2. 2
  3. 3
  1. class Zend_Application_Resource_View extends Zend_Application_Resource_ResourceAbstract
  2. {
  3. public function init()

最后使用策略的程序其实是:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  1. class Zend_Application_Bootstrap_Bootstrap
  2. extends Zend_Application_Bootstrap_BootstrapAbstract
  3. {
  4. if (!$this->hasPluginResource('FrontController')) {
  5. $this->registerPluginResource('FrontController');
  6. }

zend framework中还有其他地方都用到strategy模式。

推荐(0)
收藏