Codeigniter and Jtable plugin - An error occured w

2019-08-29 03:10发布

问题:

I have 2 php files that will generate a jtable plugin which when I run without using code igniter works perfectly. But when I put it in codeigniter that's the time the error will show up. here is my file hierarchy

 application/
      ...
      views/
           system_admin/
                 PersonActions.php
                 view_systemadmin_manageprojects.php

When I run it, the base interface of jtable shows up but without a data plus an error.

I have this code in the view file which calls the other php file

<script type="text/javascript">

    $(document).ready(function () {

        //Prepare jTable
        $('#PeopleTableContainer').jtable({
            title: 'Table of News and Events',
            actions: {
                listAction: 'PersonActions.php?action=list',
                createAction: 'PersonActions.php?action=create',
                updateAction: 'PersonActions.php?action=update',
                deleteAction: 'PersonActions.php?action=delete'
            },

回答1:

CI framework use MVC (Model, View, Controller) pattern and you have to follow it, here you are sending requests direct to PHP PersonActions class, try to create controller with name personAction and call your actions

class PersonActions extends CI_Controller{

   function listRecord(){

   }

   function create(){

   }  

   function update(){

   }

   function delete(){

   } 

}

now javascript

//Prepare jTable

var base_url = "<?=base_url()?>"; // in you html as global before calling jtable script 

$('#PeopleTableContainer').jtable({
    title: 'Table of News and Events',
    actions: {
        listAction: base_url+'PersonActions/list',
        createAction: base_url+'PersonActions/create',
        updateAction: base_url+'PersonActions/update',
        deleteAction: base_url+'PersonActions/delete'
    },