Working on Sencha Command for Sencha Touch

0

Since some time I’m working with Sencha Touch (ST) to create mobile projects. One of the hard parts of learning the MVC structure for ST is setting up the correct file and directory hierarchy.

Sencha Touch does contain a very cool tool to do this quick and clean, it is called Sencha Command. When I started playing with it I came across a few errors which made it almost impossible to decently work with it, but as a developer I’m not to lazy to get my hands dirty on some code.
I started my search on Github where I came across the master by Muc at https://github.com/muc/sencha-command I immediately forked it and started playing. This version of Sencha Command seemed to be quite clean and workable. The only thing that was still missing in creating the application skeletons was a folder for the stores part of the MVC framework. So I started working on my own fork and fixed this is my pull request. If you want the latest and greatest you can grab it from my own Github account https://github.com/Martin1982/sencha-command

Next stop will be the build command which isn’t quite working out for me as well. Don’t know when I will find time again for it though. If you’re looking for more Sencha Touch MVC resources I’d recommend watching this video:

SenchaCon 2010: Structuring Your Sencha Touch Application from Sencha on Vimeo.

Dutch PHP Conference 2011 (a.k.a. DPC 2011)

0

I’m already fully preparing my talk for the Dutch PHP Conference 2011, this time it is not directly quality related. This time we will learn how to take over the world with Zend Framework. Well probably the title is a bit over-done, but I like to do that. I’m going to try to squeeze into 45 minutes what Zend_Locale is and which other components are affected by using it. We will look at an example and at the moment I’m hacking away on some treats to even extend the functionality beyond it’s limits. All by using PHP and Zend Framework.

Although I’m not a Zend Framework guru like Rob Allen or Matthew Weier O’Phinney, I became a pretty heavy user of the package. Especially people who haven’t had the chance to look internationalization will catch up quite a few great tricks to finally make problems like translation and currencies (which are very common in multinational’s sites or webshops) a thing of the past.
Even if you have never used Zend Framework my session will get you up to speed quite fast. I’m now working on a demo project which I will put on Github after the DPC.

PHPBenelux Conference 2011 – The day after

1

This weekend was the PHPBenelux Conference 2011, and if you don’t like reading the complete article, the conclusion is; it was awesome! Everyone made it happen, the visitors, the sponsors, the speakers, my fellow crew members and the hotel staff. The whole chemistry of all of these factors together made it a really cool event.

It all started Thursday, as part of the crew I was there quite early, after doing a few pickups and going through some final checks we were ready to start the speakers dinner. The dinner was really good, and we had some great laughs with Derick Rethans, Elizabeth Naramore, Tobias Gies, Paul Jones, Nick Belhomme, Scott McVicar and John Mertic. I would’ve loved to stop by everyone, but duty called, so we still had to fill the goody bags with all the goodies that came in that day.
After we were done it was time for a few more drinks and some sleep before the big day would start.

The next morning was conference day (day 1); ofcourse I almost overslept, but being 15 minutes late at breakfast wasn’t too much of a problem since I just wanted the coffee. We picked up the goodie bags, set up the whole registration table, placed some signs around the venue, and the first few visitors already came in. It took us about 5 minutes (and 5 visitors) to get the registration process running smoothly which is actually quite nice. People didn’t have to wait in the queue for very long with 5 people behind the desk and having setup a system where people queued by the first letter of their last name.

After the intial registrations I took some quality time to look at Paul Borgermans session about Solr. Solr is totally new to me and I just wanted to pickup what I could. And I must say I’m impressed with what Paul achieved during those 3 hours. He really started of with some basics which I did understand and will get me started, but quickly after that he added great value for current Solr users.

After the session me and Iwan Luijks managed the tutorial dinner and guided the conference-only people still looking for a lunch to the Hotel’s bistro. The vibe was great, people understood that the restaurant couldn’t ever handle 250 people and weren’t awkward about it.

During the keynote I only watched the opening and then returned to the registration desk to make myself useful again. We were amazed by the amount of people that already came in on a Friday. Hats off to all the managers who sent their employees to the conference already.
After the opening keynote I attended and managed the room for Stephan Hochdörfer with the “Testing untestable code” session. The session itself was short, but it had everything so it was great at the same time. Stephan explained some really dirty (but necessary) methods to use when you get legacy code and need to test it. The presentation ended with a note that you should always write testable code yourself which I totally agree with. During the next 2 sessions I have been working at the registration desk again, as a member of the crew I also wanted the other crew members to be relieved from their duties to watch some of the sessions.
After closing the registration desk just 20 badges remained which could still be picked up on saturday, so we were very pleased with the number of people already showing up. I attended the closing keynote by Michelangelo van Dam, Maarten Balliauw and Katrien de Graeve about Microsoft’s new Azure cloud computing. And although most PHP developers dislike Windows, I’m still convinced that Microsoft is heading the right way with what they are doing. They still need to gain a lot of trust but they are open to the PHP community, so let’s give them a chance to show this.

The first conference day ended with a bowling and social event which was really a blast. And while the drink vouchers by Github were a great idea I got into that flow again where I would drink one or 2 beers too much resulting in a small headache the other morning. I had great talks with many people though and especially had some real fun seeing Tobias Schlitt and Iwan Luijks discussing the Windows subject with great passion for their views. At 03:00 the three of us got really hungry so we asked at the hotel reception if there was a possibility to order kebab. And tadaaa; the friendly lady gave us a menu and offered us to call for a delivery. All I can say; very tasty stuff but the quantity was way too much!

On the second day getting up worked a bit better despite the slight headache. I again helped at the registration desk during the first session and almost all badges were given out during this time.
The first session of this day for me was by Joshua Thijssen about Sed and Awk. Being a former collegue of Joshua, I loved to see how he would premiere on a conference. He really amazed me with his talk, showing a lot of great finding and replacing stuff using these tools. And he teached us how to make Sed p(ee), which was actually quite funny.

During the break I setup my own laptop getting ready for my own session. At first I was starting to feel a bit sick, probably some kind of stage illness. But when I started off thing were rolling quite well. The audience were great listeners and asked some really good questions. 2 people in the room seemed to know the subject quite good as well, and although it scared me at first and made me a bit unsure, I really liked the fact that we were actually collaborating in a good way for the whole crowd. So many thanks to Mike van Riel and Jeremy Coates for that! After my session I had a little chat with some people who had some personal CI questions and gave out some images of a demo environment. My complete talk is already available on slideshare (it was even featured on the homepage wooohooo!). I also need to thank Harrie Verveer and Felix DeVliegher who coached me while creating the session, got some really good tips while preparing! Below you can see the slides of my talk:

After having a cheese pistolet for lunch it was my turn to be the room manager for track 2 and learned quite some good stuff about CouchDB by Sander van de Graaf. It was a complete new view after seeing Kore Nordmann’s presentation on the subject twice and it really gave some good new insights. After Sander I saw Stephan Hochdörfer’s talk about multitenant web applications which was also a joy to see.

During the break we got the main stage ready to thank our speakers and got Elizabeth all set up to do her closing keynote. It was very cute how she compared the community with the baking process of chocolate chip cookies and we had many great laughs. I love her way of getting a crowd’s attention!

We closed the conference with some raffle’s and thanked the speakers with a Belgium beer package and some Belgium chocolate which I hope they’ll enjoy. After cleaning up we aligned some drivers and went into Antwerp with the remaining speakers to have a pizza. After dinner me and some others were getting tired after 2 great but intense days so we returned to the hotel to have a few more drinks (I was drinking coke, had enough of the beer stuff the evening before, and I’m a nice driver you can ask Lorna Jane Mitchell she was quite fond of my driving to Antwerp and back).
Around 11:00pm I decided that it was time to head home to catch up on sleeping, 2 days with just 5 hours of sleep in total had really hit me by then.

And here I am blogging about something we could’ve never imagined to work out this well. We are really flattered with all the good comments we got already and I am already looking forward to see everyone again in 2012!

Become a quality assurance expert in just two days.

0

This post will be just a shameless plug to get you to my session at the PHPBenelux Conference 2011. But while browsing the schedule I mentioned there were quite some talks related to quality assurance. If you follow this path you will know many of the qa-drills required to become an expert in the field.

Ofcourse you’d have to practice what we preach!

Friday January 28, 2011
09:00 – 12:30 Workshop Real world Quality Assurance, unit testing, code review Tobias Schlitt and Kore Nordmann
14:10 – 15:10 Testing untestable code Stephan Hochdörfer
15:40 – 16:40 Making software management tools work for you John Mertic
15:40 – 16:40 Technical debt Elizabeth Naramore
Saturday January 29
09:00 – 10:00 Benchmarking applications and frameworks Paul Jones
11:40 – 12:40 Improving code quality with continuous Integration Martin de Keijzer
14:50 – 15:50 Project triage & recovery Keith Casey

Once you’ve seen al these sessions, get your notes out, lock yourself in a room for a month and apply this knowledge to your current projects. After you leave the room, you’d probably first shave, then go to work and apply these to one of the larger projects in your company. After the project has became more profitable you can step up to your boss and go get that raise!

Speaking at the PHPBenelux Conference 2011

2

This year will start out with a bang, not only am I fortunate enough to help organizing the PHPBenelux conference, I will also fill up one of the slots with my talk on continuous integration. The talk originates as a quick unconference fillup which was created in 15 minutes during the Dutch PHP Conference, there the talk was well accepted and even gave me an assured spot for the 2011 edition.

A few months later I worked out the talk some more into what it actually should be and presented it at one of the user group meetings. Again there were almost no questions and everyone said it was pretty clear. You might ask yourself, how can you improve on that? Well I did some major continuous integration on my own talk. It already contained the basics, the common tools for a PHP environment, a single environment (CruiseControl + phpUnderControl).

So this time we’ll add a second environment (Hudson), there’s still time for that. The screenshots will be even more clear, so you won’t need to do much guessing on how to start when you finally do. And last but not least I can add a whole lot of real life experience tips as I have been growing into the subject more and more.

Why should you come and see my talk? If you haven’t heard of continuous integration you’ll get to know the matter. You will see how it will affect your development lifecycle to deliver more stable and changeable code. And how you can be assured that your changes won’t break other parts of your application. We also look into complexity of code, because we like to keep it simple, duplicate code, or very complex routines don’t help anyone.

So in the end I want you to leave the room with a feeling that you can finally keep control of that monstrous project that always bites you in the back when new customer requirements reach your desk.

Hope to see you all in Antwerp, if you haven’t bought your ticket yet you can do so in the shop

Quickly adding terms to a Zend_Translate array

0

A little while ago I ran into a task that was pretty repetitive, so I quickly coded a small solution which I’d like to share with you all.

I was working on making a site multilingual using Zend_Translate with the array adapter, I created my translation files with the returning array in the translations folder.

Now putting in all the translation terms and putting these in all the array variables for each language was pretty dull and time consuming. I wanted to have a tool which I could run from command line so I came up with the following;

  1. <?php /**  * Config  */
  2.  
  3.  
  4. $translationsPath = ‘../translations’;
  5.  
  6. /**  * Do not change  */
  7.  
  8. if($argc < 2) exit("Translation item missing,\nUsage: ./add-translation \"My new term\"\n");
  9.  
  10. $translateItem = $argv[1];    
  11. foreach (new DirectoryIterator($translationsPath) as $fileInfo) {    
  12. if($fileInfo->isDot()) continue;    
  13. $fileLocation = $fileInfo->getPathname();    
  14. $fileContent = file_get_contents($fileLocation); $newContent = str_replace(‘);’,"    ’".$translateItem."’ => ‘".$translateItem."’,\n);",$fileContent); file_put_contents($fileLocation, $newContent);
  15. }

Now I can just call ./add-translation “welcome to my site” from the command line to get the new translations into each language file with a default value.

Hope this helps in your daily tasks, any comments are appreciated.

This article has been taken from my old blog, so it could look familiar. I’m closing down the old one and transfer the most interesting articles.

Defining relations in Zend_Db_Table

0

As promised in my previous post I will revisit the Zend_Db_Table for defining relations. Now boys and girls, I have been busy, but I found some time to get my hands dirty.

Let’s say we have a Zend Framework application which is nothing more than an image wall for multiple users. We setup our table models as posted in previously mentioned post. And we come across a problem we’d like to address;
We have 1 user and we want to show multiple images for this user. Here is how I solved this;

I have 2 models which both extend the Zend_Db_Table class. One for the users called Application_Model_Users and one for the images called Application_Model_Images. I want to show all users and all their images (for the sake of example ofcourse! Once your application hits a billion users you’ll regret this decision). So I create a public method for this purpose called getCollection which should do the job for me.

Now here is where you should ask yourself the first question “I have my basic object, what is attached to it? What is the model name of this attachment?”. In our example the answer would be Application_Model_Images. And we can magically build our User class:

  1. <?php
  2. class Application_Model_Users extends Zend_Db_Table {
  3.         protected $_name = ‘users’;
  4.        
  5.     public function fetchCollection(){
  6.         $rowset = $this->fetchAll();
  7.         $fullItem = array();
  8.         foreach ($rowset as $row) {
  9.            $fullItems[] = array(
  10.                 ‘basic’ => $row,
  11.                 ‘images’ => $row->findDependentRowset(‘Application_Model_Images’)
  12.            );
  13.         }
  14.         return $fullItems;
  15.     }
  16. }

What happens in the method is that we retrieve all rows (all users) and loop through them. We create a new array with the user properties called basic (the user information a Zend_Db_Table_Row) and images (another Zend_Db_Table_Rowset with all images).

Was that all you might ask yourself. Well the simple answer is; NO, KEEP ON READING. The Application_Model_Images needs to be aware that an object will be requesting data from it. This is where the property $_referenceMap kicks in.
The reference map contains an array of references. Each reference has a human readable key and should define the following items in it’s array:

  • columns: The name of the column from this class you’ll be referencing by (userId)
  • refTableClass: The class name of the basic object (the user class in this case)
  • refTableColumns: The name of the column from the foreign class (id from the user class / table) you’ll be using

Which makes the class look like below:

  1. <?php
  2. class Application_Model_Images extends Zend_Db_Table {
  3.         protected $_name = ‘userImages’;
  4.         protected $_referenceMap = array(
  5.            ‘userPhotos’ => array(
  6.                ‘columns’ => ‘userId’,
  7.                ‘refTableClass’ => ‘Application_Model_Users’,
  8.                ‘refTableColumns’ => ‘id’
  9.            )
  10.         );
  11. }

Ok now you’re ready to call this wonderpiece. I’ll explain using a view and controller, but any piece of PHP code should be able to gather this information.

Controller:

  1. class IndexController extends Zend_Controller_Action
  2. {
  3.  
  4.     public function indexAction()
  5.     {
  6.         $userModel = new Application_Model_Users();
  7.         $userCollection = $userModel->fetchCollection();
  8.         $this->view->users = $userCollection;
  9.     }
  10.  
  11. }

This action loads our user mode, calls the self defined method to retrieve all users including all their images and assigns it to the view. Which will be the final piece of the puzzle;

View:

  1. <?php foreach ($this->users as $user): ?>
  2.     Name: <?php echo $user[‘basic’]->name ?><br>
  3.     <?php if(count($user[‘images’])): ?>
  4.         <?php foreach ($user[‘images’] as $image): ?>
  5.             <img src="<?php echo $image->filename ?>">
  6.         <?php endforeach; ?>
  7.     <?php endif; ?>
  8. <?php endforeach; ?>

Now this is the way I solved a similar problem. But this probably isn’t the best way, this is where you kick in; read, learn and improve. As soon as you have a better solution please think about me just once, and share the knowledge in the comments. Just like I shared this knowledge with you.

I’ll keep the post updated.

The power of Zend_Db_Table

1

In the past I have just used Zend_Db as an interface between my database and code for making an executing queries. But as I moved deeper into the matter I have discovered that Zend_Db has a lot more to offer. It can work on several parts of your table by utilizing ony the table name.

Let’s say we have our connection all setup in our Zend_Config object and we now want to start talking to our database. We will create a class that extends from Zend_Db_Table for each table we have in our database like this:

  1. <?php
  2. class Application_Model_Page extends Zend_Db_Table
  3. {
  4.     protected $_name = ‘pages’;
  5.    
  6. }

Now from our code we can instantiate this class and could do all kinds of basic things we usually rewrite every time again. For instance getting a page by it’s primary key:

  1. <?php
  2. $pageObject = new Application_Model_page;
  3. $page = $pageObject->find(1321);

This gives us a page with the Id 1321 and we can access all properties of the page as we would with a normal object.

  1. echo $page->title; // shows the title of the page

As you can see we have reduced code we have to write ourselves to a great level. Zend_Db_Table offers other great methods which we can also use to our advantage.

  1. $pageObject->info(); // Returns the information collected by Zend Framework about your table
  2. $pageObject->setOptions($optionsArray); // Changes the options returned by the info method
  3. $pageObject->insert($dataArray); // Adds the column – value pairs as a new record
  4. $pageObject->update($dataArray, $whereString); // Updates the rows found by the where-string with column value pairs
  5. $pageObject->fetchRow($query); // Returns a single row from a query or Zend_Db_Select object
  6. $pageObject->fetchAll($query); // Returns a resultset from a query or Zend_Db_Select object

At the moment I’m still figuring out how I want to use relations but you can expect a blog post on that soon!

Deploying a Zend Framework application using git to a Plesk server

4

Most of you will tell me I’m insane that I am still running the plesk server, but actually I’m still quite happy with it. With common Linux knowledge it’s all really maintainable while having the easy interface to get things done.

Today the time had come to make a first test release of a Zend Framework application on my production server.
So here’s what I did;

  • Login to the server using SSH
  • Move to the domain directory where the httpdocs folder for my project resides
  • Moved the current directory for safe keeping; mv httpdocs httpdocs_backup
  • Made a clone of my repository contents; git clone /my/git/repository destination
  • Created a symbolic link for httpdocs: ln -s destination/public httpdocs
  • Gave Plesk the rights to access the httpdocs; chown -h username:psaserv httpdocs
    If you don’t know the username check it using ls -las
  • Gave Plesk the rights to access the public folder of my application: chown -R username:psaserv release-001/public

And that’s it, deployment succeeded.
Always keep in mind to setup your application.ini with the correct settings, but this is not different from a normal deployment.

Installing WordPress from the shell

0

I just setup WordPress in a few minutes, and for all of you who are still struggling I decided I’d write a quick post how I managed to do this. As a disclaimer I must say I didn’t read anything about WordPress so probably this is already covered a million times.

  1. Login to your server using SSH
  2. cd to your web root directory (e.g. cd /var/www/mydomain.com/http-docs/)
  3. Type: wget http://wordpress.org/latest.tar.gz
  4. Type: tar xvf latest.tar.gz
  5. Optionally: mv wordpress/* my_desired_directory/
  6. ls -las and take note of the owner of the . file
  7. chown -R username:groupname my_desired_directory/ take note that the username and groupname should be the name you saw in step 6
  8. Setup a MySQL database with it’s own user and pass (make sure that the user is able manage tables in the database)
  9. Point your browser to http://mydomain.com/my_desired_directory/ and WordPress will take it over from there

As you can see; in less than 10 steps you can easily setup WordPress, all in all it took me longer to write this small blogpost than the setup itself and I only did the setup twice in my life. So please give the WordPress crew and community a big applause for keeping things simple!

Go to Top