0

I created the library file named Kategori.php but somehow i can't load library i created.

Here is the library code:

class Kategori {

public function panggil_kategori($id_jenis)
{
     $CI =& get_instance();
     $CI->load->model('ticketing_model');
     $idjenis = $CI->ticketing_model->getone_kategori($id_jenis);
     return $idjenis;

}
}

Here is the controller code:

public function browse_ticketing()
{
    $this->load->library('kategori');
    $this->data['data']=$this->ticketing_model->get_all();
    $this->data['body']='data_ticketing';
    $this->load->view('welcome_ticketing',$this->data);
}

Here is the view code:

<table class="table table-condensed table-bordered table-hover table-striped" border="1">
<h4>Open</h4>
<tr>
    <th>No</th>
    <th>Judul</th>
    <th>Kategori</th>
    <th>Prioritas</th>
</tr>
<?php 
    $no = 1;    
    foreach($data as $row){
?>

<tr>
    <td><?php echo $no++ ?></td>
    <td><?php echo $row['judul'] ?></td> 
    <td><?php echo panggil_kategori($row['id_jenis']); ?></td> 
    <td><?php echo $row['prioritas'] ?></td> 
</tr>

<?php
    }
?>

and here is the model code :

function getone_kategori($id_jenis)


{

$this->db->select('nama_jenis');
        $this->db->where('id_jenis', $id_jenis);

        $query = $this->db->get('jenis_user');
        return $query->row();
  }

When i try run my code the answer is Fatal error: Call to undefined function panggil_kategori() in C:\xampp\htdocs\helpdesk\application\views\data_ticketing.php on line 18..

3 Answers 3

1

panggil_kategori() is a method of class Kategori. You have to create an object of class Kategori in order to use it:

$myKategori = new Kategori();

Then

$value = $myKategori->panggil_kategori($id);

I can't see where you've instantiated a Kategori.

0
0

Dont know why are you using library for this operation, as you are just fetching the data fro m database then you can use some join conditions to get the records and pass to the view.

Well if you want to go with library then i recommend to use helper here as helpers are best suited with views.

0

Your library is being loaded just fine. The problem is in the view where you are trying to access a method in your library. Its bad practice to be trying to access your library in the view. I would suggest that you assign the return value of your method to a variable in your controller and then you can use it in your view.

So in your controller you want to do something like

$this->data['return'] = $this->kategori->panggil_kategori($value);

Then in your view you can do

<td><?php echo $return; ?></td>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.