Hello, I'm having some trouble understanding and/or implementing a simple 
export of some data to a csv file.

I had everything working fine with a simple controller that did not allow a 
view to be rendered by either going back to the referrer or by returning 
the response... as described in the online help.  

But reading some more, it looked as if the export function should really be 
part of the model.  So I converted the controller to just call the model 
function (dumpEventAsCSV) which performed all the data gathering and output 
logic and then returned to the controller and it in would in turn return to 
the referrer or return the response. Again, all without using a view.

      $fn = "somefilepath";
      $ans = $this->dumpEventAsCSV($ev_id, $fn);
   if ($ans) {
      $this->response->file($fn);
      return $this->response;
    } else {
      $this->Session->setFlash('Unable to export current event');
      $this->redirect($this->referer());
    }

But two problems later appeared... When I starting using some 
AppHelper::functions to format some of the output, neither the Controller 
or Model were able to access them.  $this->Form->formatId($ev_id).  Now, 
obviously I can add another copy of the formatting functions to AppModel 
and I suppose to AppController, but that seems like overkill... Now the 
question becomes what have I done wrong with the "design" to get me into 
this silly circle!?

As another question, In the Controller example shown above, the setFlash 
never shows up when returning to the referer()... but when I proceed to 
some other controller/action... it appears?  Along with that, I don't 
really want to display the csv file to the user after is has been created, 
so the $this->response->file() would be replaced by a "success" setFlash, 
and just return to the referrer!

Thank you for any assistance,
glk

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to