public function render(array $options = array())
{
$media = $this->_classes['media'];
$class = get_class($this);
$name = preg_replace('/Controller$/', '', substr($class, strrpos($class, '\\') + 1));
$key = key($options);
if (isset($options['data'])) {
$this->set($options['data']);
unset($options['data']);
}
$defaults = array('status' => null, 'location' => false, 'data' => null, 'head' => false, 'controller' => Inflector::underscore($name), 'library' => Libraries::get($class));
$options += $this->_render + $defaults;
if ($key && $media::type($key)) {
$options['type'] = $key;
$this->set($options[$key]);
unset($options[$key]);
}
$this->_render['hasRendered'] = true;
$this->response->type($options['type']);
$this->response->status($options['status']);
$this->response->headers('Location', $options['location']);
if ($options['head']) {
return;
}
$response = $media::render($this->response, $this->_render['data'], $options + array('request' => $this->request));
return $this->response = $response ?: $this->response;
}