2016-07-12 25 views
0

コンソールにこのエラーメッセージ(500(内部サーバーエラー))が表示される理由を知ることができますか。テーブルに何も表示されません。私は、JavaScriptのajaxとcodeigniterを使用してコントローラからモデルにデータを送信する

/*モデル*/

<?php 
    defined('BASEPATH') OR exit('No direct script access allowed'); 


    class User extends CI_Model 
    { 

     function __construct() { 
      parent::__construct(); 
      $this->load->database();  
     } 

     public function validate_user($email, $password) { 
      $this->db->distinct(); 
      $this->db->select('c.contact_id, name, email, password, level, c.statusid'); 
      $this->db->from('contact c'); 
      $this->db->join('deliveryreg d', 'c.contact_id = d.idcontact'); 
      $this->db->join('ClientLogin cl', 'cl.idcontact = c.contact_id'); 
      $this->db->where('c.statusid = 1'); 
      $this->db->where('email', $email); 
      $this->db->where('password', $password); 
      $this->db->limit(1); 

      $query = $this->db->get(); 

      if($query->num_rows() == 1) 
      { 
      return $query->result(); 
      } 
      else 
      { 
      return false; 
      } 
      } 



     public function getSearch($data){ 


      $this->db->distinct(); 
      $this->db->select(" s.id AS 'searchid',s.description as 'searchname',so.id AS 'sourceid',so.description as 'service'"); 
      $this->db->from('contact c'); 
      $this->db->join('deliveryreg d', 'c.contact_id = d.idcontact'); 
      $this->db->join('searchsource ss', 'ss.id = d.idsearchsource'); 
      $this->db->join('search s', 's.id = ss.idsearch'); 
      $this->db->join('source so', 'so.id = ss.idsource'); 
      $this->db->where('c.statusid = 1'); 
      $this->db->where('email', $data['email']); 
      $ids = array('1','5','8'); 
      $this->db->where_in('so.id', $ids); 
      $this->db->order_by('s.description', 'so.description'); 

      $query = $this->db->get(); 
      return $query->result(); 
     } 

     public function printData(){ 

      $db2 = $this->load->database('otherdb', TRUE); 
      $db3 = $this->load->database('pan', TRUE); 

      $sql = "SELECT c.id,p.name AS 'Pubname',section,pubdate,byline,headline,subheadline,TEXT,AREA,ave,linkedto,thumimage,pagenum,clipuploadpath, c.articleref,pdf,docpath,articlepartnumber,articlepartscount,keyword,logo,p.description AS 'PubInfo',circulation,m.description AS 'MediaType', r.description FROM pearhpmszm_db5.Allocation a JOIN pearhpmszm_db5.clip c ON c.id = a.idclip LEFT JOIN pearhpmszm_db3.Publication p ON c.pubid = p.id LEFT JOIN pearhpmszm_db3.ABC ab ON ab.idpub = p.id 
       LEFT JOIN pearhpmszm_db3.mediatype m ON m.id = p.idmediatype LEFT JOIN pearhpmszm_db3.Region r ON r.id = p.idregion WHERE a.idsearch IN ('".'$_POST["idsearch"]'."') AND c.pubdate BETWEEN '".'$_POST["dateFrom"]'."' AND '".'$_POST["dateTo"]'."'"; 

      $query = $this->db->query($sql); 
      return $query->result(); 

     } 

     public function onlineData(){ 

      $db2 = $this->load->database('otherdb', TRUE); 
      $db4 = $this->load->database('pan2', TRUE); 

      $sql = "SELECT a.idsearch AS 'Searchid',c.id AS 'clipid',c.url,headline,c.description,pubdate,author,TEXT,ave,p.name AS 'sitename', st.description AS 'sitetype',r.description AS 'region' FROM pearhpmszm_db4.allocation a JOIN pearhpmszm_db4.clip c ON c.id = a.idclip LEFT JOIN pearhpmszm_db3.site p ON c.siteid = p.id LEFT JOIN pearhpmszm_db3.sitetype st ON st.id = p.sitetypeid LEFT JOIN pearhpmszm_db3.Region r ON r.id = p.regionid WHERE a.idsearch IN ('".'$Searchid'."') AND c.pubdate BETWEEN '".'$dateFrom'."' AND '".'$dateTo'."' "; 

      $query = $this->db->query($sql); 
      return $query->result(); 

     } 

     public function broadcastData(){ 

      $db2 = $this->load->database('otherdb', TRUE); 
      $db5 = $this->load->database('pan3', TRUE); 

      $sql = "SELECT mentions.id,`pearhpmszm_db2`.`search`.Description,pearhpmszm_db6.Allocation.idsearch,Mention,station,MentionDT,duration,AVE,clipPath, au.Audience,pearhpmszm_db3.Region.Description AS 'Region',pearhpmszm_db3.language.language,pearhpmszm_db6.station.idlanguage,pearhpmszm_db6.licenceType.Licence, (SELECT programme FROM pearhpmszm_db6.schedule WHERE idstation = pearhpmszm_db6.station.id AND CASE DAYOFWEEK(mentiondt) WHEN 1 THEN sun = 1 WHEN 2 THEN mon = 1 WHEN 3 THEN tue = 1 WHEN 4 THEN wed = 1 WHEN 5 THEN thu = 1 WHEN 6 THEN fri = 1 WHEN 7 THEN sat = 1 END AND starttime < TIME(mentiondt) AND endtime > TIME(mentiondt) LIMIT 1) AS Programme, pearhpmszm_db6.Allocation.keyword FROM pearhpmszm_db6.Allocation JOIN pearhpmszm_db6.mentions ON pearhpmszm_db6.Allocation.idmention = pearhpmszm_db6.mentions.ID JOIN `pearhpmszm_db2`.`search` ON `pearhpmszm_db6`.`Allocation`.idsearch = `pearhpmszm_db2`.`search`.id LEFT JOIN pearhpmszm_db6.station ON pearhpmszm_db6.station.name = pearhpmszm_db6.mentions.Station LEFT JOIN pearhpmszm_db3.Audience au ON au.idstation = `pearhpmszm_db6`.station.id AND au.active = 1 LEFT JOIN pearhpmszm_db3.Region ON pearhpmszm_db6.station.IDRegion = pearhpmszm_db3.Region.ID LEFT JOIN pearhpmszm_db3.language ON pearhpmszm_db6.station.idlanguage = pearhpmszm_db3.language.id LEFT JOIN pearhpmszm_db6.licenceType ON pearhpmszm_db6.licenceType.id = pearhpmszm_db6.station.idlicencetype LEFT JOIN pearhpmszm_db6.programname ON au.idstation = `pearhpmszm_db6`.station.id WHERE pearhpmszm_db6.Allocation.idsearch IN ('".'$idsearch'."') AND pearhpmszm_db6.mentions.MentionDT BETWEEN '".'$dateFrom'."' AND '".'$dateTo'."'"; 

      $query = $this->db->query($sql); 
      return $query->result(); 

     } 

     function __destruct() { 
       $this->db->close(); 
      } 
    } 

/* CONTROLLER */

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 
session_start(); //we need to call PHP's session object to access it through CI 
class PrintData extends CI_Controller { 

function __construct() 
{ 
    parent::__construct(); 
    $this->load->model('user'); 

} 

function index() 
{ 
    if($this->session->userdata('logged_in')) 
    { 
    $session_data = $this->session->userdata('logged_in'); 
    $data['email'] = $session_data['email']; 
    $data['query'] = $this->user->getSearch($data); 
    $data['print'] = $this->user->printData($data); 
    $this->load->view('header', $data); 
    $this->load->view('sidebar', $data); 
    $this->load->view('print_content', $data); 
    $this->load->view('footer', $data); 
    } 
    else 
    { 
    //If no session, redirect to login page 
    redirect('login', 'refresh'); 
    } 
} 

function getPrintData($data){ 
    if($this->session->userdata('logged_in')) 
    { 
     $session_data = $this->session->userdata('logged_in'); 
     $data['email'] = $session_data['email']; 
     $data['idsearch'] = $this->user->printData($data); 
     $data['dateFrom'] = $this->user->printData($data); 
     $data['dateTo'] = $this->user->printData($data); 
     $data['query'] = $this->user->getSearch($data); 
     $data['print'] = $this->user->printData($data); 

    } 
    else 
    { 
    //If no session, redirect to login page 
    redirect('login', 'refresh'); 
    } 
} 

function logout() 
{ 
    $this->session->sess_destroy('logged_in'); 
    session_destroy(); 
    redirect('home', 'refresh'); 
} 

} 

?> 

/* VIEWを使用して送信される情報から、テーブル上のデータを表示したいのですがでAJAXによって送信*/

 <!-- Add the sidebar's background. This div must be placed 
      immediately after the control sidebar --> 
     <!-- <div class="control-sidebar-bg"></div> --> 
    </div><!-- ./wrapper --> 

    <!-- REQUIRED JS SCRIPTS --> 

    <!-- jQuery 2.1.4 --> 
    <script src="<?php echo base_url();?>assets/js/jQuery-2.1.4.min.js"></script> 
    <!--Jquery--> 
    <script src="<?php echo base_url();?>assets/js/jquery.js"></script> 
    <!-- Bootstrap 3.3.5 --> 
    <script src="<?php echo base_url();?>assets/js/bootstrap.min.js"></script> 
    <!-- AdminLTE App --> 
    <script src="<?php echo base_url();?>assets/js/app.min.js"></script> 
    <!-- Scroll effect --> 
    <script src="<?php echo base_url();?>assets/js/scroll.js"></script> 
    <!-- Slide effect --> 
    <script src="<?php echo base_url();?>assets/js/slideEffect.js"></script> 

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script> 
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.min.js"></script> 

    <script> 


     /******************************************* 
      GET THE LAST 24HRS DATA PER SEARCHID 
     ********************************************/ 

     function getPrintData(){ 
     alert("In getPrintData"); 

      var dateFrom = moment().add(-1,'days').format("DD/MM/YYYY"); 
      var dateTo = moment().format("DD/MM/YYYY"); 
      var searchid = ""; 
      var count = 0; 
      searchid = $('.searchid:checked').map(function() { 
       count = count + 1; 
       return this.value; 
      }).get().join(","); 


      $.ajax({ 
      url:"<?php echo site_url('printdata/getPrintData');?>", 
      data:{dateFrom:dateFrom, dateTo:dateTo, idsearch:searchid}, 
      type:"POST", 
      cache: false, 
      success: function (response, status, xhr) { 
         alert(response); 
         $("#myContentPrint").html(response); 

        }, 
        error: function (XMLHttpRequest, textStatus, errorThrown) { 
         alert(errorThrown); 
        } 
      }); 
     } 





    </script> 



    <!-- Optionally, you can add Slimscroll and FastClick plugins. 
     Both of these plugins are recommended to enhance the 
     user experience. Slimscroll is required when using the 
     fixed layout. --> 
    </body> 
</html> 
+0

あなたのCSRFセキュリティは無効ですか.......... $ config ['csrf_protection'] \t = FALSE; – kuldeep

+0

あなたのコントローラで、この 'function getPrintData()'のように関数名を変更してください。あなたのjavascriptでは、 'getPrintData()'関数のポストコールを行っています。 '$ this-> input-> post()'を使ってデータを検索する必要があります。 –

答えて

1

まずキャプチャデータこの

function getPrintData(){ 
    if($this->session->userdata('logged_in')) 
     { 
      $data = array('dateFrom' => $this->input->post('dateFrom'), 
       'dateTo' => $this->input->post('dateTo'), 
       'idsearch' => $this->input->post('idsearch'), 
      ); 

     $session_data = $this->session->userdata('logged_in'); 
     $data['email'] = $session_data['email']; 
     $data['idsearch'] = $this->user->printData($data); 
     $data['dateFrom'] = $this->user->printData($data); 
     $data['dateTo'] = $this->user->printData($data); 
     $data['query'] = $this->user->getSearch($data); 
     $data['print'] = $this->user->printData($data); 

    } 
    else 
    { 
     //If no session, redirect to login page 
     redirect('login', 'refresh'); 
    } 
    } 

セカンドのようなコントローラが、メソッドに

をモデル化するために渡される引数を使用してデータを受け取る必要がありますあなたのモデルは、あなたはそれがこのようにする必要があります任意の引数

に合格しませんでした。

function printData($data = array()){ 

     $db2 = $this->load->database('otherdb', TRUE); 
     $db3 = $this->load->database('pan', TRUE); 

     $sql = "SELECT c.id,p.name AS 'Pubname',section,pubdate,byline,headline,subheadline,TEXT,AREA,ave,linkedto,thumimage,pagenum,clipuploadpath, c.articleref,pdf,docpath,articlepartnumber,articlepartscount,keyword,logo,p.description AS 'PubInfo',circulation,m.description AS 'MediaType', r.description FROM pearhpmszm_db5.Allocation a JOIN pearhpmszm_db5.clip c ON c.id = a.idclip LEFT JOIN pearhpmszm_db3.Publication p ON c.pubid = p.id LEFT JOIN pearhpmszm_db3.ABC ab ON ab.idpub = p.id LEFT JOIN pearhpmszm_db3.mediatype m ON m.id = p.idmediatype LEFT JOIN pearhpmszm_db3.Region r ON r.id = p.idregion WHERE a.idsearch IN ('".'$data["idsearch"]'."') AND c.pubdate BETWEEN '".'$data["dateFrom"]'."' AND '".'$data["dateTo"]'."'"; 

     $query = $this->db->query($sql); 
     return $query->result(); 

     } 

し、代わりに印刷データで$ _POST使用$データを使用しての($データ=配列())

+0

ありがとうございますが、エラーメッセージ(500内部サーバーエラー)を依頼しています –

+0

$ sqlを出力して何の出力があるか確認できます – pradeep

+0

$ sqlは完璧です。 searchid、dateFrom、およびdateToを手動で入力すると、データが表示されます。 –

0

まずコントローラにデータを取得する:

function getPrintData(){ 
    if($this->session->userdata('logged_in')) 
     { 
      $data = array('dateFrom' => $this->input-post('dateFrom'), 
       'dateTo' => $this->input-post('dateTo'), 
       'idsearch' => $this->input-post('idsearch'), 
      ); 
     $this->user->printData($data); 

     $session_data = $this->session->userdata('logged_in'); 
     $data['email'] = $session_data['email']; 
     $data['idsearch'] = $this->user->printData($data); 
     $data['dateFrom'] = $this->user->printData($data); 
     $data['dateTo'] = $this->user->printData($data); 
     $data['query'] = $this->user->getSearch($data); 
     $data['print'] = $this->user->printData($data); 

    } 
    else 
    { 
     //If no session, redirect to login page 
     redirect('login', 'refresh'); 
    } 
    } 

あなたがモデル内のデータを取得します:

public function printData($data){ 
//your code here 
} 
+0

ありがとうございますエラーメッセージ(500内部サーバーエラー) –

+0

をプロンプトすると、$ this-> output-> enable_profiler(true)を追加してプロファイラレポートを生成することで、データがポストかどうかを確認できます。コントローラ内で....以下のビューファイルを参照してください。 –

+0

データが転記されていません –

関連する問題