Archive for CakePHP

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

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

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

CakePHP: implementing custom validation objects

Today I would like to share with you a really simple problem about model validation.

What to do if you need to share some custom validation logic between multiple models?

Continue reading »

Posted in CakePHP | Leave a comment

Be careful on debug() and CakePHP Session!

Few days ago I spend about an hour on a very strange strange bug relating to usages of debug() utility.

I was implementing a CakeEventListener on a very simple controller.

I was thinking it was a bug… but it was just a consequence of CakePHP lazy-load initialization behavior!

Continue reading »

Posted in CakePHP, Tips & Tricks | 2 Comments

CakePHP AuthComponent – refresh user data

In my authentication based project I have an Account Settings panel who allow authenticated user to change some profile data like e-mail, language and country.

All things works fine with CakePHP Model’s save() method but AuthComponent still provide old values because it stores user’s data into CakePHP SessionComponent at login time.

The problem is that when an authenticated user updates it’s profile then he need to logout then login to update session’s data.

Continue reading »

Posted in CakePHP, CakePOWER, Tips & Tricks | Leave a comment

Ajax / REST HTTP Status Response Code

Today I was playing with BackboneJS save/destroy methods on data models.

My JS app was binded to a MySQL db by a CakePHP (CakePower) REST layer so I have a controller implementing the CRUD methods.

This controller sends notifications using the CakePower notification system but I found a problem with this interface: no error http status was given to the response!

// the simple CakePower error notification:
$this->Session->error( 'user not found' );

This code drives standard CakePHP requests (forms, links) setting up a flashMessage, ajax and REST requests setting up a JSON response object.

The problem was all responses was given with the 200 HTTP Status code! This was a very bad mistake!

If errors was found in controller’s logic then HTTP Status needs to be configured according to the error: 404 if resource was not found or, at least, a generic 500 – Internal Server Error.

Dealing with jQuery::ajax()

The real world problem was that with 200 response status jQuery::ajax()’s error callback was never thrown!

BackboneJS Model::destroy() method implements an automation to remove destroyed model from related collections… But this automation fails without correct HTTP status!

NOW THIS BUG IS FIXED AND ALL THINGS WORKS FINE!

Customize HTTP Status Code

Default HTTP Status is 200 for: message(), confirm(), warning() methods and 404 for error() method.

You can customize this information with the status option:

$this->error( 'bad request!', null, array( 'status'=>400 ) );
$this->confirm( 'updated!', null, array( 'status'=>204 ) );

Have a nice developing experience with CakePower and BackboneJS!

Posted in CakePHP, CakePOWER | Leave a comment

CakePower Notification System

When performing actions like “find something”, “save something”, “do something” you often need to inform about results just like: “ok, done!” or “ko, errors found!”.

CakePHP let you set a flash message then (optional) redirect wherever you need to but I think this is not enough! 

CakePower introduces the concept of “state response” to solve this problem.

Continue reading »

Posted in CakePHP | 4 Comments

HtmlHelper::tag() method in CakePower

CakePower extends CakePHP’s HtmlHelper without change it’s API. This way you can enjoy powerful functionalities without to change helper names in your sources.

The standard CakePHP code:

$p1 = $this->Html->tag( 'p', 'content of first P' );
$p2 = $this->Html->tag( 'p', 'content of second P', array( 'class'=>'second' ));
echo $this->Html->tag( 'div', $p1.$p2, array( 'class'=>'container' ));

Enjoy CakePower:

echo $this->Html->tag(array(
    'name' => 'div',
    'class' => 'container',
    'content' => array(
        array(
            'name' => 'p',
            'content' => 'content of first P'
        ),array(
            'name' => 'p',
            'class' => 'second',
            'content' => 'content of second P'
        )
    )
));

Continue reading »

Posted in CakePHP | 2 Comments

Swedish Greys - a WordPress theme from Nordic Themepark.