Spiga

Zend Framework Bootstrap file class

February 27, 09 by Gabi Solomon

After starting working with zend framework i found all sorts of examples of bootstrap files, but a lot of them seem pretty messy to me since all the calls to zend components were basically thrown in there.

So after a lot of looking around i came up with a bootstrap files that is more to my liking. I found the initial class on a blog post when i was looking around but i don’t remember where, so sorry for not giving it the credit.

Read the rest of this entry »

Install Error: Missing Dependency: perl(URI) >= 1.17 is needed by package subversion

December 29, 08 by Gabi Solomon

Today i finally decided to go ahead with installing subversion, after a bit of reading i opened a ssh session and input :

[root@servername ~]# yum install subversion

But to my surprise i got an error :(

Error: Missing Dependency: perl(URI) >= 1.17 is needed by package subversion

After a bit of googling i managed to find a solution on a forum and i thought to post it here, maybe other will find it faster :D

First we need to download the perl(URI) with version greater than 1.17 using the following command.

wget http://yum.trixbox.org/centos/5/RPMS/perl-URI-1.35-3.noarch.rpm

Then to install the perl package :

rpm -i perl-URI-1.35-3.noarch.rpm

That is it, you can now install and configure subversion as normal.

Cheers.

Advanced guide to Aspire one

December 28, 08 by Gabi Solomon

A friend of mine just bought a e-pc from acer that runs a custom linux OS called aspire one.
At first sight it seems like it a great solution for basic users since it has a very friendly interface, and it comes preinstalled with a a pack of software that is generally used like IM client, email reader, browser, office suite and much more.

aspire one 10 OS

But although this looks nice, it becomes a problem when you want more from your epc, when you want to install new apps or want to customize something. You dont even have a right menu on the desktop.

How to enable advanced menu [small hack]

To do this you will need to go to Files > My Documents. In the window opened go to the File Menu and click on Terminal.
In the terminal window input xfce-setting-show and hit enter.
This will bring up the Xfce Settings Manager.

Click on the Desktop link and you will get the Desktop Preferences window where you must select the Behavior tab.
Now mark under Menus the Show desktop menu on right click option and close the window.

Now you will bring up the normal desktop menu when you right click somewhere on the desktop which contains more options than the limited user interface on the Aspire One.

Changing the root password

Now for even more advanced usage you will need to use the root user. But after a lot of searching i came to the conclusion that you cant find out what the password for the root is, instead you can change it.

To do so you must click on the desktop and open a terminal window ( you can find it under System > Terminal ).
In the terminal window first type “Sudo –su” and hit Enter.
Then type “passwd” and hit Enter.
You will now be prompted to enter the new password. After typing press enter and retype it.
That is it. You have successfully changed the root password :D

Installing new applications

Now that you have enabled the advanced menu and have the root password you can proceed to installing new applications.
This is quite simple, you just right click on the desktop and select System > Add/Remove Software.
You will be prompted to enter the root password and after you enter it the package manager will launch.
And now the install should be easy as cake and is similar to any Linux based OS.

Adding new shortcuts to your desktop

Even though you have enabled the new advanced menu and you can access your new installed software from that menu, it just doesn’t feel right. I bet you want them to be included in the shortcuts from the desktop. Well that is just a bit tricky, you will need to edit an xml config file.
The address for it is :

/home/user/.config/xfce4/desktop/group-a pp.xml

Hope this was helpfull,
Cheers

using Zend Framework Language component

December 15, 08 by Gabi Solomon

Today i will continue the series of articles on the zend framework and i am going to talk about how i come to use the language component from zend.

The way i decided to go with it is by having a controller plugin that starts the language component and also detects the language.

But first thing first. We need to make the url to allow us to change the language. And to do that i added a new rule in the bootstrap file:

PHP:
  1. $route = new Zend_Controller_Router_Route(
  2.             ':language/:controller/:action/*',
  3.                 array(
  4.                     'language'   => 'en',
  5.                     'module'     => 'default',
  6.                     'controller' => 'index',
  7.                     'action'     => 'index'
  8.                 )
  9.             );
  10.         $router->addRoute('lang_default', $route);

This rule will produce urls like:

http://www.domain.com/en/controller/action

http://www.domain.com/es/controller/action

I decided to go with this type of URL instead of caching or storing the language in the session to not have google consider our pages as duplicate content. I have read that it better to go with subdomains (ex: http://en.domain.com/controller/action ) that with directories but for now i will do it this way.

Now that we are still in the bootstrapfile, we will also add our plugin:

PHP:
  1. Zend_Controller_Front::getInstance()->registerPlugin(new GSD_Controller_Plugin_Language());

ANd now for the final touch the plugin:

PHP:
  1. <?php
  2.  
  3.  
  4.  
  5. /**
  6. * Front Controller Plugin
  7. *
  8. * @uses       Zend_Controller_Plugin_Abstract
  9. * @category   GSD
  10. * @package    GSD_Controller
  11. * @subpackage Plugins
  12. */
  13. class GSD_Controller_Plugin_Language extends Zend_Controller_Plugin_Abstract
  14. {
  15.        
  16.     public function routeShutdown(Zend_Controller_Request_Abstract $request)
  17.     {
  18.        
  19.         $locale = new Zend_Locale();
  20.        
  21.         $options = array('scan' => Zend_Translate::LOCALE_FILENAME);
  22.         $translate = new Zend_Translate('gettext', Zend_Registry::get('siteRootDir') . '/application/languages/', 'auto', $options);
  23.        
  24.         $requestParams = $this->getRequest()->getParams();
  25.         $language = (isset($requestParams['language'])) ? $requestParams['language'] : false;
  26.                 if ($language == false) {
  27.                      $language = ($translate->isAvailable($locale->getLanguage())) ? $locale->getLanguage() : 'en';
  28.                 }   
  29.         if (!$translate->isAvailable($language)) {
  30.             throw new Zend_Controller_Action_Exception('This page dont exist',404);
  31.         } else {
  32.        $locale->setLocale($language);
  33.             $translate->setLocale($locale);
  34.             
  35.             Zend_Form::setDefaultTranslator($translate);                                
  36.    
  37.            
  38.             setcookie('lang', $locale->getLanguage(), null, '/');
  39.             
  40.             Zend_Registry::set('Zend_Locale', $locale);
  41.             Zend_Registry::set('Zend_Translate', $translate);
  42.         }
  43.     }
  44. }

A few explanations on the code.
I am using gettext adapter with auto mode ... witch will basically crawl the language directory to detect what languages can you support. I also use it conjunction with Zend Locale and at the end i store the in the Registry.
Storing Zend translate in the registry will enable you to use it in the view in a very easy way using a built in helper.

Using translate in you controllers

PHP:
  1. $this->view->title = $this->view->translate('default-register-index-title');

Using translate in you views

PHP:
  1. <?php echo $this->translate('default-register-index-title'); ?>

As a note i am not using the full text for translate i am using keys that have a naming conventions like "module-controller-action-message". I find it much more easier then putting the whole string and also much more easier to maintain. Imagine if you misspelled a string, or want to modify it ? you will then have to modify it every in your code.

That is basically it.
Cheers

Update:
I have also published this plugin on phpclasses, you can find it here.

Zend Framework modular directory structure

December 01, 08 by Gabi Solomon

After a lot of thinking and going back and forth about this idea, i finally decided to start using ( learning at first ) zend framework.

The main decision was to go with an already built framework or an inhouse one. And although i really like reinventing the wheel sometimes, i said i will not do the same this time.

After deciding i wanted to use an exiting framework, i had 2 candidates in mind : CodeIgniter or zend framework. The plus for codeigniter was the fact that it went with a more familiar approach to MVC, and the plus for zend was the company behind it. The downside about zend, was for me at least, the size of it, and the fact that it seemed a lot to learn.

But i decided to take a chance and learn Zend. The main problem i had was how to start ( as all things are :D ). Because the have such a freedom in development, i was a little puzzled on how to structure my application.

The only thing i knew was that i wanted to go with a modular structure. From there i did a lot of googling, read and watched a few presentation about this topic and finaly came up with a structure wich is bassed much on Wil Sinclair proposal.

My Zend modular structure

I will try to explain it, why i chose it this way and what each folder contains.

1. Application

The main aplication folder
1.1 Config - Contains application configuration files ( ex: mysql details )
1.2 Controllers - General Controllers, that are common in all modules
1.3 Languages - Holds the language files
1.4 Layouts - This directory is for MCV based layouts.
1.5 Models - This directory holds the application models ( in put them here instead of the modules directory since i belive there are common to all application and its more better this way )
1.6 Modules - I really liked the idea of modules that zend used because it enables you to organize your controllers and views much better in a separate folder for different sections of a website ( for example the main website, editors area and admin panel )
1.7 Views - I also included a views folder in the main application because i though i could use it to store common views for the 3 modules.

2. Data

This folder holds various information that is temporary, like cache, session data etc.

3. Docs

This directory is for documentation automatically generated or hand written.

4. Library

This directory holds the library Zend Framework files and also other folders for your own library (extended from Zend or not). I have one called GSD that extends some zend classes.

5. Public

This directory would contain the public files for your application: index.php. index.php ( this will include the bootstrap.php file from your application/ directory) and the front end assets (css, javascript, images, flash etc )

6. Tests

This directory would hold the application tests. This is a cool feature about Zend that it has support for writing application tests to better test your code during development.

Final Words

Ok this is about it so far. I am still a beginer with zend, and this structure is what i have thought off so far, and it doesn't have some real application testing. Use it at your own expense :) )
I am sure as i start developing using zend that it will be modified.

Another bad thing about zend is that there aren't so much resources and real examples about it, this is why i will write about my journey with zend here. Hopefully somebody will benefit from it. :)

Cheers