Created
          March 27, 2017 16:15 
        
      - 
      
 - 
        
Save igoralves1/3593d3ec8ef08c70869e84fefbc7683f to your computer and use it in GitHub Desktop.  
    AngularJs calling a PHP function to generate a CSV fie
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <a href="#" target="blank" ng-click="getCSVTemplate('patient')" style="color:#439367;"><img src="assets/svg/icons/csv.svg" class="svg"><br> | |
| {{ someText }} | |
| </a> | |
| //Inside the controller | |
| $scope.getCSVTemplate=function(csvType){ | |
| var page = "tools/csvTemplate.php?csvType="+csvType; | |
| document.location.href = page; | |
| } | |
| //csvTemplate.php | |
| //Note: the header makes the functionaly to not redirect to the page when this file is called innside angulrjs | |
| <?php | |
| header('Content-Type: text/csv; charset=utf-8'); | |
| $csvType=$_REQUEST['csvType']; | |
| $output = fopen("php://output", "w"); | |
| if($csvType=='patient'){ | |
| header('Content-Disposition: attachment; filename=bulkInvitePatientCsvTemplate.csv'); | |
| fputcsv($output, array('firstName','lastName','email','group','language')); | |
| $row = array('Enter First Name *mandatory','Enter Last Name * mandatory','[email protected] * mandatory','Enter Group Name','fr/en/pt/es enter only one'); | |
| } | |
| elseif ($csvType=='admins') { | |
| header('Content-Disposition: attachment; filename=bulkInviteCsvTemplate.csv'); | |
| fputcsv($output, array('email','displayName','group')); | |
| $row = array('Enter Admin Email Here','Enter Display Name Here','Enter Group Name Here'); | |
| } | |
| fputcsv($output, $row); | |
| fclose($output); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment