All posts by

CakePower Assets Version
prevent undesired assets caching!

CakePOWER allows you to add a virtual version name to all your assets:

// app/Config/core.php
Configure::write('Asset.version', '1.0.3');

Every assets url created through CakePHP helpers will be postfixed with that version string:

<script src="/js/foo.js?v=1.0.3" />
<link href="/css/foo.css?v=1.0.3" />

You should manually change version’s string whenever you upload new version of your assets forcing all clients to download new copy of libraries, stylesheets, images, etc!

Continue reading »

Posted in CakePHP, CakePOWER | Leave a comment

Dropbox CakePHP Plugin

For my new project (MameliCMS) I use a Dropbox plugin for CakePHP: Cakebox.

This plugin helps you to authenticate to Dropbox REST services and to obtain an authorization token to play with Dropbox REST API.

In this post I will (in far future) write a small tutorial to that plugin!

Continue reading »

Posted in CakePHP, Script | Leave a comment

Fix DropDown Bug on mobile devices – Twitter Bootstrap

Yesterday I helped a colleague composing a new corporate website frontend heavily based on TwitterBootstrap.

There was a problem implementing a navigation menu with dropdown sub menus:
Dropdown’s items are not selectable on touch devices!

Surfing the web I found a lot of posts about this problem on stackoverflow and TW Git’s bug tracker… but no official solution is provided by TW team yet!

Hopefully I found a great post who provide a simple solution to this problem by adding a single line of code to the TwitterBootstrap’s dropdown javascript source!

// just append to link #142 of bootstrap-dropdown.js (2.2.1 branch)
.on('touchstart.dropdown', '.dropdown-menu', function (e) { e.stopPropagation(); })

Resources

Posted in Tips & Tricks | Leave a comment

Adminer for CakePHP

adminer

Managing your database should be a problem.

cPanel, phpMyAdmin are very difficult to install and you need to remember configurations or access you database.php file to read from.

Adminer is a one file db manager for MySQL and I wrote a simple webroot package to automatize loggin-in action reading from your App/Config/datavase.php file.

Continue reading »

Posted in CakePHP, Script | Leave a comment

PanelTableUI - CakePanel

PanelTableUI is a component you can use to generate tables.

In many application interfaces you generates data-sheets to be served as tables:

// UsersController.php
public function index() {
  $this->set( 'list', $this->paginate() );
}

You can use PanelTableUI to present an HTML TABLE in a very easy way:

// Users/index.ctp
App::uses('Vendor', 'CakePanel.PanelTableUi');
$tb = new PanelTableUI($this);
echo $tb->render($list);

// or a more compact notation using CakePanel.Panel helper:
echo $this->Panel->table( $list );

Result may be something like:

  • all data sheet columns are presented into resulting table
  • some css classes are applied to beautify data-table (thanks to TwitterBootstrap!)
  • columns are sortable!

All of these features comes with zero configuration!

… but there are several things you can configure to fit your needs!

Continue reading »

Posted in CakePOWER | Leave a comment

PowerSet::def() API

Often my functions accepts an array of options to drive its behavior:

function foo( $data, $options = array() ) {
  if ( $options['filter'] = 'int' ) return intval($data);
  return $data;
}

The plus of accepting an array of options is your method can grow up without change it’s params API.

I often allow to accepts more than array type for my $options param:

function foo( $data, $options = array() ) {
  if ( is_string($options) ) $options = array( 'filter'=>$options );
  ...
}

This way my method API should be something like:

// full api
echo foo( $data, array('filter'=>'int'));

// compact api
echo foo( $data, 'int' );

I like DRY code so much!

Make it easy!

What PowerSet::def() does is to simplify the logic that convert different $options types into specific property names:

function foo( $data, $options = array() ) {
  $options = PowerSet::def($options, null, array(
    'string'=>'filter', 
    'integer'=>'length'
  ));
  ...
}

This code should be translated into:

"if $options type is -string- then put it value into -filter- key"
"if $options type is -integer- then put it value into -length- key"

In every cake $options will be converted into an array.

PowerSet::def('aaa', null, 'class');
-> array( 'class'=>'aaa' );

PowerSet::def(24, null, 'length');
-> array( 'length'=> (int) 24 );

PowerSet::def('aaa', null, array( 'string'=>'class', 'integer'=>'length'));
-> array( 'class'=>'aaa' );

PowerSet::def(24, null, array( 'string'=>'class', 'integer'=>'length'));
-> array( 'length'=> (int) 24 );

Why “null” as second param?

You can set up a default array to be extended with given values:

// useful to apply default values to an array
PowerSet::def('container', array(
  'id => '',
  'class => '',
  'style => '',
), 'class');
Posted in CakePOWER, Script | Leave a comment

PowerString Class API

PowerString extends CakePHP’s String utility library providing some new methods to the framework.

Go back to CakePower’s Documentation Page

Posted in CakePOWER | Leave a comment

PowerString::passwd() API

PowerString::passwd() generates a random string, useful for passwords generation:

echo PowerString::passwd();

It generates a random password string with a length of 8 chars.

Source Namespaces:

To generate a random password PowerString uses some namespace strings self contained into a public static property.
You are able to alter it’s defaults!

These namespaces are available by default:

n -> 0123456789
c -> qazwsxedcrfvtgbyhnujmikolp
m -> QAZWSXEDCRFVTGBYHNUJMIKOLP
s -> ,;.:-_@#*!\"$%&/()=?^+[]'
i -> @#-_.

A random password is created using all of these chars by default!

Altering Random Password Length:

You can set a numeric first argument to teach PowerString::passwd() how long random password should be:

echo PowerString::passwd( 14 );

Random Password Length:

You can also set a min length and a max length for your password; password length is chosen as random value between $min and $max:

echo PowerString::passwd( 10, 14 );

Change Namespace:

You can define a custom namespace to use for password generation:

echo PowerString::passwd( 14, 'abc123' );
echo PowerString::passwd( 10, 14, 'abc123' );

Above code generates passwords with only “a”, “b”, “c”, “1″, “2″, “3″ chars inside.

You can also import a namespace into your custom namespace string:

echo PowerString::passwd( 14, ':n-' );

Above code generates passwords composed by numbers and “-” char.

Posted in MovableApp.com | Leave a comment

Markdown CakePHP Plugin

Markdown Plugin for CakePHP provides a MarkdownHelper to parse Markdown source code plus an integration with views rendering engine to automagically render views as Markdown source files.

  • MarkdownHelper
  • Render views as Markdown

Continue reading »

Posted in CakePHP, Script | 4 Comments

LessC – LessCss Compiler Bugfix

Hi, as you may know CakePower embeds LessC to parse and compile LessCSS source files in a transparent way.

LessC is a PHP script, LessCss allows embedding javascript source code (just like a bookmarklet )so errors happens when you try to compile a LessCss source file who contains some js code.

Continue reading »

Posted in CakePOWER, Tips & Tricks | Leave a comment

Swedish Greys - a WordPress theme from Nordic Themepark.