Coders Army

You're in the army now

Follow me on TwitterRSS Feeds

  • Barracks
  • Mess Hall
  • MIA
  • Spec Ops

Zend Lego – Initialise, Part 1

Feb 12th

Posted by Matt Cockayne in Spec Ops

No comments

So we have managed to get a basic starting point for the application. Its time to now load everything that we are going to be using into it.

If you want to get a complete example of the Initialise class that i’m going to be talking about you can view it at http://code.google.com/p/zucchi-titan/source/browse/trunk/application/Initialise.php.

So the first thing to address is the reasons for this being a plugin. The main reason is because the Zend Frameworks plugin structure allows us to trigger off different things at set intervals in the applications loading/closing.

The primary functions we will need make use of the plugins capabilities are

public function __construct()
public function routeStartup()
public function routeShutdown()
public function dispatchLoopStartup()
public function preDispatch()
public function postDispatch()
public function dispatchLoopShutdown()

These are loaded in the order they are listed here. We will go through the structure of plugins in more depth at a later date.

So we start with our constructor. Here we load anything that is needed throughout the entire site an dnot just at set intervals.

In the original Zend Lego post we called instantiated the class with

$frontController->registerPlugin(new Initialise(APPLICATION_ENVIRONMENT));

The first thing to handle is the APPLICATION_ENVIRONMENT constant. Inside the class we will assign this to the variable $_env. so that we can refer back to it when needed.

We then will want to set a session so that we can make use of that across the application. I’ll cover this a little bit later.

The next thing is to get a reference to the Front Controller so that we can set that up to do waht we need it to. We can get this by using a static call to the front controllers ::getInstance() method like so

$this->_front = Zend_Controller_Front::getInstance()

Using the static method means that we keep to a singleton pattern and don’t accidentally set a second front controller.

We then get into calling a bunch of custom methods to set up specific items. More >

Cache, Config, error, Framework, Front, locale, plugin, registry, Zend

Virtually Possible in a Box

Feb 9th

Posted by Matt Cockayne in MIA

No comments

I tend to have to jump between OS depending on what I am doing. I finally got my act together and figured out how to set up my Ubuntu install to connect to my windows partition to save me having to reboot every time.

I have managed to get this to work only with Windows XP… Vista appears to be a nightmare for me to get working so if anyone has any success I would love to hear from you.

Also I have had different people try this on a number of different machines with varying results, so please don’t get angry if this doesn’t work for you. A lot of the time it has appeared to be windows not liking the setup used by VirtualBox. All I can suggest is to have a look at the settings tab and try different combination. In some situations people have just not been abel to get it working on their existing install and have had to reinstall windows. My advice to you if you get to that point is to just leave it be and install a separate virtual machine and just leave you partition as is should you ever want to go back to it for something.

Heres how i did it:

  1. Install VirtualBox
    I installed the Sun version but I have tested with the OSE version and it worked fine. For more info on setting up the Sun version via the repositories see http://www.virtualbox.org/wiki/Linux_Downloads

    sudo apt-get install virtualbox-2.0
    or
    sudo apt-get install virtualbox-ose
  2. Add yourself to the correct groups
    sudo usermod -a -G disk,vboxusers -a `whoami`
  3. Restart X [ctl-alt-bksp]
  4. Create a Master Boot Record manager in a file.
    To do this you need to use install-mbr which is part of the debian package mbr and call install-mbr with the –force option.

    install-mbr --force myBootRecord.mbr

    This will create an empty boot record with a size of 512bytes

  5. Identify which partition your windows install is on
    fdisk -l /dev/sda

    You should get a result similar to

    Disk /dev/sda: 82.3 GB, 82348277760 bytes
    255 heads, 63 sectors/track, 10011 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Disk identifier: 0xf3c1f3c1
    Device Boot Start End Blocks Id System
    /dev/sda1 * 1 2623 21069216 7 HPFS/NTFS
    /dev/sda2 2624 9704 56878132+ 83 Linux
    /dev/sda3 9705 10011 2465977+ 5 Extended
    /dev/sda5 9705 10011 2465946 82 Linux swap / Solaris

    For me it shows my windows partition as number 1 (HPFS/NTFS)

  6. Now we need to build the volume
    VBoxManage internalcommands createrawvmdk -filename ./WinXP.vmdk -rawdisk /dev/sda -partitions 1 -mbr ./myBootRecord.mbr -relative

    Some instructions I have found say to include ‘–register’ but I have had issues with this so leave it off to register manually

  7. Now we need to set up the Windows Partition so now we boot back into windows
  8. In order to make windows usable independently its is recommended you set up different hardware profiles.
    • Click Start > Control Panel > System
    • On the Hardware tab, select Hardware Profiles
    • Click Copy, name the new hardware profile Physical
    • Rename the current profile to Virtual
  9. Change Windows XP’s IDE controller
    • On the Hardware tab, select Device Manager
    • Right-click the IDE Controller and click Update Driver
    • Click No,.. and Next
    • Click [Advanced] and Next
    • Click Don’t search… and Next
    • Select Standard Dual channel PCI IDE controller
    • Click Next, Finish, then Close and Reboot into Linux
  10. Reboot back into Linux
  11. Start VirtualBox
  12. Create a new Machine using the new machine wizard [new button]
  13. Enter a name for the machine and select the appropriate Windows OS type
  14. Choose reasonable memory size (advisable not to use more than a quarter of total memory unless using windows a lot)
  15. When prompted for the hard disk to use, select existing and point it at the new .vmdk file you created in step 6.
  16. From here on in you should be able to just follow the rest of the instructions and fingers crossed it all works smoothly.

N.B. You may be prompted to reactivate you copy of windows.

ubuntu, virtualbox

Dell – ightfully Tedious

Jan 29th

Posted by Matt Cockayne in Mess Hall

No comments

So on Monday I thought that it was about time I upgraded my PC. My current one from circa the millennium and to be honest is past being long in the tooth. Now there is nothing actually wrong with my PC for a 9 year old model, it does everything its supposed to (as long as I stick to Linux or XP, vista just kills it). The problem is that everything else I have bought since then doesn’t want to work with it.

The whole thing started at Christmas. The in laws bought us a very nice electronic version of Trivial pursuit. Lots of fun.. but we couldn’t access all the features as you needed to upload a catalogue of questions from the website to get it all running properly. After about 2 hours though I find out that I need to have USB2.0 as a minimum.

Now in the year 2000 my computer was pretty up to date just having USB never mind USB2. This is also where the story gets a bit repetetive as I now have a camera and 2 mobile phones and an MP3 player that all demand USB 2 in order to work.

Anyway, I gritted my teeth and told myself that its fine I can live with it…

Until I end up running out of hard disk space. A few years ago I did upgrade and put in a second drive to give me a then impressive 160Gb. I’m astonished that I managed to use it all. God knows where its all gone.

An the final straw that broke the camels back is my monitor. I am still working with a 17″ CRT. Its absolutly massive… It takes up so much of the desk that my nose almost touches the screen.

So after about 0.5 seconds consideration i popped over to dells website. Now all things considered (and the fact I’m skint) I decided to plump for one of the basic 530 range. I was astonished how cheap the damn things were. finally my eye settled on the one I was looking for. A quad core for £500. I was pleasantly surprised.

So i decided to sign on the dotted line. and take advantage of the “Buy now Pay later” finance… its only £500 and its better in my pocket than in theirs I thought. So this was on monday and I thought all was going fine.

By tuesday I began to get nervous waiting for some update as to the progress of my finance application and order.

By wednesday I was a bit miffed… didn’t they want my money. So this morning I rang them.

“We’re sorry … didn’t you get the email” NO i replied. “We need you to send in some documents to confirm your identity”. I couldn’t believe that it had taken a call from me to get the ball rolling. And the excuse of “the email must have gotten lost” is beginning to wear a bit thin nowadays. I can distinctly remember giving them no less that 3 telephone numbers that I could be contacted on during the application process.

This makes me wonder if I’m going to have to call them to remind them to build my PC and ship it. I will bet ny amount that they wont hhesitate for ne single second when it comes time to collect the money in 6 months time.

I’m all in favour of large companies. But they need to remember that its the little people that made them large in the first place and, that without a little customer service, we can make them quite small again.

I just hope the build quality of my PC isnt as disappointing as the service.

Dell, hardware, PC, Ramble
basic file structure for send framework application

Zend Lego

Jan 27th

Posted by Matt Cockayne in Spec Ops

No comments

basic file structure for send framework application

basic file structure for Zend Framework application

A good place to start with the building a web app os to use the outline that you are provided with on the Quickstart on Zends site.

I took that and modified it slightly to suit my needs better.

My basic file structure has a few more folders… Cache, Sessions and Test. I tend to put these into the root of my appication as they tend not to be application specific.

As you may have guessed from the names of the folders they are used by the components they are nemes after Zend_Cache, Zend_Session and Zend_Test. I’ll go into these another time.

So lets start with the public folder

This will contain all of the resources that we will make publicly accessible i.e. CSS, Javascript, Images, Flash, XML, etc. It will also provide the main point of entry for the entire application.

to make this work correctly we will need to set up a .htaccess file to allow access to existing resources and anything else gets piped through to the framework.

1
2
3
4
5
6
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]

This is pulled straight from the quickstart guide and has served me very well so far.

In my index.php file we actually instantiate the framework. I have “borrowed” this from the hello world example that gets shipped with Zends Studio for Eclipse.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
try {
    require '../application/bootstrap.php';
} catch (Exception $exception) {
    echo '<html><body><center>'
    . 'An exception occured while bootstrapping the application.';
    if (defined('APPLICATION_ENVIRONMENT')
      && APPLICATION_ENVIRONMENT != 'production' ) {
        echo '<br /><br />' . $exception->getMessage() . '<br />'
        . '<div align="left">Stack Trace:'
        . '<pre>' . $exception->getTraceAsString() . '</pre></div>';
    }
    echo '</center></body></html>';
    exit(1);
}
Zend_Controller_Front::getInstance()->dispatch();

You may think that this is a very short index file but thats exactly what its meant to be. you can see in the try that it is trying to pull through the bootstrap.php file this is to add an extra layer of security so should there be an issue server side the most that would ever be served up and readable would be what we have here.

The catch also allows us to quickly identify any issues found inside teh bootstrap file and gives us a complete trace without having to worry if the applications core exception handling has been activated (more on that later).

And finally we grab the instance of the Zend Controllers frontend and “dispatch” everything in one neat package. More >

Cache, Controller, Front, htaccess, Session, Test, Zend

Sgt Zend

Jan 26th

Posted by Matt Cockayne in Spec Ops

No comments

I’m a really big enthusiast for the Zend Framework. In my opinion its got to be one of the simplest yet most versatile framework that I have come across in all my time as a programmer. Rarely have I seen a framework where I can get a whole MVC style site up and running in less than 30 Min’s (a very very basic site mind).

So what can the framework do?

Well its most useful and what i would call primary function is to enable you to build MVC style web applications, and it does this with ease.

Among the other libraries there are quite a few that can be use both in conjunction with the framework or as a stand alone component. The most useful of
these i find if the Zend_Db. A fully featured database abstraction layer allowing connection to a wide variety of  data source such as DB2, MySQLi, Oracle and a fair few PDO connectors. Its a very clever piece of coding that allows standardised access to via a programmatic object orientated method.

Another of my personal favorites is the Zend_Form. It instantly takes the hassle out of writing forms by giving a php based method of generating a for dynamically. This coupled with the Zend_Config library give you a way to instantlybuild forms that are not embedded in HTML templates making it easy to manipulate them as you need. I’m woking on an interface that will hopfully give a point and click method of building forms and generating the appropriate config files that can then be fired straight into Zend_Form. If I ever manage to get around to finishing it I will post it here.

A couple of other components worth looking at are Zend_Auth and Zend_Acl , even though they are separate components I always tend to think of them in the same context. Mainly because I just thing its daft to create a secure loging with the Auth component and not include an ACL to manage the users. The Auth is extremely versatile, allowing you to connect to a number of diffferent platforms to validate your Authentication. I tend to use it mainly with a database connection through the Zend_Db connector, but it will connect justas easily with an LDAP or active directory as it will a hash file on the server.

The ACL is remarkably simple. usiing a very simple tree system for resources, roles and rights. It really is as simple as saying “Bob can read this page”. That said you can also make it extremely complex just by expanding out on it.

The framework also sports a very elegant caching system in the guise of Zend_Cache. With a large number of frontend and backend platforms available it can make light work of any site that may become a resource hog. This is a definate must for any web application that you build.

So thats my intro to the framework. If your interested in learning more I would strongly suggest heading over to the frameworks website (http://framework.zend.com) as it has an excellent reference guide that breaks down each and every conponent along with a very very concise quickstart guide that will tell you how to get a hello world example up and running in no time at all.

Acl, Auth, Cache, Config, Db, Form, Framework, Zend
«1234»
    • Recent comments
    • Popular posts
    • Archives
    • Tags
    • Categories
    • Barracks (2)
    • Mess Hall (4)
    • MIA (3)
    • Spec Ops (8)
    Acer Acl application Aspire Auth blog Cache client cms Config Controller database Db Dell embargo error expiry Form forum Framework Front gettext hardware htaccess Linpus locale Network newsletter One PC PHP plugin plugins Ramble registry sapphire Session silverstripe temlate Test translate ubuntu virtualbox xml Zend
    • July 2010 (1)
    • March 2010 (2)
    • November 2009 (2)
    • September 2009 (1)
    • June 2009 (2)
    • March 2009 (2)
    • February 2009 (2)
    • January 2009 (4)
    • Zend + TinyMCE (17)
    • Zend In- Doctrine -ation (3)
    • Basic Training (2)
    • Getting squeakly clean with Zend_Soap (2)
    • To Gwibber or not to Gwibber (2)
    • Sgt Zend (0)
    • Zend Lego (0)
    • Dell – ightfully Tedious (0)
    • Zend Lego – Initialise, Part 1 (0)
    • Virtually Possible in a Box (0)
    • Matt Cockayne: that makes me much happier than messing around in couch.. thanks for the info... Gwibber is now...
    • Ryan Paul: When you click an item in the sidebar, you can close it by selecting "Close Stream" from the...
    • matt.cockayne: Hi Jeremy. Yes I had to create my 0own task to allow table generation. The reason for this was...
    • Jeremy Hicks: I failed to mention that the latest 1.2 download of Doctrine includes a vendor folder with sfYaml...
    • Jeremy Hicks: Great post! I've been reading all the same articles that it looks like you've already been through....
    • krishna: I am just new to zend framework ,I want to know what are file to be created and where it is to be...
    • krishna: what should be the file name and getter and setter method and folder structure
    • matt.cockayne: Not quite... my problems were occuring because a .NET client was trying to consume a service...
  • Find Something

  • My latest tweets

    Loading tweets...
    Follow me on Twitter!
  • User Login






    • Register
    • Lost your password?
  • phpnw09 PHP Conference 10/10/2009
Cloud Computing & Cloud Hosting by Rackspace

Mystique theme by digitalnature | Powered by WordPress
RSS Feeds XHTML 1.1 Top