如何在Codeigniter中实现编辑器数据表?

时间:2017-05-31 05:00:57

标签: php codeigniter

我从此网站下载了编辑器数据表codeigniter版本http://ci.dubbel16.nl/index.php/2015/12/22/codeigniter-with-datatables-and-editor/

但是当我在codeigniter中运行编辑器数据表时显示错误,如

  

致命错误:Class' DataTables \ Editor'找不到C:\ wamp \ www \ EditorTest \ application \ models \ StaffModel.php 31

他们推荐了PHP 5.3.0+版本,而且我使用的是PHP 5.3.10。

请有人帮我解决这个问题吗?

这是我的staffModel.php代码: -

class StaffModel extends CI_Model 
{
    use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Join,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate;

private $editorDb = null;

//constructor which loads the CodeIgniter database class (not required)
public function __construct()   {
    $this->load->database();
}    

public function init($editorDb)
{
    $this->editorDb = $editorDb;
}

public function getStaff($post)
{
    // Build our Editor instance and process the data coming from _POST
    // Use the Editor database class

    Editor::inst( $this->editorDb, 'datatables_demo' )
    ->fields(
        Field::inst( 'first_name' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'last_name' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'position' ),
        Field::inst( 'email' ),
        Field::inst( 'office' ),
        Field::inst( 'extn' ),
        Field::inst( 'age' )
        ->validator( 'Validate::numeric' )
        ->setFormatter( 'Format::ifEmpty', null ),
        Field::inst( 'salary' )
        ->validator( 'Validate::numeric' )
        ->setFormatter( 'Format::ifEmpty', null ),
        Field::inst( 'start_date' )
        ->validator( 'Validate::dateFormat', array(
            "format"  => Format::DATE_ISO_8601,
            "message" => "Please enter a date in the format yyyy-mm-dd"
        ) )
        ->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
        ->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 )
    )
    ->process( $post )
    ->json();    
}

//An additional method just to see if we can still use the Codeigniter database class (not required)
public function getStaffMember($id)
{
    if($id != false) 
    {
        //Use the CodeIgniter database class
        $query = $this->db->get_where('users', array('id' => $id));
        return $query->row_array();
    }
    return false;
}

}

1 个答案:

答案 0 :(得分:0)

您是否已完成以下更改在libary EditorLib.php 中,从我们的模型“StaffModel”中检索数据是通过以下行完成的:

    //Load the model which will give us our data
    $this->CI->load->model('StaffModel');

    //Pass the database object to the model
    $this->CI->StaffModel->init($db);

    //Let the model produce the data
    $this->CI->StaffModel->getStaff($post);

还尝试包含文件

// DataTables PHP库

include( "../../php/DataTables.php" );