Archive

Archive for the ‘PHP’ Category

Extendiendo Zend Framework Router

April 13th, 2009

Actualmente estoy desarrollando un sitio no muy grande, donde tengo varias funcionalidades del estilo listado de articulos, buscador, pagina de detalles de un articulo determinado, etc. Lo interesante es que también necesito tener un mini-cms, donde el cliente edite el contenido de una determinada página y la misma quede pública para los visitantes del sitio. El asunto es que las urls que utilizamos para ZF son del estilo sitio.com/modulo/controller/action. En mi caso, si el visitante quisiera acceder a la clásica página “Sobre Nosotros” deberia ir a una url del estilo: www.sitio.com/cms/ver/sobre-nosotros. Pero el cliente me pidió que la url sea algo asi: www.sitio.com/sobre-nosotros, lo cual obviamente iba un poco en contra del routeo estandar de ZF.


Me puse a googlear, e investigando un poco llegué a la siguiente solucion (no investigué mucho, por lo que calculo que capaz que hay alguna solución un poco mejor).


Básicamente lo que hice es extender el Zend_Controller_Router_Rewrite y fijarme si se puede dispatchear la url usando el esquema predefinido de ZF, si no se puede dispatchear seteo un controller y un action por defecto que se va a encargar de procesar el contenido del mini-cms. O sea, si me llega www.sitio.com/sobre-nosotros directamente voy a llamar al action ver del controller cms.

El código del router personalizado sería el siguiente:


class Stekl_Controller_Router_MiRouter extends Zend_Controller_Router_Rewrite
 
{
 
public function route(Zend_Controller_Request_Abstract $request)
 
{
 
$request = parent::route($request);
 
$dispatcher = $this->getFrontController()->getDispatcher();
 
if(!$dispatcher->isDispatchable($request)){
 
$request->setParam('pagina', $request->getControllerName());
 
$request->setControllerName('cms');
 
$request->setActionName('ver');
 
}
 
return $request;
 
}
 
}">(.*?)


No tiene nada complejo el router, simplemente lo que hago es obtener el request, luego el dispatcher y finalmente fijarme si se puede dispatchear. Si no se puede, creo un parámetro “pagina” con el valor que vino en lugar del nombre del controller. Finalmente seteo el controller y el action donde va a ocurrir la magia de interpretar el “sobre-nosotros” que me vino.


No termine aún, todavía falta decirle al Front Controller que use el router que acabo de escribir en lugar del que viene por defecto con ZF. Para ello en el bootstrap escribo lo siguiente:


$frontController = Zend_Controller_Front::getInstance();
 
$router = new Stekl_Controller_Router_MiRouter();
 
$frontController->setRouter($router);
 
$frontController->dispatch();">(.*?)


Y listo, con esto debería salir funcionando. Obviamente se podrian armar cosas un poco más elaboradas. Pero para lo que necesito me funciona.


mstekl

Recopilacion de tutoriales Zend Framework

February 13th, 2009
Dando vueltas por la web encontre una genial recopilacion de tutoriales de Zend Framework. Tiene algunos para quiens recien comienzan a usar ZF y tiene otros que no son tan basicos. Espero que sirvan para algo:

Getting Started

Zend Framework Quick Start - Por Aldemar Bernal & Bradley Holt

Getting Started with Zend Framework – Por Rob Allen

Zend Framework Intro Step Por Step Tutorial – Por phpeverysday.com

Setting up Zend Framework applications with Phing – Por Raphael Stolt

Migrating to Zend Framework: Legacy Scripts – Por Chris Abernethy


Zend_Acl

Experience with Zend_Acl and usage example – Por Jeremy Knope

Zend_Acl and storing roles and resources in a DB – Por Jani

Zend ACL usage – Por Nick Halstead

Why you need a Zend Framework ACL and Cache GUI – Por Nick Halstead

Zend_Acl / Zend_Auth example scenario – Por Cal Evans


Zend_Auth

Login and Authentication – Por Matthew Weier O’Phinney

Getting Started with Zend_Auth – Por Rob Allen

Zend_Auth and the OpenId Adapter - Por Cal Evans


Zend_Controller

Zend Framework Action Step Por Step Tutorial – Por phpeverysday.com

Action Helpers in Zend Framework – Por Matthew Weier O’Phinney

Front Controller Plugins in Zend Framework – Por Matthew Weier O’Phinney

Extending the Router for custom routing

Benchmarking Zend Framework Routes – Por Chris Abernethy

Actions, now with parameters - Por Zend Developer Zone


Zend_Db

Zend Framework Hidden Gems: Zend_Db – Por Zend Developer Zone

Database Abstraction with Zend_Db (Part 1) - Por Alan

Database Abstraction with Zend_Db (Part 2) – Por Alan

Zend Framework Database Step Por Step Tutorial – Por phpeverysday.com

Integrating Zend Framework and Doctrine – Por Ruben Vermeersch


Zend_Feed

Getting Started With Aggregating RSS/Atom Content – Por Pádraic Brady

Syndicate content with Zend Framework Zend_Feed classes – Por Alex Netkachov

Parsing tags with Zend Feed – Por Henrik Sarvell

Using Zend_Feed to Merge Multiple RSS Feeds – Por Arik Fraimovich


Zend_Form

Simple Zend_Form Example – Por Rob Allen

Simple Zend_Form File Upload Example – Por Rob Allen

Zend_Form Advanced Features – Por Matthew Weier O’Phinney


Zend_Layout / Zend_View

Zend_Layout and Zend_View Enhancements Demo – Por Ralph Schindler

Simple Zend_Layout Example – Por Rob Allen

Using Zend_View Placeholders to Your Advantage – Por Matthew Weier O’Phinney


Zend_Log

Application-level Logging with the Zend Framework – Por Stefan Koopmanschap

Zend_Log revisited – Por Raphael Stolt

Developing a simple Zend_Log_Filter – Por Raphael Stolt

Zend_Mail

Sending Emails with the Zend Framework – Por Alan


Zend_Registry

Zend Registry Step Por Step Tutorial – Por phpeverysday.com


Zend_Search

Zend Search Lucene (part 1, 2, 3 and 4) – Por Ganesh H S.

Zend_Search (Java Lucene) - Por Natalie Kather


Zend_Validate

Checking Input with Zend_Validate – Por Alan


Zend_XmlRpc

Zend_XmlRpc_Client and session support – Por David Goodwin

Soap, XmlRpc and Rest with the Zend Framework – Por Andrew Johnstone


Web Services

Teaching the Zend REST server to talk JSON – Por Raphael Stolt

RESTful Web Services with Zend Framework – Por Pádraic Brady

Accessing the Google Base data API using Zend – Por Google

ClientLogin Authentication for Zend GData

Automating Amazon research with the ZF – Por W. Jason Gilmore


Unit Testing

The PHPSpec Zend Framework App Testing Manifesto – Por Pádraic Brady

An Introduction to the Art of Unit Testing in PHP – Por Pádraic Brady

mstekl