Skip to content

Instantly share code, notes, and snippets.

@claussni
Created February 17, 2010 12:01
Show Gist options
  • Save claussni/306541 to your computer and use it in GitHub Desktop.
Save claussni/306541 to your computer and use it in GitHub Desktop.
$ php zendphy.php
Hello, World
<?php
// set include path to library
set_include_path(implode(PATH_SEPARATOR, array(
'/opt/ZendFramework-1.10.1/library',
get_include_path(),
)));
// enable autoloading
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
// fool front controller to avoid complex application setup
$front = Zend_Controller_Front::getInstance();
$front->throwExceptions(true);
$front->setParam('noViewRenderer', true);
$front->setControllerDirectory('.');
// setup custom route for say controller
$router = $front->getRouter();
$route = new Zend_Controller_Router_Route(
'say/:something/to/:someone',
array('controller' => 'say', 'action' => 'get'));
$router->addRoute('say', $route);
// say controller class
class SayController
extends Zend_Controller_Action {
public function getAction() {
$request = $this->getRequest();
$something = $request->getParam('something');
$someone = $request->getParam('someone');
$this->getResponse()->appendBody($something . ', ' . $someone);
}
}
// let front controller dispatch mind shaking url
$request = new Zend_Controller_Request_Http('http://helloworldapp/say/Hello/to/World');
Zend_Controller_Front::getInstance()->dispatch($request);
echo "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment