Adding a new Media type and Content Negotiation #600

mehlah opened this Issue Jul 28, 2012 · 5 comments


None yet

3 participants

mehlah commented Jul 28, 2012

Adding a custom Media type with Media::type('foo', 'application/foo', $options), 2 times, one with $options['conditions'], and the other without conditions, makes the last set one, the only active one.

I would expect that the both type handlers co-exists, and the $options['conditions'] assertion let Lithium pick one.

Is that a bug or a feature ?

A simple use case:

Adding a 'json' Media type with default views paths, and without an 'encode' closure, to write custom json responses (as views).
The conditions could be array('json' => true), to only handle responses for urls like /posts.json.

How to make it work, side by side with the default json type encoder?

A longer description of a use case:


Sorry, I still don't understand your use case, or why you would want to wire up two 'json' handlers. Setting 'conditions' => true is only useful when two different logical types (i.e. HTML and JSONP) share the same content-type (i.e. text/html), so I don't even think you need it here.

For your plugin, the built-in 'json' type configuration should work fine: it will be triggered if a client requests application/json, or if a URL ends in .json.

Make sense?

mehlah commented Apr 13, 2013

9 months later, I don't know why I needed that...

@mehlah mehlah closed this Apr 13, 2013
        'view' => 'lithium\template\View',
        'paths' => [
            'template' => [
            'layout' => false,
            'element' => [
        'conditions' => ['ajax' => true]

i dont know where is bug but after few yr working this part, li3 starts loading layout. Any suggestion how i can debug this ? any changes in li3 core negotiation ? when i place is('ajax') in controller, li3 return true, why media starts loading layout insted of layout false ? ;/ when i add action.ajax media handle view w/o layout properly !


I believe this is the only recent change to Media... not sure that would affect it though. You're sure it's not something in your own code?


YUP i think this is it ill try li3 b4 this patch and after..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment