Admin method in CakePHP to add a venue to the database I have a VenuesController and an EventsController. My venues controller has an admin_add method that, well, allows an administrator to add a venue to the database. It looks like this:

public function admin_add() {
    if ($this-&gt;request-&gt;is('post')) {
        if ($this-&gt;Venue-&gt;save($this-&gt;request-&gt;data)) {
            $message = 'Venue has been created.';
            $this-&gt;response-&gt;statusCode(201);
            if ($this-&gt;request-&gt;params['ext'] == 'json') {
                $this-&gt;set('id', $this-&gt;Venue-&gt;id);
                $this-&gt;set('_serialize', array('id'));
            }
            else {
                $this-&gt;Session-&gt;setFlash($message, 'flash', array('class' =&gt; 'success'));
                $this-&gt;redirect(array('action' =&gt; 'index'));
            }
        }
        else {
            if ($this-&gt;request-&gt;params['ext'] == 'json') {
                $this-&gt;set('validationErrors', $this-&gt;Venue-&gt;validationErrors);
                $this-&gt;set('_serialize', array('validationErrors'));
                $this-&gt;response-&gt;statusCode(400);
            }
        }
    }
}


As you can see, there are a lot of if () statements which seem like code smells to me. But they’re there because in my CMS’s events section, you can add a venue inline via a modal, which sents the request to this function via AJAX.

So my question is: can I improve the above VenuesController::admin_add() method, make it more intelligent without the need for the if () statements, and just generally make it more CakePHP-ier?
Why do you have the following lines repeating:

    if ($this-&gt;Venue-&gt;save($this-&gt;request-&gt;data)) {
        if ($this-&gt;Venue-&gt;save($this-&gt;request-&gt;data)) {


I think you may try to merge them to one and the associated logic too.