2009年9月30日星期三

Re: [fw-mvc] creating a cli interface to mvc web app

I posted a blog article about this just yesterday. The problem is that routing is a built in requirement of the FrontController dispatch cycle and there's no way to disable it, and yes, by default it insists on complaining about CLI requests.

You can wrok around it by supplying the FrontController with a custom Router which basically stubs all the right methods a Router needs, but which are all empty. So the FC can do routing, but the Router is just a dummy class that does nothing. Messy, but works ;). Here's the class I'm using:

<?php

class ZFExt_Controller_Router_Cli implements Zend_Controller_Router_Interface
{

    public function route(Zend_Controller_Request_Abstract $dispatcher){}
    public function assemble($userParams, $name = null, $reset = false, $encode = true){}
    public function getFrontController(){}
    public function setFrontController(Zend_Controller_Front $controller){}
    public function setParam($name, $value){}
    public function setParams(array $params){}
    public function getParam($name){}
    public function getParams(){}
    public function clearParams($name = null){}

}
 
Pádraic Brady

http://blog.astrumfutura.com
http://www.survivethedeepend.com
OpenID Europe Foundation Irish Representative



From: water <zflist@yahoo.com>
To: fw-mvc@lists.zend.com
Sent: Wed, September 30, 2009 9:35:55 PM
Subject: [fw-mvc] creating a cli interface to mvc web app

I wanted to create a scriptable cli to a web app that we have have. One of the things that it does is that it kicks off a set of writing thousands of static html files.

I have something like the following:
$fc=Zend_Controller_Front::getInstance();
$fc->setControllerDirectory(array(
                     'default'=>$app.'/controllers/'));

Zend_Layout::startMvc(array('layoutPath' => $app.'/layouts/'));

$request=new Zend_Controller_Request_Simple('jt','generator');
$response=new Zend_Controller_Response_Cli();

$fc->setRequest($request);
$fc->setResponse($response);
$fc->throwExceptions(true);
Zend_Debug::dump($request);
$fc->dispatch();

but it gives me the following error: 
PHP Fatal error:  Uncaught exception 'Zend_Controller_Router_Exception' with message 'Zend_Controller_Router_Rewrite requires a Zend_Controller_Request_Http-based request object' in /data/sites/site/www/zf_source/library/Zend/Controller/Router/Rewrite.php:359

Do I need to call this upon the index.php that I have in my doc_root? 

I'm sure somebody has crossed this bridge so I greatly appreciate the help.

-jonathan


没有评论: