Archive for 'PHP'

Insert processing istruction to Zend View Helper Navigation Sitemap dom object

What if you want to associate a xslt stylesheet to the sitemap generated by Zend_View_Helper_Navigation_Sitemap. I did it by adding a xml-stylesheet processing instruction to the view helper dom object. Here is the code:

class SitemapController extends Zend_Controller_Action
{
public function indexAction ()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender("true");

$pages = array();

// generate the pages array somehow
$someservice = new My_Serivce_PageGenerator();
$pages = $someservice->fetchAllMyWebsitePages();

// generate sitemap xml
$xml = $this->_generateSitemapXml($pages);

$response = $this->getResponse();
$response->setHeader('Cache-Control', 'public', true);
$response->setHeader('Content-Type', 'text/xml', true);
$response->appendBody($xml);

}

private function _generateSitemapXml ($pages)
{

$sitemap = new Zend_View_Helper_Navigation_Sitemap();

$sitemap->setView($this->view);
$sitemap->setUseSitemapValidators(false);
$sitemap->setMinDepth(0);
$sitemap->setMaxDepth(0);

$container = new Zend_Navigation();
$container->addPages($pages);

$sitemap->setContainer($container);


// get the dom object
$dom = $sitemap->getDomSitemap();

// define path to xslt stylesheet
$xslt_file_path = '/sitemap_style.xsl';

// create processing instruction
$xslt = $dom->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="' . $xslt_file_path . '"');

// add it to the dom
$urlset = $dom->getElementsByTagName('urlset');
$dom->insertBefore($xslt, $urlset->item(0));

// instead of using the render method we use this:
$xml = $sitemap->getUseXmlDeclaration() ? $dom->saveXML() : $dom->saveXML($dom->documentElement);

return rtrim($xml, PHP_EOL);


}

}

Magento for Developers: Part 1 Introduction to Magento

What is Magento? It’s the most powerful online eCommerce platform in the universe and is changing the face of eCommerce forever.

Of course, you already know that. What you may not realize is Magento is also an object-oriented PHP Framework that can be used to develop modern, dynamic web applications that tap into Magento’s powerful eCommerce features.

This is the first in a series of articles in which we’re going to go on a whirlwind tour of Magento’s programming framework features. Don’t worry if you don’t follow everything immediately. As you study the system more everything in this article will start to make sense, and you’ll soon be the envy of your colleagues stuck working with more primitive PHP systems.

Magento “Knowledge Base” Magento for Developers: Part 1 “Introduction to Magento” eCommerce Software for Growth

PHP date.timezone warning fix

OK, Have you gotten this (or similar):
PHP Warning: PHP Startup: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Los_Angeles’ for ‘-8.0/no DST’ instead in Unknown on line 0

I am running PHP 5.3.0 on my Windows XP, and have spent the better part of the day to try to get rid of this warning and finally managed to do it. How, you say?

The breakthrough came after I have read this instructions from the PHP web site Changes in PHP datetime support. Here is part of it:

Since PHP 5.1.0, there has been an extension named date in the PHP core. This is the new implementation of PHP’s datetime support. Although it will attempt to guess your system’s timezone setting, you should set the timezone manually. You can do this in any of three ways:

  • in your php.ini using the date.timezone INI directive
  • ion your system using the TZ environmental variable
  • ifrom your script using the convenience function date_default_timezone_set()

All supported timezones are listed in the PHP Manual.

Notice that you can set your system’s timezone setting using php.ini, set TZ environment variable or from your php script.

The first option did not work for me. The third option does not work for php scripts that are not written by me, so the only option left is to set environment variable TZ. That finally saved the day!
On Windows XP:

  1. go to My Computer
  2. View System Information
  3. Advanced Tab
  4. Environmental Variables
  5. Add New Variable with name ‘TZ’ and value whatever your timezone is. In my case is ‘America/Los_Angeles’.

That’s it. I hope this saves somebody few hours of searching.

Zend, Microsoft, IBM join forces to simplify cloud-app devlopment for PHP coders | All about Microsoft | ZDNet.com

As this article says all the right buzzwords are part of a newly unveiled Simple API for Cloud Application Services. It’s an open-source initiative that currently includes Zend, Microsoft, IBM, Nirvanix, Rackspace and GoGrid as the founding members. (No Google and no Amazon, however.) Here you can read more : Zend, Microsoft, IBM join forces to simplify cloud-app devlopment for PHP coders | All about Microsoft | ZDNet.com.

Phing

One of the best Phing resources I have come across is the blog of Raphael Stolt. I have used Phing based scripts for backup and code generation, but that is not all you can do with it. As Raphael is showing in its blog, you can use it for unit testing, phplocing (see my post on phploc), refactoring, code sniffing, database generation and so on.

Open Programming Laboratory

This is good place for zend framework samples

SEO and Url Rewriting

This is interesting discussion about url rewriting.  Here is the link .

Andi Gutmans on working with Microsoft & Improving PHP on Windows

Today at Zendcon Bill Hilf and Andi Gutmans announced a new technical collaboration aimed at improving the performance of PHP on Windows both for IIS 6 as well as in the future including IIS 7 on Longhorn…

read more | digg story

Sitepoint PHP Blog

Check this blog out! Or as I saw somewhere : Have you had you PHP today?

PDF Generation with Apache FOP

I wrote a small PHP class for generation of PDF document using XML,XSL-FO and Apache FOP Generation. [...]

Zend Framework

Zend came up with their own framework

PHP

PHP Official Site