Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Export CSV file From Mysql Database
  • I write this code for csv download.
    <?php
    $products = Model_Account::find('all');
     
     
        $data = "name;password ;email\r\n";
        
        foreach ($products as $product)
        {
         $data .= $product->acc_name . ";";
         $data .= $product->acc_password . ";";
         $data .= $product->acc_email . ";";
         $data .= "\r\n";
        }
          
        $data = Format::factory($products)->to_csv();
        File::create(DOCROOT . 'assets/doc', 'report.csv', $data);
      I get this error.imageimage
      imagehow to solve this problem.can you help me!
  • HarroHarro
    Accepted Answer
    When you feed an ORM object into Format, it will iterate over all properties of the object, including related objects from the looks of it. And you can't str_replace() on an object.

    You could try converting the ORM records in $products to array's first:

        foreach ($products as $id => $product)
        {
         $data .= $product->acc_name . ";";
         $data .= $product->acc_password . ";";
         $data .= $product->acc_email . ";";
         $data .= "\r\n";
         $products[$id] = $product->to_array();
        }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion