Working on Sencha Command for Sencha Touch
0Since 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)
0I’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.
Become a quality assurance expert in just two days.
0This 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
2This 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
0A 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;
-
<?php /** * Config */
-
-
-
$translationsPath = ‘../translations’;
-
-
/** * Do not change */
-
-
-
$translateItem = $argv[1];
-
foreach (new DirectoryIterator($translationsPath) as $fileInfo) {
-
if($fileInfo->isDot()) continue;
-
$fileLocation = $fileInfo->getPathname();
-
$fileContent = file_get_contents($fileLocation); $newContent = str_replace(‘);’," ’".$translateItem."’ => ‘".$translateItem."’,\n);",$fileContent); file_put_contents($fileLocation, $newContent);
-
}
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
0As 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:
-
<?php
-
class Application_Model_Users extends Zend_Db_Table {
-
protected $_name = ‘users’;
-
-
public function fetchCollection(){
-
$rowset = $this->fetchAll();
-
foreach ($rowset as $row) {
-
‘basic’ => $row,
-
‘images’ => $row->findDependentRowset(‘Application_Model_Images’)
-
);
-
}
-
return $fullItems;
-
}
-
}
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:
-
<?php
-
class Application_Model_Images extends Zend_Db_Table {
-
protected $_name = ‘userImages’;
-
‘columns’ => ‘userId’,
-
‘refTableClass’ => ‘Application_Model_Users’,
-
‘refTableColumns’ => ‘id’
-
)
-
);
-
}
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:
-
class IndexController extends Zend_Controller_Action
-
{
-
-
public function indexAction()
-
{
-
$userModel = new Application_Model_Users();
-
$userCollection = $userModel->fetchCollection();
-
$this->view->users = $userCollection;
-
}
-
-
}
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:
-
<?php foreach ($this->users as $user): ?>
-
<?php foreach ($user[‘images’] as $image): ?>
-
<img src="<?php echo $image->filename ?>">
-
<?php endforeach; ?>
-
<?php endif; ?>
-
<?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
1In 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:
-
<?php
-
class Application_Model_Page extends Zend_Db_Table
-
{
-
protected $_name = ‘pages’;
-
-
}
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:
-
<?php
-
$pageObject = new Application_Model_page;
-
$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.
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.
-
$pageObject->info(); // Returns the information collected by Zend Framework about your table
-
$pageObject->setOptions($optionsArray); // Changes the options returned by the info method
-
$pageObject->insert($dataArray); // Adds the column – value pairs as a new record
-
$pageObject->update($dataArray, $whereString); // Updates the rows found by the where-string with column value pairs
-
$pageObject->fetchRow($query); // Returns a single row from a query or Zend_Db_Select object
-
$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
4Most 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
0I 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.
- Login to your server using SSH
- cd to your web root directory (e.g. cd /var/www/mydomain.com/http-docs/)
- Type: wget http://wordpress.org/latest.tar.gz
- Type: tar xvf latest.tar.gz
- Optionally: mv wordpress/* my_desired_directory/
- ls -las and take note of the owner of the . file
- chown -R username:groupname my_desired_directory/ take note that the username and groupname should be the name you saw in step 6
- Setup a MySQL database with it’s own user and pass (make sure that the user is able manage tables in the database)
- 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!