Twilight SEO

Standing at the border line. Beautiful color spectrum of Search Engine Optimization. White, Gray, Black Hat SEO learning by doing.

Kohana and Zend, Killer Combo! The best PHP5 framework and library in one package.

Posted in kohanaphp, php5, zend by ruru on the December 14th, 2008

My current favorite php framework is kohana. After several weeks playing with it, i feel that KohanaPhp far exceed CakePHP and CodeIgniter. Now i want to buid a *secret* site, after taking a look around i found that Zend framework has a neat library providing many classes that i need. Take a look of this list, you'll get the idea:

  • Zend_Acl
  • Zend_Captcha
  • Zend_Feed
  • Zend_Gdata
  • Zend_Http
  • Zend_OpenId
  • Zend_Pdf
  • Zend_Rest
  • Zend_Service_Akismet
  • Zend_Service_Amazon
  • Zend_Service_Audioscrobbler
  • Zend_Service_Delicious
  • Zend_Service_Flickr
  • Zend_Service_Nirvanix
  • Zend_Service_ReCaptcha
  • Zend_Service_Simpy
  • Zend_Service_SlideShare
  • Zend_Service_StrikeIron
  • Zend_Service_Technorati
  • Zend_Service_Twitter
  • Zend_Service_Yahoo

I really love it, but i don't like zend framework itself. So i search around and found this cool tutorial.

It gives cool trick but doesn't work well, so i modify a bit.

Put the 'Zend' folder (unpacked from the Zend Framework package, under 'Library/') in Kohana installation's 'application/vendors/Zend' folder

Copy code below and paste it to a new file called Zend.php in application/libraries/.

PHP:
  1. /**
  2. * Zend Framework Loader
  3. *
  4. * Put the 'Zend' folder (unpacked from the Zend Framework package, under 'Library/')
  5. * in Kohana installation's 'application/vendors/Zend' folder
  6. * You can put it elsewhere but remember to alter the script accordingly
  7. *
  8. * Usage:
  9. *   Zend::instance('Zend/Package/Name');
  10. *   Zend::instance('Zend/Service/Yahoo');
  11. *
  12. * * the second usage is useful for autoloading the Zend Framework library
  13. * * Zend/Package/Name does not need the '.php' at the end
  14. */
  15. class Zend
  16. {
  17. /**
  18. * Returns a singleton instance of URI.
  19. *
  20. * @return  object
  21. */
  22. public static function instance($class = NULL)
  23. {
  24. static $instance;
  25.  
  26. // Create the singleton
  27. if ($instance == NULL)
  28. {
  29. // Initialize the URI instance
  30. $instance = new Zend($class);
  31. } else
  32. {
  33. $instance->load($class);
  34. }
  35.  
  36. return $instance;
  37. }
  38.  
  39. /**
  40. * Constructor
  41. *
  42. * @param    string $class class name
  43. */
  44. function __construct($class = NULL)
  45. {
  46. // include path for Zend Framework
  47. // alter it accordingly if you have put the 'Zend' folder elsewhere
  48. ini_set('include_path',
  49. ini_get('include_path') . PATH_SEPARATOR . APPPATH . 'vendors');
  50.  
  51. if ($class)
  52. {
  53. require_once (string) $class . EXT;
  54. //Log::add('debug', "Zend Class $class Loaded");
  55. }
  56. else
  57. {
  58. //Log::add('debug', "Zend Class Initialized");
  59. }
  60. }
  61.  
  62. /**
  63. * Zend Class Loader
  64. *
  65. * @param    string $class class name
  66. */
  67. function load($class)
  68. {
  69. require_once (string) $class . EXT;
  70. //Log::add('debug', "Zend Class $class Loaded");
  71. }
  72.  
  73. }

Do you have trouble figuring out how to use it?
See an example below, you'll get a nice grab just within seconds:

PHP:
  1. class Welcome_Controller extends Controller {
  2.  
  3. public function index()
  4. {
  5. $zend = Zend::instance('Zend/Service/Yahoo');
  6. $yahoo = new Zend_Service_Yahoo('zendtesting');
  7. $keywords = "kitty";
  8. $results = $yahoo->imageSearch($keywords, array("results" => 5));
  9.  
  10. if ($results->totalResults()> 0) {
  11. <p id="image">';
  12. <h2>Image Search Results</h2>
  13. ';
  14. foreach ($results as $result) {
  15. echo "<a href="http://php.fallenray.com/wp-admin/%7B$result-%3EClickUrl%7D" title="$result-&gt;Title"><img src="http://php.fallenray.com/wp-admin/%7B$result-%3EThumbnail-%3EUrl-%3EgetUri%28%29%7D" /></a>";
  16. }
  17. ';
  18. }
  19. }
  20.  
  21. }

Another way to do this also posted as an updated tutorial. Things are getting much simpler now. I still liked my own twisted approach though :p

Also you might want to check out the official tutorial.

Happy ending, i can use the best PHP5 frameworks along with the best PHP5 library. It cannot get better than this. Try it, if you miss this you'll be sorry.

One Response to 'Kohana and Zend, Killer Combo! The best PHP5 framework and library in one package.'

Subscribe to comments with RSS or TrackBack to 'Kohana and Zend, Killer Combo! The best PHP5 framework and library in one package.'.


  1. on February 18th, 2009 at 2:42 am

    [...] best way to Integrate Kohana and Zend. I recently came across a really cool way to do this @ the Rainbow Hat SEO website. It differs from most other approaces in style and [...]

Leave a Reply




Cannot find your answer here?
Feel free to get in touch and ask PHP-ist anything, just anything :)