generateApp: Missing .htaccess in public folder
-
Louis St-Amour
Well, on the XML front, I discovered quickly that there was one glaring problem -- it didn't exist.
Right now, it seems, if you type
.jsonat the end of the URL, instead of leaving it blank or typing.html, it will automatically convert $this from your controller into JSON. So$this->flash = "Hello!"becomes{"flash":"Hello!"}in your browser. But when you try typing .xml, nothing new happens.Except,
$this->request->formatin your controller function is set toxhtmlwhen loaded normally,jsonwhen .json is appended, and (you guessed it),xmlwhen .xml is appended.So here's my quick and dirty way to add XML output in addition to XHTML output:
if($this->request->format == Formats::XML) $this->request->meta->app->viewsDir = $this->request->meta->app->viewsDir . 'xml/';Oh sure, it's not that great, but it gets the job done. I won't have that many methods, and I'll just add it to each one, I suppose. Or maybe I can add a similar trick to the Application controller. I'm not sure. But it seems to work, at least in development mode. And that's enough for me right now.
As to why it works, take a look at
recess/recess/framework/views/NativeView.class.phpbelow. Note the line withviewDirto load the correct view (And the line withgetViewsDir, which seems um, useless.) Also, you can see where XML output code should go, in the second method's case statement, afterFormats::JSON.class NativeView extends AbstractView { /** * Realizes HTTP's body content based on the Response parameter. Responsible * for returning content in the format desired. The render method likely uses * inversion of control which delegates to another method within the view to * realize the Response. * * @param Response $response * @abstract */ protected function render(Response $response) { $this->renderFormats($response); extract($response->data); $viewsDir = $response->meta->app->getViewsDir(); include($response->meta->viewDir . $response->meta->viewName . '.php'); } protected function renderFormats(Response $response) { switch($response->request->format) { case Formats::JSON: $this->render_JSON($response); default: } } protected function render_JSON(Response $response) { foreach($response->data as $key => $value) { if($value instanceof ModelSet) { $response->data[$key] = $value->toArray(); } if($value instanceof Form) { unset($response->data[$key]); } if(substr($key,0,1) == '_') { unset($response->data[$key]); } } if(isset($response->data['application'])) unset ($response->data['application']); if(isset($response->data['controller'])) unset ($response->data['controller']); print json_encode($response->data); exit; } } -
Kris Jordan
- State changed from new to open
Thanks for the submission. There is revamped support for content-negotiation in 0.20 that should be making its way to Github in the next day or so. Will update this ticket when it happens. Thanks!
-
Kris Jordan
- State changed from open to resolved
More flexible support for response types is in 0.2 and we are now generating .htaccess in public dir thanks to KevBurnsJr
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.