2016-05-28 10 views
0

私はcodeigniterでデータベースに自分のデータを表示したいだけです。CodeIgniterでデータベースデータを表示

私のコードはerror 404 The page you requested was not foundです。

モデル

<?php 
    class Daftar_model extends CI_Model 
    { 
     public function __construct() 
     { 
      //connect ke database 
      $this->load->database(); 
     } 

     public function get_pertanyaan() 
     { 
      $query = $this->db->get('pertanyaan_ts'); 
      return $query->result_array(); 
     } 

    } 
?> 

コントローラ

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

class Daftar_controller extends CI_Controller { 

    public function index() 
    { 
     //echo "Hallo"; 
     $this->load->model('administrator/pertanyaan/daftar_model'); 
     $this->load->view('administrator/pertanyaan/daftar_view',$data); 
     $data["pertanyaan_ts"] = $this->daftarpertanyaan_model->get_pertanyaan; 
    } 

ビュー

<html> 
<head> 
    <title><?php echo $judul; ?></title> 
</head> 
<body> 
    <h1>Daftar User</h1> 
    <table border="1"> 
     <thead> 
     <tr> 
      <th>Pertanyaan</th> 
     </tr> 
    </thead> 
    <tbody> 
      <?php 
       foreach($pertanyaan as $p){ 
     ?> 
       <tr> 
      <td><?php echo $p->pertanyaan; ?></td> 

     </tr> 
      <?php } ?> 
    </tbody> 
    </table> 
</body> 
</html> 
+0

あなたの.htaccessファイルを確認してください。 –

+0

あなたは経路を書いてありますか? – splash58

+0

Daftar_controllerは 'controller'の名前を削除します。コントローラ名はDaftarでなければなりません。 * http://example.com/daftar/* –

答えて

1

あなた制御へのカップルの変更あなたはよかったはずです。

変更するクラスの名前とexample.com/daftar

class Daftar extends CI_Controller { 

public function index() 
{ 
    //assign the page title 
    $data['judaul'] = "Daftar User"; 

    $this->load->model('administrator/pertanyaan/daftar_model'); 

    //you need to assign a value to $data before sending it to the view 
    $data["pertanyaan_ts"] = $this->daftar_model->get_pertanyaan;  
    $this->load->view('administrator/pertanyaan/daftar_view', $data); 
} 

でこれを参照モデルを使用すると、構文$p->pertanyaan_tsを反対しない配列構文$p['pertanyaan_ts']でビューに送信されたデータにアクセスする必要があるので、配列を返します。変更されたビューファイル

<html> 
    <head> 
    <title><?php echo $judul; ?></title> 
    </head> 
    <body> 
    <h1>Daftar User</h1> 
    <table border="1"> 
     <thead> 
     <tr> 
      <th>Pertanyaan</th> 
     </tr> 
     </thead> 
     <tbody> 
     <?php 
     foreach($pertanyaan_ts as $p) 
     { 
      ?> 
      <tr> 
      <td><?php echo $p['pertanyaan']; ?></td> 
      </tr> 
      <?php 
     } 
     ?> 
     </tbody> 
    </table> 
    </body> 
</html> 
関連する問題