Sign in to follow this  
nickngqs

Export CSV for a page

Recommended Posts

Does anyone know how to do an export of a page entries to CSV using the Processwire way?

I'm trying to setup a list where the client can see a list of user's form values.

Example ->

A front end form -> Upon submit -> Adds to database -> Shows on the admin of Processwire.

From there, I can see the entries and sort stuff. And lastly I can export them in CSV.

I'm looking at the Processwire cheatsheet and see the $files, is this the one I should be looking at? 

Share this post


Link to post
Share on other sites

I didn't understood everything but you can take a look at this thread :

 

 

and this module if it help :

 

 

  • Like 2

Share this post


Link to post
Share on other sites

I use something called SimpleExcel to export / import CSV.

http://faisalman.github.io/simple-excel-php/

 

Here's an example code snippet for Export :

$AllPages is just the data source, so you can replace it with your own.
I would also ignore all the col_subcat fields and any associated functions like GetSubCategoryNames.

You can replace 'SSS-Exported' at the bottom to the filename of your choosing.

    public function ProcessXML() {

        $AllPages =  Data::PagesAllContentsNoInteraktives();

        if ($AllPages->count()==0)
            exit;

        $_colTitle  = 0; //A
        $_colCategory=1; //B
        $_colSubcat1 =2; //C
        $_colSubcat2 =3; //D
        $_colSubcat3 =4; //E
        $_colSubcat4 =5; //F
        $_colSubcat5 =6; //G
        $_colContent = 7; //H
        $_colIntro   = 8; //I
        $_colAuthor  = 9;//J
        $_colImage   = 10;//K
        $_colAlt     = 11;//L
        $_colTitleNav= 12;//M
        $_colSEOTitle= 13;//N
        $_colKeywords= 14;//O
        $_colSEOImage= 16;//Q
        $_colMeta    = 15;//P
        $_colURL     = 17;//R
        $_colURLnew  = 18;//S
        $_colCanonical=19;//T
        $_colParent  = 20;//U
        $_colAudio   = 21;//V
        $_colVideo   = 22;//W
        $worksheet = array();

        array_push($worksheet,
        array(
            'Title',
            'Category',
            'Sub-Category I',
            'Sub-Category II',
            'Sub-Category III',
            'Sub-Category IV',
            'Sub-Category V',
            'Content',
            'Intro',
            'Author',
            'Image',
            'Alt',
            'Title for Navigation',
            'SEO Title',
            'Keywords',
            'Meta Description',
            'SEO Image',
            'URL',
            'URL New',
            'Canonical',
            'Parent',
            'Audio',
            'Video URL',
            'ID'
            )
        );

        foreach ($AllPages as $page) {
            try {

                $subcats = GetSubCategoryNames($page);

                $subcat1='';
                $subcat2='';
                $subcat3='';
                $subcat4='';
                $subcat5='';

                try {
                    $subcat1 = $subcats[0];
                    $subcat2 = $subcats[1];
                    $subcat3 = $subcats[2];
                    $subcat4 = $subcats[3];
                    $subcat5 = $subcats[4];
                }
                catch (\Exception $e)
                {}

                array_push($worksheet, array(
                    $page->title,
                    GetCategoryName($page),
                    $subcat1,
                    $subcat2,
                    $subcat3,
                    $subcat4,
                    $subcat5,
                    $page->content,
                    $page->content_intro,
                    $page->author,
                    $page->image,
                    $page->image_alt,
                    $page->title_nav,
                    $page->seo_title,
                    $page->seo_keywords,
                    $page->seo_description,
                    $page->seo_image,
                    $page->url,
                    $page->url,
                    '',
                    $page->seo_canonical,
                    $page->audio,
                    $page->video_url,
                    $page->id
                ));
            }
            catch (\Exception $e) {
                WriteLog($e->getMessage() . " " . "{$page->title}" . " has errors");
            }
        }

        try {
            $excel = new SimpleExcel('xml');

            $excel->writer->setData($worksheet);
            $excel->writer->saveFile('SSS-Exported');
        } catch (\Exception $e) {
            WriteLog($e->getMessage());
        }


    }


 

P/S In case you need to switch from CSV to XML, this post could be of interest.

 

.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By matsn0w
      Hey everyone, hope you're all doing well!
      I'm building my first ProcessWire website at the moment, which is of course a very good way to understand all of the possibilities ProcessWire has to offer. But that also means that I'm facing some troubles now and then, and so is the case right now.
      I made a template for a couple of pages, like the homepage, the contact page, etc. I am using Bootstrap 4.0 for the layout. 
      So here's the deal: I want to show an alert box on top of every page, warning the user that the website is still under construction. Of course, I can just include the code and add the fields I made for the alert into the template, but that means I have to do that for every page, which I obviously don't want. So I made a template with the code and fields for the alert. When I did this, I realised that I can create multiple alerts this way, so I made two pages, containing different alerts. (And converted the code into a foreach-loop in the template).
      But now my question; how can I include these pages in a different template? Can I make a field or something to insert a page or is this simply not possible? Or do I have to approach this in a different way?
      I hope I explained my problem clear!
      Thank you in advance,
      matsn0w
    • By kongondo
      Pages Export
      This module is for specifically exporting ProcessWire 2.x sites for later importing into ProcessWire 3.x.
      Github: Project Page
      Modules Directory: https://modules.processwire.com/modules/process-pages-export/
      Credits: Ryan Cramer
      Background
      As I make my modules ProcessWire 3.x-compatible only, I've had the need to re-create/mirror their ProcessWire 2.x test sites in respective ProcessWire 3.x sites. These ProcessWire 3.x sites (one for each module) were already in place and I didn't feel like re-doing them by exporting/importing site profiles. I also like working with JSON rather than other export formats. So, I decided to write a custom pages export/import script for moving the ProcessWire 2.x sites to their respective ProcessWire 3.x counterpart sites. I'd just finished the export side of things when I came across a post in the forums that reminded me that ProcessWire 3.x already boasts a pages export/import feature, although some of it is still in development. Great! I like its API (PagesExportImport.php) and GUI (ProcessPagesExportImport.module) so no need to re-invent the wheel. 
      I still had the small problem of making sure my JSON export would be compatible with the JSON input that the ProcessWire 3.x import expects. No need to re-invent the wheel, again! I ditched my custom script and instead ported the export functionalities of ProcessWire 3.x Pages Export/Import for use in ProcessWire 2.2 - 2.7, specifically to help migrate older sites to ProcessWire 3.x.
      Compatibility
      The module and class have been tested and work in ProcessWire 2.2, 2.3, 2.4, 2,5, 2.6 and 2.7.  The module is currently tagged as 'in development' until Pages Import feature of ProcessWire 3.x is released as stable. Nonetheless, I have not encountered any issues so far in either the export or the ProcessWire 3.x import. I think Ryan is waiting until he can support more complex field types before tagging the ProcessWire 3.x Pages Export/Import as production-ready.
      This is not a ProcessWire 3.x module and will never be. It has no such need . Just in case you forget and try to install it in a ProcessWire 3.x site, the module will throw a WireException(). I will also not be porting the ProcessWire 3.x import functionality for use in ProcessWire 2.x. That will defeat the purpose here; to move sites to ProcessWire 3.x and not the other way round.
      Supported Fields
      All non-complex fields such as integer, text, textarea, etc Page fields Repeaters File and Image fields I think these cover most needs. Note: not yet tested with Multilingual fields.
      Technical
      To ensure exports will be compatible with ProcessWire 3.x Pages Import, where necessary, the module borrows (and amends as needed) methods from ProcessWire 3.x for use in ProcessWire 2.x. For instance, ProcessWire 3.x Pages Export/Import uses the new(-ish) $file functions found in WireFileTools. Rather than copy and include such files, the module only borrowed and amended needed methods. These are listed below.
      PagesExport.php
      From /wire/core/Functions.php: wireInstanceOf(), wireClassName() and wireClassParents() From /wire/core/Fieldtype.php: getImportValueOptions() and getDatabaseSchema() From /wire/core/WireFileTools.php: zip(), chmod() and mkdir() From /wire/core/WireHttp.php: sendFile From /wire/modules/Fieldtype/FieldtypeFile.module: exportValue() and exportDescription() From /wire/modules/Fieldtype/FieldtypeImage.module: exportValue() From /wire/modules/Fieldtype/FieldtypePage.module: exportValue() and exportValuePage() From /wire/modules/Fieldtype/FieldtypeRepeater.module: exportValue() From /wire/core/Fieldtype/WireTempDir.php: create(), createName() and getTempDir() All the export methods from the /wire/core/PagesExportImport.php class ProcessPagesExport.module
      All the export methods from /wire/modules/process/ProcessPagesExportImport/ProcessPagesExportImport.module Newer methods such as $this->wire() will gracefully degrade to the older wire() function, ensuring smooth and uniform operation in ProcessWire 2.2  - 2.7.
      Use
      This module and class is for supersusers only and has only 1 aim; to export ProcessWire 2.x sites ready for importing into ProcessWire 3.x sites. You can either install (like any other module) and use the process module (ProcessPagesExport.module) or skip the install and just include and use the class (PagesExport.php) to export your sites.
      Both the module (Export GUI) and API require that you are logged in as a supersuser before you can use them. The PagesExport class has a gateway method and option not found in the original class (PagesExportImport). The method export() allows access to the three export methods in the original class, i.e. pagesToArray(), exportJSON() and exportZip(). See example usage below.
      GUI/Process Module
      On install, the module will create a new admin page Export Pages. Please note that unlike the original code, this page is created directly under /admin/ and not /admin/pages/. Click on Export Pages to start.
      Nothing much has changed from the original ProcessPagesExportImport.
      In older ProcessWire versions where InputfieldSelector was not available, the module will instead present you with a text input to specify a valid (for that version of ProcessWire!) selector for finding pages. The other two methods for adding pages (add pages manually or add by parent) are still available.
      Custom JS ensures older installs without showIf functionality still get the inputfield dependency treatment.
      API
      export($items, $options) 
      PageArray $items: The PageArray to export.
      Array $options: In addition to the options in the original class that you can pass to pagesToArray(), there are two more options here. mode to specify the export type (array or json or zip) and fieldNamesExclude, to specify fields to exclude from the export. Note that the original class option fieldNames still works. It's for specifying the fields to include in the export.
       
      // API USAGE // get and include PagesExport class /* @note: you'll need to include the path differently if you are using the class directly without installing the Process module */ $path = $config->paths->ProcessPagesExport . 'PagesExport.php'; require_once($path); // create new instance of the class $siteExport = new PagesExport(); // find items to export /* a. export whole site! (minus admin and children) careful! in some cases, better to export in batches */ //$items = $pages->get('/')->find('has_parent!=2'); // export a batch of pages $items = $pages->find('template=basic-page|computer'); /* you could also use these methods directly #$data = $siteExport->pagesToArray($items); #$data = $siteExport->exportJSON($items); #$data = $siteExport->exportZIP($items); */ $options = array( // @kongondo addition: export to screen as 'array' or 'json' OR export to zip // zip will be saved in /site/assets/backups/PagesExport/ 'mode' => 'array',// array or json or ZIP // export only these field names, when specified 'fieldNames' => array('images', 'files', 'multi_pages'), // @kongondo addition: exclude fields from export. Here we exclude 'body' field 'fieldNamesExclude' => array('body'), ); // get the export $data = $siteExport->export($items, $options); if(is_array($data)) { echo '<pre> EXPORTED SITE USING pagesToArray '; print_r($data); echo '</pre>'; } // JSON export else echo $data; Screenshots
      See also the links to Ryan's blog posts above.
      ProcessWire 2.2

       
      ProcessWire 2.4

       
      ProcessWire 2.5

       
      ProcessWire 2.7

       
      Video Demo
      (Sorry, long and boring) 
      Demo shows various exports from ProcessWire 2.x and their importing into ProcessWire 3.x. Remember the old Skyscrapers site profile? See how a whole Skyscrapers site gets exported from a ProcessWire 2.7.3 site and imported into a ProcessWire 3.x starting from here.
       
    • By louisstephens
      Hopefully this is pretty easy/quick. I have a signup form with name and email and on submit, a new page is created under "Entries". Is it possible to check if the name (which has two fields for first and last) and or the email is already registered and display an error?
    • By kaba86
      Hello PW Community, really glad that discovered this CMS recently, it is very strange it took so long That idea of no front design limitations is just awesome!
      Need to say that I have a bit of knowledge of html and css, but almost no php, so I need your help.
      What I want to do is an article posting  cms, with this structure:
       
      - Homepage - Projects - Articles -- Category 1 --- Articles of category 1 -- Category 2 --- Articles of category 2 - About - Contact Found this ProcessWire Profile https://github.com/tutsplus/how-to-create-an-ajax-driven-theme-for-processwire
      It covers almost all my needs, except the menu. When I add a childpage for this page http://artist.nicegrp.com/publications/world-world/ , World:World doesn't appear under Writings & Publications.
      I need a menu that works like a breadcrumb, that shows on the menu the category that you are viewing. So when I'm in articles page, on the menu it shows only articles and it's categories. When I get into a category, that category takes state active link but doesn't show on the menu links and titles for contained articles. How can I do that?
      Sorry for my long writing and English, it is not my native but I hope you understood what I need. Can you help me with that?
      Thank you
       
    • By louisstephens
      I have been using the wiresmtpmail module in a few installs for sending out automated emails etc etc, and it works flawlessly. However, I now need to send an email when a user submits a form, and for the life of me I can not figure out how to get the form to submit.
      if(isset($_POST['Submit'])) { $mail = wireMail(); // calling an empty wireMail() returns a wireMail object $toName = $sanitizer->text($input->post->fullname); $toEmail = $sanitizer->email($input->post->email); $phone = $sanitizer->text($input->post->phone); $comments = $sanitizer->text($input->post->comments); $subject = $page->store_name . $page->title; $numSent = wireMail($toName, '', $subject, $textBody, $options); } If I remove the if statement, the form submits just fine, however you can just refresh the page (without adding anything to the fields), and it will submit a blank email every refresh. Has anyone gotten this working with a submit button?