Getting to know Zend_View

June 10th, 2006

Like many other PHP developers I’m keeping an eye on the progress of the Zend Framework. It’s currently still in the very early stages of development but is nonetheless worth “getting to know”. These are some notes from a play around with the current View functionality.

I generally use a nested layout template file with PHP embedded in HTML. Variables are assigned by a controller file so a layout template may look like this “main_layout.php” file:

<body>
    <?php include 'modules/header.php'; ?>
    <?php include $page; ?>
    <?php include 'modules/footer.php'; ?>
</body>

After some much appreciated help from Paul M Jones and Simon Mundy on the Zend Framework General List, I now have the following three methods of doing the same in the Zend Framework.

Use Zend_View::_script()

Include the additional views directly in the layout using the Zend_View::_script() method:

<body>
    <?php include $this->_script('/modules/header.php') ?>
    <?php include $this->_script( $this->content ); ?>
    <?php include $this->_script('/modules/footer.php') ?>
</body>

Use assigned variables

Assign the additional views in the controller file and then use the variables in the layout:

In the view controller:

$view->header = $view->render('modules/header.php')
$view->content = $view->render('page.php')
$view->footer = $view->render('modules/footer.php')

In the view script:

<body>
    <?php echo $this->header; ?>
    <?php echo $this->content; ?>
    <?php echo $this->footer; ?>
</body>

Use Zend_View::render()

This seems to be the “proper” solution as it makes full use of the _file stack in render().

Call Zend_View::render() from within the view script:

<body>
    <?php $this->render('modules/header.php') ?>
    <?php $this->render( $this->content ) ?>
    <?php $this->render('modules/footer.php') ?>
</body>

The above three solutions all require a final call to render the whole layout in the view controller file, e.g.:

echo $view->render( 'layouts/main_layout.php' );

Cautionary Note

Since the framework is currently in preview release stage it’s possible that the above may change soon after posting this (though I suspect probably not much if at all).

Update (8th November)

As of the latest SVN checkouts Zend_View::render() does not echo the output so you will need to use…

<?php echo $this->render( $this->content ) ?>

Ranking on Yahoo! Australia

June 1st, 2006

Further to my Google, PageRank, search results placing post and yet again for the sake of posterity and curiosity I have to record a further oddity in our search engine rankings.

We are currently second place for “ingredients australia” in Yahoo! Search, Australia and NZ and since the addition of this relatively minimal amount of text…

Web Design and Development

Projects we are and have been working on include; underwater.com.au, Byron Bay Dive Centre, Whale Watching Byron Bay, Marine and Coastal Community Network, Marine Passions, PacMab, Melaleuca House, Byron Bay Accom (In conjunction with Nextwave Media).

While there is not much here at the moment you’re welcome to take a look at Sandra’s or Nick’s notes.

Contact Ingredients Australia, PO Box 1437, Byron Bay, NSW 2481, Australia | contact@ingredients.com.au

…we have moved up to 3rd place in Google for the same search.

Once again it is not especially significant that we get the rankings for what may be an obscure search term (Although we have already had hits from searches like “ingredients in australia”). It is however an indication that the idea of aiming for some kind of niche has validity at least for search engine placement. If you try and search for “web design and development australia” I doubt we’d appear after thirty pages of results.

Almost as soon as we connected up the wiring for ingredients.com.au we began receiving mistaken emails from food and general ingredients suppliers. All that was based simply on our using the keyword “ingredients”.

Anyway, for now I’m just keeping an eye on the changes and clearing up the inevitable junk email being sent to our newly popular contact@ email address!

Using fonts on web pages

June 1st, 2006

Using a specific font in brochures, stationary and other printed material is simple, so why then is it such an issue when developing web pages?

Unlike the printed page the display of web page text is limited to the fonts available on each viewer’s own computer. The most commonly available Western fonts are just a small selection of around 10 or so, which can include Times New Roman, Arial, Verdana, Georgia, Trebuchet, Impact, etc.

When developing a web page the font to be used for say headers or paragraphs can be specified in a stylesheet like so:

h1 { font-family: Helvetica, Arial, Sans-Serif; }

This tells the page that for all headers size 1 (h1) try to use the font Helvetica, or, if that is not on the viewers computer, try Arial, or, if that is not on the viewers computer, try whatever sans-serif font they do have.

What if I want to use a font that is not commonly available?

If you decide you want to use a font that is not commonly available on your viewer’s computer, such as Sand, you could try and specify…

h1 { font-family: Sand, Helvetica, Arial, Sans-Serif; }

…which would work great for the ones that have Sand installed as we can see below…

Sand Installed

…unfortunately for everyone else it would work down the list until it hit a font they do have installed. In the image below the viewer does not have Sand but does have Helvetica

Sand Not Installed

But I really want my viewers to see my font!

If you really want all your viewers to see the headers in your font of choice, just about the only way to do so is to use an image made using that font. Below is an example of such an image which, in contrast to this paragraph, you’ll notice you cannot cut and paste text from:

Look Like Text

The downside of using images over text

Since the text is in fact a picture of text, it is essentially invisible to anything that can only read actual text such as a search engine or a text reader.

If you’d like to see this for yourself, try making the following setting in Internet Explorer:

Go to Tools > Internet Options > Advanced Multimedia > untick “Show pictures”

If you then reload this page you will be able to see how the “I look like text but I’m really an image” image disappears, leaving no actual text at all. That is how a search engine sees your page (Sidenote: that setting is also useful if you have a very slow connection and don’t want to waste time waiting for web page images to load.).

Another downside is the need to generate images for every header on the page. Updates to the page may also require redoing those images.

So what are the solutions?

Stick to fonts commonly available on the majority of computers.
While this is the least exciting option, it is the most failsafe and practical solution.
Use an image but make sure it is not crucial to the understanding or value of the page
By making the header more of a decorative addition you can somewhat side step the potential loss of functionality should it not be able to be seen. In practice it would be very hard to do this on a page with a number of headers. Search engines and text readers would also be less able to weight the elements of the page since there would be less structure to the text.
Use an “image replacement technique”
These are really hacks that try to have the best of both worlds; the viewer sees the image if they can but if not the text is available as a backup. There are many different alternatives, none of which have conclusively solved the issue.

Ultimately all web developers are waiting for this issue to be solved by updates to the various technologies involved. In the meantime, we are left to decide on the most appropriate solution (or combination of solutions) from those mentioned above.

Further Reading

Image Replacement. Again.

Thierry Image Placement

The Anatomy of Web Fonts

Natural Sequence Farming

May 22nd, 2006

Growing up in Scotland and Northern England surrounded by farms gave me a decent respect for the work involved in farming. I still remember desperately pulling on my “wellington” (gum) boots and running to catch up with the local shepherd’s tractor as he passed by our house.

Under the advice of the very same shepherd, I did not to go into farming, however, I’m still drawn by stories like this ABC episode of Australian Story on Peter Andrews:

Peter Andrews is a racehorse breeder and farmer credited with remarkable success in converting degraded, salt-ravaged properties into fertile, drought-resistant pastures. His methods are so at odds with conventional scientific wisdom, that for 30 years he has been dismissed and ridiculed as a madman. He has faced bankruptcy and family break-up.

The programme and the Natural Sequence Farming website are a good read for anyone interested in the uniqueness of the Australian landscape and the ways in which traditional European agricultural methods have worked against it.

Carrot

May 22nd, 2006

Like most people in search of info, I have endured the old Google routine of clicking through page after page of results, to find a site that is not just trying to sell me something. It is therefore quite refreshing when you find a simple one like the search results for “carrot” and the first link is to the World Carrot Museum which has more information about carrots than you could (or should?!) probably ever need.

Of course not everyone is in need of enormous amounts of information about carrots, but for those of us that are, Google and the internet have served us well!

Google, PageRank, search results placing

May 11th, 2006

Right now our home page has a Google PageRank of 4/10 and we are on the first page of search results for the words “ingredients australia”. To give some perspective on that, we are currently only 7 places below Vic Cherikoff’s website and his site has a PageRank of 5/10. Vic Cherikoff’s site is one that definitely does have a great deal of valuable content relating to “ingredients australia” and has been around for a long time.

In of itself that would not be very surprising, until you consider that we have almost nothing on the front page. In fact, the page Google has currently indexed simply says “Sorry, there is nothing here yet but you can contact us at….”. Not only does it have very little content on it but it has no links out of it (except for our email) nor does Google have any links to it indexed. We have also made very little mention of our site.

How much real value this has depends on whether we are specifically aiming to attract Google traffic based on the keywords “ingredients australia”. Nevertheless it is interesting to see just how skewed search engine results can get.

(Note having said all that, these results may just disappear as soon as I publish this!)