Zend: How to fix the 404 Problem in a Zend Framework Project

If you have a nice and shiny new Zend Framework project all set up but are still getting nasty browser 404 errors when attempting to hit URL other than the home page (instead of the expected errors dealt out by the error handler controller), the root of your problem is actually quite simple:

Your Apache mod_rewrite module is disabled and your Apache directory AllowOverride directive is not switched on.

To fix is easy enough. Locate your Apache httpd.conf configuration file and open it up. Run a search for mod_rewrite and you should find the line:

#LoadModule rewrite_module modules/mod_rewrite.so

Uncomment it in order to enable, by removing the # character from the front of the line.

Next search for AllowOverride and you should find it in one of your declarations. If it is present, change the value to All. If it isn’t, add it. (Note if you are using virtual hosts you will need to set it under the virtualhost declaration). Setting this to all means that Apache will honour local .htaccess files, which is exactly what Zend, in conjunction with mod_rewrite, depends on.

Restart Apache, and hit a non home page URL.

And now you know.

Posted in Zend | Tagged 404, allowoverride, front controller, mod_rewrite, pretty url, | View Comments

Web Design: How to Stop Text from Word Wrapping

Although in 99% cases, word wrapping in web pages is essential, there is that 1% of the time where you do actually want a line of text to remain on a single line, even if it does push your page into horizontal scrollbar land (which is always a bad thing note). Like phone numbers for example. You don’t really want those to wrap if they are expressed in a token format for easier reading: e.g. <-- I'm not using the trick here, so this will word wrap if necessary! :)

Anyway, back in the day HTML had what was called the NOBR tag, basically an inline tag that prevented text from being broken / word wrapped.

Don’t wrap this text

It still works and is supported by the major browsers, but it has long since been deprecated in the HTML specification meaning that ideally, you shouldn’t be using it in your website code.

So a different solution then?

CSS has the useful white-space attribute and leveraging this you can create a CSS class which can then be applied as part of the block or inline HTML container holding the text you don’t want to break.

The rule looks like this:

.nobr {white-space:nowrap;}

And now you know. Nifty.

Posted in HTML & CSS | Tagged , nobr, nowrap, , word wrap | View Comments

Worth Reading: Zend Framework in Action (Rob Allen, Nick Lo, Steven Brown)

Let me start off if you want to learn to program, or learn to program in PHP specifically, you don’t learn by starting off using a framework. That is not going to teach you anything other than making you unable to solve small problems in the most efficient manner.

However, if you are already a programmer and have been asked to pick up Zend, the first thing you’ll find is that the learning curve into Zend is steep. Very, very steep.

So much so that there is no way a bunch of simple tutorials are going to get you properly versed in the framework, leaving us in other words with proper learning materials – i.e. books.

And if you are looking for a good book, look no further than the excellent Zend Framework in Action by Rob Allen, Nick Lo and Steven Brown, published by Manning.

In depth, covering all aspects of the Zend Framework in an easy to understand manner, padding out with a lot of examples (and more importantly, a nice complex real world website that gets carried throughout the text), Zend Framework in Action is an excellent read to get you properly up and running and well on your way to becoming proficient in the world of Zend.

Nifty.

Posted in Zend | Tagged book, nick lo, rob allen, steven brown, , zend framework, zend framework in action | View Comments

How to Create a Zend Project from the Command Line with zf

To generate an empty project shell using the Zend Framework is pretty easy thanks to the powerful zf command line utility.

To create a project, simply open a command line window, browse to the directory in which you want to create your Zend Framework project and enter:

zf create project "My Project"

where My Project is the name of the project you want to generate. Note that for project names containing spaces, you can make use of double quotes to enclose. Also, zf (or rather the Zend bin directory) should be added to your system PATH in order to give it global visibility and thus make it easier to use.

The program will create a directory matching the name of your given project, and populate it with all the necessary Zend shell structures. You should at a minimum have application, docs, library, public and tests folders in the root, as well as a .zfproject.xml file. In the public folder, check that there is a .htaccess file containing the following rules:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Finally, you need to either symlink the library folder to that of the installed Zend framework’s library folder on the system, or just copy the Zend framework library folder’s contents into the library folder of your new project directory.

Done.

Posted in Zend | Tagged , create, project, , zend framework, zf | View Comments

Simple Zend Tutorial for People Starting Out… with Zend

This post serves more as a bookmark for me than anything else, now that I have been tasked with learning the icky world of Zend and its MVC pattern from the powers above here at work. Learning Zend is not for the faint hearted, that is for sure, and just finding your feet takes a fair bit of reading.

One of the best introductory and explanatory tutorials introducing new users to Zend that I have come across yet, is written by one Nicholas Chase, a consultant at Backstop Media who writes for the IBM developerWorks website.

Originally written way back in 2006 and consequently updated in January 2011, this excellent nine part tutorial covers just about everything someone starting out needs to know, including database work, feed and inputFilter usage, HTTPClient and PDF, e-mail sending and searching, connecting to outside services like Flickr and even adding AJAX to your application.

The tutorial segments are all well written, well laid out, with detailed explanations seemingly always forthcoming.

And hey, after going through everything you’ll even have your very own RSS reader to show off! ;)

You can kick off the tutorial by clicking here.

Nifty.

Related Link: http://www.ibm.com/developerworks/opensource/library/os-php-zend1/

Posted in Zend | Tagged ibm developerworks, nicholas chase, , , zend framework | View Comments
Navigation »