#102 ✓resolved
Louis St-Amour

generateApp: Missing .htaccess in public folder

Reported by Louis St-Amour | May 18th, 2009 @ 03:36 PM | in 0.20

Hello!

Just a quick note, the generateApp function in the RecessToolsAppController creates the public folders perfectly, but the .htaccess file at the root of the main apps folder says "deny from all", which persists in the public folder, causing Apache to toss Forbidden errors.

A quick .htaccess file in the public folder saying "allow from all" is the easy fix, however. I would suggest then that the generateApp function writes such a file, since it's the expected behaviour of a public folder -- to be public, I mean. :-)

It also happens to be what is done in the RecessTools public folder, so it's a "duh" fix.

Thanks for a great RESTful time so far ... the only other question I have now is on writing things like index.xml to get the XML ... the plan is to have the non .xml call present sample output and documentation.

Comments and changes to this ticket

  • Louis St-Amour

    Louis St-Amour May 18th, 2009 @ 07:47 PM

    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 .json at 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->format in your controller function is set to xhtml when loaded normally, json when .json is appended, and (you guessed it), xml when .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.php below. Note the line with viewDir to load the correct view (And the line with getViewsDir, which seems um, useless.) Also, you can see where XML output code should go, in the second method's case statement, after Formats::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

    Kris Jordan June 9th, 2009 @ 02:49 PM

    • 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

    Kris Jordan September 15th, 2009 @ 07:23 PM

    • 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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The Recess PHP Framework is an open source, full stack, RESTful PHP framework.

http://www.recessframework.org/

People watching this ticket

Tags

Pages