Skip to content

Instantly share code, notes, and snippets.

@notomato
notomato / gist:3377487
Created August 17, 2012 09:45
Adding an ajax media type
<?php
Media::type('ajax', array('text/html'), array(
'view' => 'lithium\template\View',
'paths' => array(
'template' => array(
'{:library}/views/{:controller}/{:template}.ajax.php',
'{:library}/views/{:controller}/{:template}.html.php',
),
'layout' => false,
@notomato
notomato / media.php
Created August 17, 2012 09:42
Adding a mobile template type
You can easily add support for mobile templates by configuring the Media class. Using the snippet below if the request is made from a mobile device we can first check for a mobile template, and if there is none fall back to the default.
@notomato
notomato / gist:3377437
Created August 17, 2012 09:32
Customising form helper
<?php
// Default
<?=$this->form->text('email'); ?>
<input type="text" name="email" id="MemberEmail" value="[email protected]" />
// Custom wrapper class
<?=$this->form->field('name', array(
'wrap' => array('class' => 'wrapper')
)); ?>
@notomato
notomato / gist:3377378
Created August 17, 2012 09:25
Service with custom request class
<?php
$service = new Service(array(
'scheme' => 'https',
'host' => 'web.service.com',
'username' => 'user',
'password' => 's3kr1t',
'classes' => array(
'request' => 'my\custom\Request'
)
@notomato
notomato / gist:3377363
Created August 17, 2012 09:23
Cache config with multiple environments
<?php
use lithium\storage\Cache;
Cache::config(array(
'default' => array(
'development' => array('adapter' => 'Apc'),
'production' => array(
'adapter' => 'Memcache',
'host' => '127.0.0.1:1121'
@notomato
notomato / gist:3377345
Created August 17, 2012 09:22
Example session config with Form and Http adapters
<?php
//config/bootstrap/session.php
use lithium\security\Auth;
Auth::config(array(
'customer' => array(
'adapter' => 'Form',
'model' => 'Customers',
@notomato
notomato / gist:3376920
Created August 17, 2012 08:13
Example configuring multiple database connections
<?php
// config/bootstrap/connections.php
use lithium\data\Connections;
Connections::config(array(
'default' => array(
'type' => 'MongoDb',
'database' => 'my_mongo_db'
@notomato
notomato / gist:3376901
Created August 17, 2012 08:10
Example configuring multiple cache types
<?php
//config/bootstrap/cache.php
use lithium\storage\Cache;
Cache::config(array(
'local' => array(
'adapter' => 'Apc'
),
@notomato
notomato / gist:3376894
Created August 17, 2012 08:06
Quick and dirty admin
<?php
// somewhere in config/bootstrap
Dispatcher::config(array('rules' => array(
'admin' => array(
'action' => 'admin_{:action}'
)
)));
// app/classes/PostsController.php
@notomato
notomato / gist:3376880
Created August 17, 2012 08:01
Using a base subclass
<?php
class Base extends lithium\data\Model {
public function save($entity, $data = null, array $options = array()) {
if ($data) {
$entity->set($data);
}
if (!$entity->exists()) {
$entity->created = new MongoDate();