« Older Entries Newer Entries » Subscribe to Latest Posts

14 Aug 2009

adding actions to a plugins module in symfony

Posted by havvg. No Comments

There are many cases in which you might want to extend capabilities of a plugin. As this is not that complicated at all and you can go edit every file within your plugin directory, this is not the best way doing this. Adding new methods to a library can easily be done by creating a new class extending the plugins one. I don’t like to edit any file within the plugin directory, as I am using svn:externals to install and update plugins.

I just wanted to add a register action to the famous sfGuardPlugin. It’s – as always – pretty easy to do this in symfony. There are two ways of creating a new action for a module. You add a method “executeRegister” to the actions.class.php of the module or you add a class for the action. The second approach helped me not to touch the code of the sfGuardPlugin.

If you want to overwrite or add things to a module of any plugin, you simply add a folder for the module in your applications “modules” folder. In my case, this is “sfGuardAuth” because I want to extend the sfGuardAuth module of sfGuardPlugin. Having done this, you can add or overwrite anything for this module by adding the required files.

havvgBook:modules havvg$ ls -lR sfGuardAuth
total 0
drwxr-xr-x  3 havvg  staff  102 Aug 14 20:18 actions
drwxr-xr-x  4 havvg  staff  136 Aug 14 20:24 config
drwxr-xr-x  3 havvg  staff  102 Aug 14 20:20 templates
 
sfGuardAuth/actions:
total 8
-rw-r--r--  1 havvg  staff  461 Aug 14 20:27 registerAction.class.php
 
sfGuardAuth/config:
total 16
-rw-r--r--  1 havvg  staff  26 Aug 14 20:24 security.yml
-rw-r--r--  1 havvg  staff  24 Jul 28 21:08 view.yml
 
sfGuardAuth/templates:
total 8
-rw-r--r--  1 havvg  staff  8 Aug 14 20:21 registerSuccess.php

Now that the files exist, you can add the content in sfGuardAuth/actions/registerAction.class.php.

<?php
class registerAction extends sfAction
{
  /**
   * Execute the register action.
   *
   * @param sfWebRequest $request
   *
   * @return string
   */
  public function execute($request)
  {
    return sfView::SUCCESS;
  }
}

The only thing missing now, is a proper route and of course the action itself :)

Tags:

11 Aug 2009

share user class among apps within one symfony project

Posted by havvg. No Comments

Is it possible to share one user class among all apps within one symfony project? – Yes, it is! It is very easy, too. All you need is – surprisingly – a class, some changes in the factories.yml of the apps sharing the user class and that’s it!

At first create a user class you want to share and save it e.g. in lib/mcxUser.class.php, for example:

class mcxUser extends sfGuardSecurityUser
{
  // your code here
}

Now all that’s left is the factories.yml. Add these lines to the factories.yml in the all: section within all apps that will be using the shared user class.

  user:
    class: mcxUser
    param:
      timeout:         1800
      logging:         %SF_LOGGING_ENABLED%
      use_flash:       true
      default_culture: %SF_DEFAULT_CULTURE%

Having done this, you have a green to go. Make sure you clear the cache after doing this.

Tags:

5 Aug 2009

triggerHandler on live event bindings in jQuery

Posted by havvg. No Comments

As stated in the jQuery API Documentation, the triggerHandler() method does not work on events bound to objects using the live() method, which includes also objects created after the DOM was loaded completely.

However, this is nothing unusual. In fact, it might be a common way to work within an advanced AJAX enabled webapplication. I encountered this problem this evening and also created a simple workaround. The following code snippet works just fine.

?View Code JAVASCRIPT
var event = new $.Event('click');
event.preventDefault();
$('input:submit', $(this)).trigger(event);

Tags: