Setup ZF using svn externals

After you create a project with zf tool, put it on SVN, you might want to include inside /library the ZF, but you want to have the bleeding edge all the time. You can include it as a svn external like this:

cd library/
svn propset svn:externals 'Zend' . 

Next time when you run svn up, your project will fetch the latest ZF from it’s repo.

Setup controllers and actions inside a module using zf tool

I’ve been trying to move some old code into separate modules for easier use later on. I installed zend framework and zend tool and created a new project:

zf create project myproject

Adding a new module is easy as pie:

zf create module mymodule

This creates the /application/modules/mymodule folder with complete MVC structure inside (controllers, models and views folders).

My module was not working so after a bit of looking around i’ve found Akrabat’s post that some light on the subject. You have to add to /application/configs.ini the following inside the [production] section:

# enabling modules
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = ""

Good, now we should have a working module, except we don’t have any controllers. Trying to create a controller proved a bit tricky as zf tool would not pleace them in the right place, inside the modules/mymodule/controllers but in the default /application/controllers. The same applies for actions. With a bit of help from TheAshMan on #zftalk i found the right answer:

# create controller Photos_IndexController at /application/modules/controllers/Photos_IndexController.php
zf create controller Photos_Index 1 mymodule
# create the action view inside the Photos_IndexController
zf create action view Photos_Index 1 mymodule

Hope this helps someone as it took me a few hours to figure it out 🙂

How to update your Twitter status using Zend Framework

After reading the NetTuts tutorial on how to update your Twitter status using CodeIgniter, I wanted to show how to update your Twitter status using Zend Framework.

For this tutorial you need to install Zend Framework and Zend_Tool first.

Step 1: setup apache vhost by creating the /etc/apache2/sites-available/twitter as follows:

    ServerAdmin [email protected]
    DocumentRoot /home/mimir/Zend/workspaces/DefaultWorkspace7/twitter
    ErrorLog /home/mimir/Zend/workspaces/DefaultWorkspace7/logs/twitter_error_log
    CustomLog /home/mimir/Zend/workspaces/DefaultWorkspace7/logs/twitter_access_log combined

Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all

You will need to change the DocumentRoot and Directory directives to match your configuration.

Step 2: add to your hosts file:

Step 3: create the Zend Framework project

# i switch to my Zend Studio workspace, where apache is reading his sites from:
# cd Zend/workspaces/DefaultWorkspace7/
zf create project twitter

Step 4: restart apache

sudo /etc/init.d/apache2 restart

At this point you should have a default Zend Framework project that you can browse at How let’s change our status 🙂

Replace the content of IndexController with the following:

setLabel('New Twitter Status')

        $submit = new Zend_Form_Element_Submit('submit');

        $updateForm->addElements(array($status, $submit));

        // we send the form to the view
        $this->view->updateForm = $updateForm;

        // we check if there was any POST
        if ($this->getRequest()->isPost()){
            $formData = $this->_request->getPost();
            // checking if the form data is valid (if we have a new status or not)
            if ($this->view->updateForm->isValid($formData)){
                // our form is valid, we can update our status
                $twitterStatus = $formData['status'];

                $twitter = new Zend_Service_Twitter('myusername', 'mypassword');
                $response = $twitter->status->update($twitterStatus);



Also replace the view for the index action of IndexController with:

Welcome to the Twitter Update Tutorial


TADA! You can now check your twitter account and see that twitter status is updated every time you submit the form -:)

Install Zend Framework and Zend_Tool using PEAR on Ubuntu

I work every day with Zend Framework and the easiest way i find to install it is by using the PEAR packages offered by the betta channel ZF Campus

Here is what you have to do install Zend Framework and Zend_Tool using PEAR on Ubuntu:

sudo pear channel-discover
sudo pear install zfcampus/zf
# for some reason the installer does not correctly link the zf.php and Zend_Tool won't work
# so we need to setup a symlink
sudo ln -s /usr/share/php/zf.php /usr/bin/zf.php

That’s it! You can now test your install:

zf show version

In my care the output was this one:

[email protected]:~$ zf show version
Zend Framework Version: 1.9.2

Magento export categories with id

A friend asked me to help out import some products and categories from an old database to a brand new magento install. What I first did was to construct a CSV file with all the categories from the old store (that was the easy part…) and import them to magento. I followed this thread and the import when smooth. Now I needed to get the ids that magento addigned to my categories so that I could import a product inside the categories so that my friend won’t have to do it in backend.

First thing I did was to look on magento forums how to get all store categories. After finding this great thread, i came up with this little script which I put into my template folder in /catalog/allcategories.phtml:

$category = Mage::getModel ( 'catalog/category' );
$tree = $category->getTreeModel ();
$tree->load ();

$ids = $tree->getCollection ()->getAllIds ();

if ($ids) {
$fp = fopen('var/import/catwithid.csv', 'a');
fwrite($fp,  'catId, catName\n');
foreach ( $ids as $id ) {
                $string = $id . ', ' .$category->load($id)->getName() . '\n';
fwrite($fp,  $string);

As a note, you need to make sure that /var/import/catwithid.csv exists and it’s writeable by your web server. You can make sure it is by chmod-ing it to 777

touch var/import/catwithid.csv # we create the file
chmod 777 var/import/catwithid.csv #make sure it's writeable

Since this was a dev install, I then just loaded that script into a block element by editing the Home Page inside the CMS section:

{{block type="core/template" template="catalog/allcategories.phtml"}}

Hope this helps someone 🙂

Made the switch to wordpress

I’ve been using MovableType as the platform for my blog and i’ve been really happy with it. The reason i decided to switch to WordPress is simply because it’s written using PHP and i’m able to easily extend it, unlike MT which is built in perl.
I haven’t got a change to import the comments so far, but hopefully i’ll get to that this week.

Let me know if you find a broken link or something unusual.

Zend Framework tutorials – RFC

After a talk on #zftalk I’m thinking to start witting a site that would allow the Zend Framework community to submit learning material.

The site is going to be called Zend Framework Tips

I have a few ideas of my own, but i want to hear more from you.

Continue reading “Zend Framework tutorials – RFC”

Eclipse plugins written in PHP?

On another Eclipse related news, i have noticed today the GSOC 2009 ideas for eclipse. Although all the ideas are interesting, what catched my view was “Write Eclipse plug-ins in PHP
” through e4.

e4 is the community effort for building the next generation of the Eclipse Platform. The project has three principle aims:

  • Simplify the Eclipse programming model: This will
    reduce development and maintenance costs and enable a larger developer
    community to leverage the platform in their own Eclipse-based
  • Enable the platform for use on emerging web-based runtime technologies:
    This will ensure the platform remains a compelling and viable
    application framework in a rapidly changing web technology landscape,
    and it will allow e4-based applications to leverage web technologies,
    while remaining insulated from specific technology choices that may
    quickly become obsolete.
  • Broaden participation in development of the platform:
    This reduces the risks associated with building on a platform largely
    funded from a single source. Having a large and diverse group of
    commercial backers, will ensure the platform remains vibrant and viable
    over the long term.

Please refer to the project proposal for more information, including the initial list of committers. The e4 project summary page is here.

I’m really interested to see what comes out of that.