Digital Base – Blog » development

What is important in a PHP editor/IDE ?

Posted by Gijs Nelissen in Programming

I’ve been building websites for a while now. So i could say i am quite experienced although my (programming) knowledge is limited mainly focussed on building php applications. As a developer time is expensive, that’s why i am always looking for ways to speed up the web development process. A good start for fast & secure development is to have the right tools and the right feeling/connection with your editor.

On day-to-day basis i could say 80% of the time i have an open editor somewhere. Based on the amount of time you are “working together” with this piece of software, you could compare it to a marriage (although you shouldn’t trade wives as soon as you meet a younger, smarter and more beautiful girl).

I have a few expectations / requirements for a modern, good working editor

Decent Code Completion / Code Assistance

We all know word completion : auto completion involves the program predicting a word or sentence without the user actually having to type it in completely. This feature is used alot in text messaging (sms), email clients, browsers, search engines etc…

google_image_autocomplete

Autocompletion speeds up the entire process of typing a message, entering an address or, in our case, writing PHP code.

A decent source code editor analyses your source and suggests the function based on the first characters of the variable, function name or object. Most editors these days have code completion although they come in many flavours.

eclipse autocomplete

Larger web applications tend to use alot of classes & files. That’s what it is really important your autocompletion allows you to use an unlimited depth of super- & sub classes (inheritance). For this your IDE should have a decent understanding of the relation between classes. If in some case the code completion does not work for a certain object, you should be able to tell the editor which class your object belongs to, so it will allow you to use the code completion on next occurences of the same object/variable.

Code Documentation / PHPDoc

Another important aspect of code completion is documentation. It is very useful for a programmer to get as much visible feedback as possible about the method/function he is calling. For a php core function this should be a short summary what the function does, for custom methods/functions this would be the description as entered by the one that created the class/method.

eclipse_link

Next to that information it could be useful to show the return type and perhaps some information about the needed arguments. All these things should be integrated in the IDE, readily available when i enter the name of a method/class without opening a seperate manual or the php.net website.

When adding custom classes/methods/functions it is important that you document this code using phpdoc. Eclipse will then pick up this documentation and show it whenever you are using it somewhere else throughout your project.

Syntax Highlighting / Coloring

Code should look good. If you’re spending most of your time looking at code, it’s important to take care of your eyes. A good syntax highlighter highlights the different code to make a clear distinction between actual code, variables & documentation. Marking different type of elements in seperate colors will increase readability and help you understand a function faster.

Syntax highlighting also helps in finding errors in your code. Some editors mark incorrect code (missing delimiter, etc), this comes in handy when you are paying less attention. The editor will immediately show you you are doing something wrong…

Personally i prefer dark editors, many other programmers agree that this is alot better for your eyes. Next to that i find dark color schemes to be alot clearer and more beautiful to look at. TO give you an idea, this is what my eclipse looks like :

screenshot1

Code Bookmarks

When we are writing code it is important to keep track of important locations throughout the project. Code Bookmarks is the easiest way to do it.

A good implementation of bookmarks should allow you to easily switch to next/previous bookmark and give you an overview/listing of the current “bookmarks”.

screenshot3

If you look on the left side, you will see a small flag that marks the current line as being bookmarked.

screenshot7

Once you have these “code bookmarks”, its hard to code without them.

Smart/Quick opening

Now where did i put this code/file again ? Which class defines the foo() method ? Most of you will agree with me that opening the correct resource/file/method takes alot of time. A good editor should allow you to find/open everything you are looking for with a few keystrokes and (more important) without touching your mouse.

My favourite editor (Eclipse) allows you to use ctrl+shift+R to “open resource” and quickly find the file you were looking for.

screenshot8

This means i do not need to touch my mouse or open the “file explorer” to look for the file. Easy & Fast…

I know some people who use “grep -r ‘ methodname()’ to find the location of a method. I personally think this stinks. A good editor should contains some ways to easily open a file/method.

Class Outline

It’s easy to lose track of the variables/methods that are defined in a class. This is where the “outline view” comes in handy. This “outline” view will give you a the overview of every method/variable defined.

screenshot9

Double clicking a method will take you to this method. No search, no scrolling, no touching the mouse. In eclipse there is an even better way. Once inside a class you can use CTRL+O to get a quick outline with autocomplete functionality, finding the method you were looking for never was this easy…

eclipse quick outline

Thanks Eclipse :)

Platform Independance

If you are a regular reader of this blog, you will know we are using several linux flavours in our office. So for us it is very important t he same editor can be used on Windows & Linux platforms. Most “multi-platform” ide’s are based on java (zend, eclipse,…) but there are some other ide’s that have clients for both platforms.

How to unsecure admin generated modules in Symfony

You gotta love the admin generator… There’s only one problem: it’s secured by default (according to the symfony site).
But I want to use these modules in a non-secured environment.
Adding credentials: [] in the admin generator does not work… Why?
Look at your automoduleactions. You’ll find a preExecute function:

  public function preExecute()
  {
    $this->configuration = new eventGeneratorConfiguration();
 
    if (!$this->getUser()->hasCredential($this->configuration->getCredentials($this->getActionName())))
    {
      $this->forward(sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action'));
    }
 
    $this->dispatcher->notify(new sfEvent($this, 'admin.pre_execute', array('configuration' => $this->configuration)));
 
    $this->helper = new eventGeneratorHelper();
  }

This code is always executed before any action.

if (!$this->getUser()->hasCredential($this->configuration->getCredentials($this->getActionName())))

the getCredentials function:

  public function getCredentials($action)
  {
    if (0 === strpos($action, '_'))
    {
      $action = substr($action, 1);
    }
 
    return isset($this->configuration['credentials'][$action]) ? $this->configuration['credentials'][$action] : array();
  }
}

The problem is that hasCredential(array()) returns false.
My solution:
Override the hasCredential function in myUser

  public function hasCredential($credential, $useAnd = true)
  {
    //for usage in generator => + as credential will return hasCredential=true (even if user has no credentials at all)
    if($credential === true) return true;
    //btw => you could have checked for an empty array of credentials which is what the generator is returning
    return parent::hasCredential($credential, $useAnd);
  }

Now to make it work, put in generator.yml

  config:
     actions:
        _delete:        { credentials: admin }
        _list:            { credentials: + }
        index:           { credentials: + }
#        _new:         { credentials: + }
#        _edit:         { credentials: + }

Ps: You could also use false & -

Simplifying Queries: Using sum, count, etc in Propel 1.3

My old post handled Propel 1.2.

This is the way to do it in Propel 1.3

1
2
3
4
5
6
7
    $c = new Criteria();
    $c->add(FavoriteDatePeer::EVENTDATAPROPOSAL_ID, $this->getId());
    $c->addSelectColumn("SUM(".FavoriteDatePeer::SCORE.") as rank");
 
    $stmt = FavoriteDatePeer::doSelectStmt($c);
    $row = $stmt->fetch();
    return $row['rank'];

Symfony Plugin for Eclipse : SfDT

Posted by Gijs Nelissen in All

I just found out someone is working on a new symfony plugin for eclipse, there used to be symfoclipse, but closed-source, commercial and no support for Eclipse 3.4. This new plugin works with symfony 1.0, 1.1 and 1.2. The website states it is tested with Eclipse 3.3.2 and PDT 1.0.2 but i did manage to run it on Eclipse 3.4 and PDT 2.x.

So what can this plugin do ?

  • create modules/projects/applications rightfrom within Eclipse
  • convert Clay database to schema.xml/yml
  • run symfony commandline from within eclipse

screenshot11

More information on this plugin :

Good job guys !

What i love about Redmine

Posted by Gijs Nelissen in All

I previously told you we moved from Trac to Redmine for project management (issue/ticket tracking, milestones, source control management). In this post i will tell you what i like about Redmine and compare it to our previous Trac setup.

From what i understand from the Trac mailing list & some discussions in some of the ticket comments (by core developers) the main goal of  Trac is to create a stable (and basic) system (or groundlayer) that can be extended by using plugins. Thats a great mission statement…But (and there is a but) if you are managing several Trac installations this vision turns against you rather quickly, below some of the main things i miss in Trac.

Multiple Projects

The initial reason for moving to Redmine was the lack of support for multiple projects in Trac. I know you can hack Trac (see track-hacks) to include multi-project support, but i don’t like hacking. There were several discussions how (and if) Trac should implement multi-project support fact is : there is no “out-of-the-box” solution. I read something about Trac v2.0 supporting this, so i guess we’ll see that in 2015 then..

Redmine does support multiple projects. The integration throughout the entire system is excellent. You can create nested subprojects and move issues/tickets from one project to another. For each project you are able to assign different users and turn certain functionality (milestones, time tracking, source control,..) on and off.

redmine-projects

Batch Issue/Ticket editing

I have to agree Trac ticketing system is very powerful and flexible. Without a doubt Trac is one of the most common and stable tools for project management & issue tracking for a very good reason. You can easily search and filter tickets by severity, project component, version or owner, and then store those. Great.

trac-tickets

What i really miss using Trac is the ability to do a “mass update” (edit/close/move) on several tickets at the same time. This is where the ajax powered “batch edit” feature of Redmine comes in quite handy.

redmine-mass-issue-update

User / Role Management

The user management in Redmine is great ! Besides normal user management it supports (custom) roles. You are able to set different user roles for different projects.

Trac doesn’t support “user management” out-of-the-box. Unlike other bug-tracking systems that simply have a table for storing the users, Trac took the approach of allowing users to leverage the numerous authentication modules available for their web server. This means system administrators are able to hook Trac into something like LDAP, Active Directory, or whatever centralized user system that they already have in place.

So which one is better ?  Difficult question. I am a great supporter of working software out of the box. Not too much configuration, easy to install. This doesn’t mean the software has to be “simple” : flexible and easy-to-configure can go along hand in  hand. That being said i think Redmine took the best approach in having good user management right after installation. If you need something more centralized they still have LDAP support.

A lot of updates/ new features

I am sure Trac is more stable then Redmine. So if you need a stable product, use Trac But as we are a small webdesign company, the stability of the development environment isn’t really that critical to us.

What i am looking for in project management software are new features/idea’s to improve the way our team is working together. I keep an eye on the Redmine timeline/activity to see how other people are using the Redmine platform. Some of their comments/ideas inspire us to change the way we are working or start using a specific feature we haven’t paid attention to.

Anything else ?

Yes, there are some things Trac does alot better. First of all Trac has a large community with multiple core developers, redmine is built around one (maybe a few) persons. Then the source repository browser in Trac is alot more powerful and intuitive.

I have been using Trac for along time now and i have a great deal of respect for all the guys that are working on this rocksolid project. But as i said before, Trac’s strengths is also it’s weakness. By trying to keep the system as lightweight as possible, discussions about possible features mostly result in the “not for core” decision.

PDT 2.0 for Eclipse is out

Posted by Gijs Nelissen in All

If you are into PHP development, this might interest you : PDT 2.0 is out, download it here. Congrats to the PDT team for this great release and the respect of the deadline.

download pdt

If you are wondering whats new, check this page. Have fun with it…

Developer Faster with lightning fast Eclipse

Posted by Gijs Nelissen in Programming

When maintaining & developming large web applications you might notice that eclipse slows up a bit. Building workspace, showing the autocomplete or syntax highlighting might take a while to load. The solution for this is to optimise your eclipse.ini and tell your favourite PHP development IDE to use more memory.

After installing eclipse you open the eclipse.ini in the root. If you followed my previous post, the default settings should be something like this :

-startup
plugins/org.eclipse.equinox.launcher_1.0.101.R34x_v20080819.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_1.0.101.R34x_v20080805
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
-vmargs
-Xms40m
-Xmx256m

This means eclipse will use in between 40 and 256mb. These default settings will allow you to run Eclipse on a pre historic PII with less then 1GB ram, although i wouldn’t recommend that.

Most of you, especially developers working in a development agency, will have powerful workstations. So lets tell eclipse to use a bit more resources

-startup
plugins/org.eclipse.equinox.launcher_1.0.101.R34x_v20080819.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_1.0.101.R34x_v20080805
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
-vmargs
-Xms256m
-Xmx1024m
-XX:MaxPermSize=256m

I changed the xms, xmx and xx:maxpermsize settings.

What does it mean ?

  • Xms sets the initial Java heap size
  • Xmx sets the maximum Java heap size
  • XX:MaxPermSize allows for the JVM to be able to grow the PermSize to the amount specified. Initially when the IDE is loaded, the MaxPermSize will still be the default value but will not actually take up that amount until it is needed.

Wordpress : Seperate RSS feed for Category / Author / Tag

Posted by Gijs Nelissen in Programming

As you may have read we migrated this blog to a wordpress one. Yeahyeah, we are not officially wordpressified.

My impression of the core

The default wordpress core holds alot of use’eable functions, but it took me a while to figure out how the thing worked. You need to know that wordpress is not really written very object oriented, so basically its a collection of functions although some “under the hood” core functionality is object oriented.

If i was not convinced wordpress is a serious project with a great future, i wouldn’t have chosen it, so let’s not start the “code quality” discussion.

The problem

Something i was missing after the default drupal installation was an easy way to retrieve the related rss feed based on the page the visitor was accessing. If a visitor was on the “all posts by author X” page, the linked rss feed should only hold those posts. Same for category pages and tag pages.

Getting the information of a tag, author of category is very easy. There are some built in functions like get_category, and get_category_feed_link that will give you this information. The downside is, this information is basically only available inside “the loop“.

The solution

To get the information about the selected category, author or tag i had to jump a few hoops. It’s a combination of core functions and some minor custom code where i had to retrieve the current tag from the queried variables.

Then I created a custom method that returns the most related feed based on the page request. The method will check what type of page the visitor is accessing (category, tag, author or main page) and return the appropriate rss feed.

/**
 * This method will give you the most related rss feed based on the current page request
 *
 * @param $type
 * @return string (feed url)
 */
function get_feed_url($type = "rss2_url") {
 
  if (is_category()) {
    $current = get_the_category();
    $current = $current[0]->cat_ID;
    return $url_rss = get_category_feed_link($current,$type);
  }
 
  if (is_author()) {
    $current = get_query_var('author_name');
    $current = get_userdatabylogin($current);
    $current = $current->ID;
 
    return get_author_feed_link($current,$type);
  }
 
  if (is_tag()) {
    $current = get_query_var('tag');
 
    $formaturl = "/feed/";
    switch ($type) {
      case "rss_url":
        $formaturl = "/rss/";
      break;
      case "atom_url":
        $formaturl = "/atom/";
      break;
 
    }
    return get_bloginfo("url") . "/tag/" . $current . $formaturl;
  }
 
  return get_bloginfo($type);
}

Examples

get_feed_url("rss2_url"); // on page /blog/
 
//returns : http://www.digitalbase.eu/blog/feed/
 
get_feed_url("atom_url"); // on page /blog/category/digitalbase/
 
//returns : http://www.digitalbase.eu/blog/category/digitalbase/feed/atom_url/
 
get_feed_url("rss_url"); // on page /blog/tag/symfony
 
//returns : http://www.digitalbase.eu/blog/tag/symfony/rss/

Enjoy

Installing Eclipse + Latest Php Development Tools (PDT 2.0)

Posted by Gijs Nelissen in Programming

Following up on my previous post on “installing 3.4 + PDT 2.x” i wanted to let you know there is a much easier way. As we are coming close to a stable version of pdt 2.x (launch on 29th of December) :

  • 2.0 M1 – November 03
  • 2.0 M2 – November 24
  • 2.0 RC1 – December 08
  • 2.0 RC2 – December 14
  • 2.0 RC3 – December 23
  • 2.0 Release – December 29
  • The PDT core team decided to setup an “update site” so you can easily fetch the latest version from within eclipse.

    Installation

    Getting & Running Eclipse

    Get the latest version of Eclipse from the download site. I went for “Eclipse Classic 3.4.1 (151 MB)“. Extract it and double eclipse the eclipse executable.

    Adding the PDT 2.x

    When you selected a workspace and fired up eclipse add the different update sites (Help > Software Updates… > Available Software > Manage Sites)

    A list of the ones you need to add :

    Also make sure to enable the default Ganymede update site.

    make sure these checkboxes are ... checked :)

    make sure these checkboxes are ... checked :)

    Expand the DLTK site and select the Dynamic Languages Toolkit – Core Frameworks or Dynamic Languages Toolkit – Core Frameworks SDK Feature.
    Then check the PDT SDK feature (PDT SDK 2.0.0 ….). Click install & restart eclipse.

    Blog : Moved to Wordpress

    Posted by Gijs Nelissen in General

    I hate reinventing the wheel. That’s why i decided to migrate this blog to wordpress. It takes alot of effort to write your own symfony plugin that holds the functionality of a full stack blogging platform (like wordpress, typepad, blogger …).

    The Symfony Story

    Initially we started by using the simpleBlogPlugin and modifying it to our needs. Some of the things we added :

    • multilanguage support : different posts in english / dutch
    • tag cloud : although they did add this in the new version
    • author information : links to digg/linkedin profile
    • tag / category pages
    • some SEO basics (different descriptions/keywords per post/page)
    • seperate rss feeds (for tag/description/author pages)
    • summary/excerpt support

    Then why change to wordpress ?

    To keep this all updated with the changing symfony framework takes some time. Adding common features popular blogging platforms offer (comment, askimet integration, image editing, …) is a huge job. Thats why i decided to “migrate” this blog to wordpress.

    I did a little hacking here & there to have it support multiple languages, created a custom theme (holding the old digitalbase theme layout) and added some clearly missing core functions.

    I’ll do a followup post with the things i changed and some code.