Digital Base – Blog » symfony

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 !

using dbFormExtraPlugin for datepicker or datetimepicker

Posted by Gijs Nelissen in All, Programming

For an internal web development project i was looking for a good date picker. I bounced onto sfFormExtraPlugin, but it took me a while to find the correct jquery & jquery UI css & javascript files and set the paths. I decided to create my owner datepicker based on the one in sfFormExtraPlugin (which was based on the jQuery UI Datepicker).

As we already had a plugin containing some of the widgets/validators we are using for some of our webdesign projects, i decided to include those widgets into the existing one named dbFormExtraPlugin, original name, i know…

Installing dbFormExtraPlugin

It’s really this simple, install, publish assets, en clear your cache.

symfony plugin:install dbFormExtraPlugin --release=0.0.5
symfony plugin:publish-assets
symfony cache:clear

sfWidgetFormDateJQuery

This is based on the normal jQuery date picker

class ProjectForm extends BaseProjectForm
{
  public function configure()
  {
 
      $this->widgetSchema['published_at'] = new sfWidgetFormDateJQuery();
  }
}

Should give you something like this

sfwidgetformdatejquery

sfWidgetFormDateTimeDyn

This is based on the dyndatetime project, something i found on google code. From their website :

jQuery has lots of date pickers, but no date- time pickers. This supports date and time, and renders the value to a single field in a configurable format.

Use it like this

class ProjectForm extends BaseProjectForm
{
  public function configure()
  {
      $this->widgetSchema['featured_at'] = new sfWidgetFormDateTimeDyn();
  }
}

Results in a popup, similar to the dynarch calendar picker, including time sliding capabilities !

sfwidgetformdatetimedyn

I still have some work todo on configuration/customisation but it does work (out of the box).
Other installation instructions here. Comments welcome. Leave a message on this post, post a bugticket on the symfony trac or contact us by email.

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.

Bug in Eclipse3.4 + PDT 2.0 (all platforms)

The Problem

After installing Eclipse 3.4 (codename : Ganymede ) and PDT 2.0 (PHP Development Tools ) as i explained in this post . You should have noticed a strange problem when opening/editing PHP files.

An internal error occured during “Selection Job Title”

After googling i found another user having the same problem but no real solution is posted, so here it comes .

The Solution

You need to install the latest version of DLTK (Dynamic Languages ToolKit ). Just download the files here , extract those to a local directory. Then launch eclipse, in software installs & updates (help menu) add a local site, and update DLTK.

After that just restart Ecipse (ganymede) and you can start using PDT.

Custom .debs for Symfony (1.0/1.1 & 1.2) for Debian/Ubuntu

Installing multiple versions of symfony

As i wanted to test some of my projects compability against symfony 1.1, i wanted to install multiple symfony versions on my system. The main reason for this i want to keep the default symfony installation on my desktop as well as on our production environment.Â

Now as you know, we are working with 5 workstations and multiple servers. So it’s a real pain in the *** doing this stuff all over again on each of those machines, so i decided to create some .debs.

The Solution

Thanks to a great guide posted on the Symfony Wiki i was up & running in under 5 minutes. I had to check out the different versions, create some folders to hold the different symfony installs and create some symlinks to make sure you can use those different versions by command line.

The Packages

I created 3 different packages for each version of symfony. You can install as many as you like, as those will all use a different path. Direct Link .

I tested these packages on an Ubuntu Hardy & Feisty and it works like a charm. Let me know if it doesn’t for you.

If you have a hard time figuring out which version of the symfony framework you want to use for your project, check this post

Show me the magic

You can see you now have 3 (or 4) different versions of Symfony available to you.Â

 Multiple Version of Symfony On the same system

Configuration

Now the hardest part (if you can even call it that). Howto tell your symfony application which symfony to use ? Just go to your applications config/config.php and update the paths to the corresponding version.

[code]#52[/code]

Don’t forget to also update the /js path in your virtual host configuration , change the version to the one you want to use for this project.

Alias /sf /usr/share/php/symfony_1.0/data/web/sf

Feedback/Suggestions welcome, just send an email to info@digitalbase.eu Â

Update : if you have a problem opening PHP files (error occured during Selection Job Title) here is my follow-up post (the fix)

Directadmin + Custom Webroot (for symfony…)

As a we are using directadmin for our webhosting machines we previously had problems with custom webroots.

The problem

Directadmin rewrites all uses httpd.conf files when adding/updateing subdomains or domain settings leading to a default httpd.conf, resulting in a blank page for symfony projects. (symfony projects use the /web) webroot.

Previous solution

The previous solution told you to update the symfony webroot directory, this way you went with the directadmin default configuration. (public_html document root). The downside of this solution was that your domain directory (/home/user/domain/mydomain.com) was a mess with directories like public_html, private_html, logs….

The final solution

Now i just bumped into a better & easier solution. Apperently directadmin ‘custom httpd configuration’ accepts the following tokens :

|DOMAIN|,
|IP|,
|HOME|,
|ADMIN|,
|DOCROOT|,
|USER|,
|GROUP|,
|CERT|,
|KEY|, |HOSTNAME|,
|SAFE_MODE|,
|OPEN_BASEDIR|,
|CREATOR|,
|BANDWIDTH|,
|QUOTA|Â

So for all your symfony projects you could update the documentroot right there (no manual httpd.conf configuration or changing the symfony webroot). Just add these 2 lines into your ‘custom httpd.conf’ for the selected domain :

1
2
Alias /sf /usr/local/lib/php/data/symfony/web/sf
|?DOCROOT=/home/USERNAME/domains/DOMAIN/public_html/web|

In the above example you should replace DOMAIN & USER by the variables you can find in the ‘contents of the httpd.conf file’ just below the custom httpd.conf configuration.

dbFusionChartPlugin : Simple Example

Posted by Gijs Nelissen in Programming

This first example will show you howto integrate a FusionChart (free / non-free ) graph in your symfony application, using the dbFusionChartPlugin . I will explain 'example1' included in version 0.0.2 of our plugin.

The Result

Before getting to the code, here is what the final graph/chart will look like

[partial]dbFusionChartExample/example1[/partial]

 

The Partial

The example1 is a partial that looks like this

[code]dbfusionchart-example1-partial[/code]

As you can see the code in this partial is pretty easy. First you tell the symfony application to load the FusionChart helper (using : use_helper). After that you load the graph/chart itself. dbfusionchart_js takes multiple arguments, the most important are the first 2.

  • the first argument is the type of chart (using class constants)
  • second argument is the url to the xml
  • extra arguments tell the dbFusionChart how big the chart should be (width & size).

Very important in the url to the xml is that symfony knows it needs to return valid xml (an no html).

The Action

In the action.class of the dbFusionChartExample module we have the following action :

[code]dbfusionchart-example1-action[/code]


Line 5 – 6
tell symfony to not include the debug bar and send the response as XML (and not html)
On line 8 you will see the declaration of the chart. The classes are pretty smart, but the above example is a very basic example (copy pasted from FusionChart documentation).

When you are ready setting the properties of your chart (we will explain that in further posts), you tell symfony to return the xml (see line : 40).

 

FusionCharts Symfony Plugin: dbFusionChartsPlugin

We're
currently writing an OO class to create FusionCharts
quickly, easily & intuitive, because the existing FusionCharts.php class is not OOP and, honestly, we thought we could do better…
Our package is based on and tested against the FusionCharts Free v2 package. It's written
symfony independent, but we provide a helper, for easy use in symfony.

The symfony plugin, dbFusionChartPlugin, is
in its alpha state now, because it only includes basic single & multi-series chart support. Although the basic code is ready, it needs to be extended, to work with all chart types, but a mediocre programmer should be able to understand its structure and adapt/extend it to his needs. We deeply appreciate all help and suggestions!

Symfony
helper

[code]FC helper ex[/code]

This helper creates the necessary JavaScript.

[code]FC javaScript[/code]

Documentation

You can find the dbFusionChart phpDoc at digitalbase.eu/dbFusionChart/doc/index.html

Logic

As you can see in the FusionCharts Documentation, you need to define your chart's data in an XML file. Our dbFusionChartXML class uses the php DOM extension to encapsulate that XML logic by providing methods to add categories and (datasets with) sets. It has (for now) the descendants dbFC_Single & dbFC_Multi. The latter will make sure there are always as many sets in each dataset as there are categories, when adding a dataset or category.

Stay tuned

We have recently added a check in the addCategory function so it
wouldn't add the same category twice, no matter how many times it's
being called, e.g. when looping Propel objects to init a dbFusionChartXML. It's checks like these that need to be added, among much much more… So stay tuned!