Feed items

TwigView – The CakePHP 2.x way

Graham Weldon (aka Predominant) recently cloned my TwigView repository on GitHub and changed it to be fully 2.x compliant. One important note on his work is that the changes break 1.x support on purpose. So if you are on CakePHP 2.x looking for a Twig plugin, feel free to head over to his repository for now / from now on. It has all the goodies of mine, but is designed for 2.x.

QuickTip: Environment & Database.php

In this post i am going to explain how to use the Environment library from Rafael Bandeira to automatically configure your Database connection based on the environment your app is running.

Environment looks at the SERVER_NAME (or configurable conditions) and gives it a name and applies a defined set of core options. The method i am explaining uses this info to choose which database config to load, by adding some magic into Database::__construct.
A good practice is to create a file in config with all your environment configs.

Twig for CakePHP: Updates

New features have been added to TwigView just recently. New filters, Better readme, Access to view object and experimental CakePHP 2.0-dev support.

CakePHP 2.x Support
This one is experimental. Using changes made by BigClick in his fork i’ve remodeled the methods to act as proxy and detect if 2.x is being used. So this feature is completely transparent and the plugin will work in 1.2+, 1.3x and 2.0-dev without any changes required. At least in my quick tests it did ;) Enjoy.
View Object
You can now access the view object within a template
{{ _view.action }} //=> 'display'
Two new filter sets
‘basic’ und ‘number’ and as the name suggest are shortcuts to the NumberHelper (me) and basic.php (Hiroshi Hoaki)
Display the debug (pre+print_r) output

cakealot is back!

It’s me again :)
Due to a chain of unfortunate events the entire blog went down and i had to find a new host, dns and all that stuff. Also lost all my old posts in the process. :/
But i’m gonna try to restore them asap and start posting again.

Twig Templates in CakePHP (cont.)

The TwigView got it’s own repository shortly after the initial gist. I am using the same TwigView for a few days now and i am not missing anything so far. Everything runs smoothly and i really enjoy working with Twig.

At first it was awkward.. How to write loops, etc. Had to refer to the manual alot. But with all new technology you just need some time to get used to it. I wasn’t turned off cause views simply started to looked alot nicer than they usually do. All the variable, method calling crap is out of the way. Helps alot when building nicely structured XHTML.
Custom helpers, loops, conditions and elements work. I am also using it for different output formats like JSON and even emails. For emails i was really happy about a working {% trans %} block implementation (everything in between is passed to i18n).

Twig Templates in CakePHP (cont.)

The TwigView got it’s own repository shortly after the initial gist. I am using the same TwigView for a few days now and i am not missing anything so far. Everything runs smoothly and i really enjoy working with Twig.

At first it was awkward.. How to write loops, etc. Had to refer to the manual alot. But with all new technology you just need some time to get used to it. I wasn’t turned off cause views simply started to looked alot nicer than they usually do. All the variable, method calling crap is out of the way. Helps alot when building nicely structured XHTML.
Custom helpers, loops, conditions and elements work. I am also using it for different output formats like JSON and even emails. For emails i was really happy about a working {% trans %} block implementation (everything in between is passed to i18n).

Using Twig with CakePHP

Having fun with Twig right now. Here’s a draft View implementation with i18n support. Just a gist, but works very well for me.
For those who don’t know what Twig is:
- Twig is a template language.
- http://www.twig-project.org

Using Twig with CakePHP

Having fun with Twig right now. Here’s a draft View implementation with i18n support. Just a gist, but works very well for me.
For those who don’t know what Twig is:
- Twig is a template language.
- http://www.twig-project.org

Jailson! Access Control for CakePHP

I’ve written a access control plugin for CakePHP dubbed Jailson. It is completly transparent and auto integrates with Auth if present.

Some examples from the README, because code says more than a thousand words.. =)
// simple in and out
$this->User->lockAs('client');
$this->User->release('client');

// related to another model
$this->User->lockAs('admin_of', $this->Project);
// testing
$this->User->is('admin_of', $this->Project); // true
$this->User->isNot('admin_of', $this->Project); // false

// array support
$this->User->lockAs(array('admin', 'member', 'reporter'), $this->Project);
// and-testing

Jailson! Access Control for CakePHP

I’ve written a access control plugin for CakePHP dubbed Jailson. It is completly transparent and auto integrates with Auth if present. Check it out at GitHub.
Some examples from the README – Code says more than a thousand words.. =)