Blog posts

Dec 07

JQuery Live and draggable event with elements created on the fly

Written: Dec 7th 2009, 22:20

Draggable and Droppable in jQuery UI is very handy, but if you are adding new draggable items to your DOM tree on the fly, they will not work since the events is binded when the document is created. jQuery Live comes to rescue, but how do you use it jQuery.live?

The answer is to add the draggable behavior when the user first mouse over the item. To avoid binding the behavior twice we a init check:

Permalink for JQuery Live and draggable event with elements created on the fly
Aug 24

Embed images anywhere in CakePHP

Written: Aug 24th 2009, 22:38

Inspired by the Ez publish’s way to embed images inside rich text fields, this CakePHP code takes the same principle in the true CakePHP way, with two helpers to extend David Persson’s Media Plugin.

Permalink for Embed images anywhere in CakePHP
Aug 09

Getting started with OpenID and PHP

Written: Aug 9th 2009, 14:14
Open ID

Growing number of web applications and multiple numbers of user accounts can be a headache for the end user. Luckily the big players have started to agree on standards that makes the personal information flow between these services.

Permalink for Getting started with OpenID and PHP
Jul 26

Basic sorting with HABTM relation in CakePHP

Written: Jul 26th 2009, 23:23

After struggling with doing a basic filter pattern on my new Portfolio section, I found the clues I needed in this tutorial. Here is the basic function.


function index($cat = null) {

if($cat == null) { // If no category chosen, just use the basic paginate function $portfolios = $this->paginate(); } else { // Set basic params with conditions form $this->paginate $params = array( ‘contain’ => false, ‘fields’ => array(‘DISTINCT (Portfolio.id) as id’), ‘conditions’ => $this->paginate[‘conditions’], ‘joins’ => array() );

// Add the search on the habtm relations table $joins1 = array( ‘table’ => $this->Portfolio->tablePrefix.‘portfolios_categories_portfolios’, ‘alias’ => ‘CategoriesPortfolio’, ‘type’ => ‘inner’, ‘foreignKey’ => false, ‘conditions’=> array(‘CategoriesPortfolio.portfolio_id = Portfolio.id’) ); $joins2 = array( ‘table’ => $this->Portfolio->tablePrefix.‘portfolios_categories’, ‘alias’ => ‘Category’, ‘type’ => ‘inner’, ‘foreignKey’ => false, ‘conditions’=> array( ‘Category.id = CategoriesPortfolio.category_id’, ‘Category.slug’ => $cat ) ); array_push($params[‘joins’], $joins1); array_push($params[‘joins’], $joins2);

$tmp = array(); foreach ($this->Portfolio->find(‘all’, $params) as $row) { array_push($tmp, $row[‘Portfolio’][‘id’]); } // Final paginate query with the Portfolio ID’s as ‘scope’ $portfolios = $this->paginate(null, array(‘Portfolio.id’ => $tmp)); } // Send var to the view $this->set(‘portfolios’, $portfolios);
}

Permalink for Basic sorting with HABTM relation in CakePHP
Jul 22

Gersh.no is updated

Written: Jul 22nd 2009, 22:33
My new homepage

Finally I managed to get my new homepage ready. I have been working on building the logic I needed since spring, but with the ironman season and my involvement of the new homepage for Norseman Xtreme triathlon I got a little delay.

Permalink for Gersh.no is updated
Mar 11

Why your Cakephp app should be made up of plugins

Written: Mar 11th 2009, 21:35

Recently I have been working on my latest Cakephp app, and found Cakephp’s plugin architecture to be a great timesaver and helper. Totally I have 12 models, but only 3 in the regular app/model directory. The rest is located under the plugins:

  • Authake (3 models) – handles users, user groups and roles
  • Newsletter (5 models) – subscribers, groups, mails and reporting
  • Comments (1 model) Build myself, and is plugable in any view since it is using the url as an relation

Both Authake and Newsletter needed some finishing and debugging, but if I was do build the same functionality myself I would have spent much more time.

Guidelines for building plugins

While taming these external plugins, you got a feel for what’s best praxis building plugins. As a short list I will emphasize these points:

  • Use conventions! Admin functions should utilize the build in admin routes!
  • Use conventions! Do NOT mock up to much with the baked views. Rather but your effort in writing smart, and good code in models, controllers, helpers and components. Avoid using icons instead of the edit, view and delete buttons/links!
  • Comment code!
  • Escape the messages with the __(“string”) function to make language translation or customization easier!
  • When deploying a plugin I tent to move some views into the main view-folder in the app directory. At least I did that with the Newsletter-plugin (see above)
  • Even though you are using SVN for your app, you can add a svn propedit svn:ignore plugins and check out other repositories in that directory
Permalink for Why your Cakephp app should be made up of plugins
Feb 02

Launch of Surdeig.no CakePHP application

Written: Feb 2nd 2009, 19:05

Screenshot cakephp application surdeig.no

I started baking a wail ago, think it must have been almost 10 years back. For many years I was like a once in a while baker, reading the recipies at the back of flour packages and happy eating theese breads. Then I discovered sourdough in a danish book about outdoor cooking, and successfully created my first sourdough culture. Call it passion, but since than I have been a weekly baker and eating my selfmade, healthy rye bread each and every day (almost).

Combined with my other “baking” passion I have now created a norwegian sourdough baking site, build in CakePHP of course! Mostly I want to share and serve knowledge about sourdough baking and other baking relative thinks I have picked up, but also try out CakePHPish this and do nice design stuff. Check it out on www.surdeig.no.

Source code is awailable on code.google.com/p/gerhardsletten/ or (directly):
svn co http://gerhardsletten.googlecode.com/svn/trunk/cakephp/surdeig

How I started baking with CakePHP

Then I found out about CakePHP in a web framework roundup in Pratical Webdesigner. Think it was the joy of a Ruby on Rails application structure combined with the fact that I didn’t had to learn another language that won me over. After a mounth of playing I was able to release my first app – my version of the famous blog tutorial hosted here at www.gersh.no (it has been refactored once since then).

Permalink for Launch of Surdeig.no CakePHP application
Dec 18

SmartMarkUp with CakePHP

Written: Dec 18th 2008, 22:15

Smarkup with Cakephp

SmartMarkUp is a lightweight textedtor in where the compressed version weights only 10kb (without css and images.

How to use in CakePHP

Adding it to CakePHP is pretty easy: Just drop it in your “js” folder, and add a symbolic link of it in your “css” folder so you can add the css as well.


// Add the stylesheets
css(‘smarkup/skins/style.css’) ?>
css(‘smarkup/skins/default/style.css’) ?>

// Add the javascript
link(‘smarkup/smarkup.js’); ?>
link(‘smarkup/conf/html/conf.js’); ?>

Then you activate it with:


.. SMarkUp.bind('PostBody', 'html', 400); ..

Follow the guide on their this page.

Permalink for SmartMarkUp with CakePHP
Dec 14

Dice Adobe Air application

Written: Dec 14th 2008, 23:45

Had some friends over at my place on saturday and for beer and “Navigare” (like the Monopoly Board Game only on the ocean). Unfortunately the dice was gone.. Well, creating a random thing shouldn’t be that hard on a computer, so I wrote this simple dice application.


Download Dice.air (Adobe Air Application)


Download Dice Source

Permalink for Dice Adobe Air application
Oct 11

Leaves are falling while I am coding

Written: Oct 11th 2008, 17:07

After a rather tough season with plenty of triathlon competions here in Norway. The main race where a Ironman in Kalmar the 2. of august, where I completed the 3.8 km swim, 180 bicycle leg and marathon on 10 hours and 15 minutes.

Since then my weekly training volume has dropped, and I have been spent more time on my new MacBook doing computer related stuff.

Things archived so far this fall

  • Did a revision of the code on this site (www.gersh.no) and upgraded to CakePHP 1.2.
  • Redesign my norwegian blog at www.gerhardsletten.no – not quite finished yet, think I might also need to do a rebranding.
  • Added some new open source project to www.gersh.no/projects that I have been having laying around.

Upcoming plans for this winter

  • This summer I have been included in the Norseman Extreme Triathlon Crew, with responsibility for their homepage at www.nxtri.com where we will move it over to the Ez publish platform and enhance usability.
  • Write a Adobe Air application for uploading images directly to your own server, and a PHP application to receive these files. Much as the Picasa or Flickr plugin for iPhoto, but on your own server.
  • Write a new version of WorkTimer in Adobe Air, but maybe with some new features. I have been receiving a lot of wishes via mail, and I also would like to add some “Scrum” functionality like Scrumworks.
  • With my new work at www.netmaking.no – a Ez partner here in Oslo I will probably be doing a lot of stuff in the Ez to.
  • Working on my norwegian sourdough site www.surdeig.no. A lot of people have signed up!

Guess it won’t be a lazy winter for me..

Permalink for Leaves are falling while I am coding

Page 1 of 3

<< previous
| 1 | 2 | 3 | next >>