Category Archives: zend framework

Extending the art & spirit of PHP, Zend Framework is based on simplicity, object-oriented best practices, corporate friendly licensing, and a rigorously tested agile codebase. Zend Framework is focused on building more secure, reliable, and modern Web 2.0 applications & web services, and consuming widely available APIs from leading vendors like Google, Amazon, Yahoo!, Flickr, as well as API providers and cataloguers like StrikeIron and ProgrammableWeb.

Connect MySQL from Zend Server CE trough unix socket!

First of all, let me introduce you to my case. I’m working on a Mac with both Xampp and Zend Server CE. Both have separate MySQL servers installed from their default installation on my machine. Both have their separate phpMyAdmins.

The one thing I couldn’t find in the man page of Zend Server CE is how to I access this MySQL server installation from my PHP scripts.

The answer is quite simple – trough UNIX socket. The ZS CE default db socket is:

/usr/local/zend/mysql/tmp/mysql.sock

and yet again let me say that this is for Mac.

Zend_Openid and Google Accounts. Patch needed.

Zend_Openid

This extension as expected gives the Zend Framework the possibility to implement OpenId protocol. The problem is that the current version 1.9.6 does not work correctly with Google accounts.

The solution

can be found on one of the best resource sites – stackoverflow. You can simply follow the two comments to this post with no fear that this will work. It’s tested already.

Zend Framework – simply the best. Into the deep of OpenId

Now I’m convinced that Zend Framework is indeed the best of the best for the PHP community. Now I’m researching about the use of OpenId with ZF, and hopefully beside Zend_Auth there is entirely for that Zend_OpenId. Which is exactly what I needed.

Really a great community and very high level code. Talk to that soon about Zend_OpenId, with some sample code and Zend_Feed_Reader, my modules of choice.

Redirecting with Zend Framework

Many of the web applications need to be redirected to some given URI sooner or later. In that scenario like redirecting to the profile page after login, which is very common to almost every app, you need to change the URI of the browser after the login form is validated. You can make this by simply using the built in header function in PHP. In other terms the most popular method to redirect in Zend Framework, don’t know why, but this is the _forward method of the controller actions:

$this->_forward('action-name');

The problem here is that thus you get to the given action name, or controller/action but the URI of the browser stays as it is from the caller action.

If you’d like to redirect, like the header function will do it you should use the following construction:

$this->_helper->redirector->gotoRoute(array(
   'controller'=> 'contrlname',
   'action' =>'actionname'));

Zend Framework custom URLs

URL organization in Zend Framework

As you may know in ZF the urls are strictly organized. First you’ve the module, if you use modules. If there is only one module, and it is normally the default one, you omit the module name from the url. Than comes the controller name, the action name in that particular controller and than separate by / the url continues with key value pairs of the get parameters.

Of course to make this all work, you’d need to setup a simple .htaccess file just to rewrite all this to the index.php file which than parses the $_SERVER[‘REQUEST_URI’] to collect all the data he need about which controller, which action and what parameters to call.

That’s pretty simple. If you’ve the following URL /user/profile/name/john.smith you may suppose that Zend Framework calls the “user” controller, “profile” action with get parameter “name” which equals to “john.smith”. In a traditional PHP style old school URL this can look like this:

?controller=user&action=profile&name=john.smith

Why I need such long URL?

The problem is that Zend reads all this, parses it and than returns the correct output. But however not always this is what we want, right? I’d like to have custom url for the profile page. Why should I need both profile and name in my URL, I’d prefer a URL like this: /user/john.smith. Continue reading Zend Framework custom URLs