SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,192
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)

    Zend Framework 2: Change Action Response Based on Request Format?

    I'm sure this is possible in zf2 though I'm not all that familiar. Any I'm trying to replicate rails formats where if you make a request like:

    /user/create:POST

    The create method of the user controller is invoked with a default response of HTML.

    However, this request:

    /user/create.json:POST

    Would return a json response for the state of the action.

    Could someone point me to the ZF2 documentation for doing that?

    Rails snippet:
    Code Ruby:
      def create
     
       @classified = Classified.new
     
        respond_to do |format|
          if @classified.save
            format.html { redirect_to @classified, notice: 'Classified was successfully created.' }
            format.json { render json: @classified, status: :created, location: @classified }
          else
            format.html { render action: "new" }
            format.json { render json: @classified.errors, status: :unprocessable_entity }
          end
        end
      end

    Thanks
    The only code I hate more than my own is everyone else's.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,192
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)
    Surprise, surprise I don't think ZF2 is capable of this. At least not as easy as it would be in rails or Symfony 2. shrug…

    http://framework.zend.com/manual/2.0...nse-strategies

    Looks like the *best method would be to check for some type of flag manually than change the rendering strategy.

    Could they have made it any more of a clusterf**k… I think not.
    The only code I hate more than my own is everyone else's.

  3. #3
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    Ya, I spent about an hour going through Zend 2 before quitting. I'll stick with 1.x, not that it's much better, but Zend 2 didn't look like something I wanted to pick up. Seems like more code to do less.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,192
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)
    I have no choice. Some other developers have chosen to use ZF2 for a project. We are going to use that project as a starting point for an up and coming one. At least that is the plan. I have already stated my concerns and recommend using Symfony 2, which should have been used in the first place due to our marriage with Drupal. At least by using Symfony 2 we could get the hell away from Drupal while also increasing our knowledge in it for future versions since Drupal 8+ is transitioning into Symfony 2 or a significant portion of it. We will see. I'm really just happy to work with something other Drupoo but I prefer it to be Symfony 2…
    The only code I hate more than my own is everyone else's.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •