杂货店crud codeigniter callback_before_insert无效

时间:2016-08-27 10:53:32

标签: php database codeigniter grocery-crud

我正在使用杂货店来操纵我的数据库,我需要在将新输入数据添加到我的表之前检查它,所以我使用了

$crud->callback_before_insert(array($this,'check_advert_title'));

我有函数check_advert_title

public function check_advert_title($post_array) {
    echo '<pre>';
    echo 'hello<br>';
    var_dump($post_array);
    echo '</pre>';
}

但是当我添加新数据时没有任何反应,我只会得到一个空白页面{{success“:false}(因为广告标题应该是唯一的,我使用的标题已存在于我的表格中)

这是广告功能

public function advert() {
    $crud = new grocery_CRUD();

    $crud->set_table('advert');
    $crud->columns('title', 'price', 'file_url', 'is_deleted', 'campaign_id', 'advert_size_id', 'advert_type_id', 'priority_id');
    $crud->display_as('title', 'Title')
            ->display_as('price', 'Price')
            ->display_as('file_url', 'Link')
            ->display_as('price', 'Price')
            ->display_as('campaign_id', 'Campaign')
            ->display_as('advert_size_id', 'Advert Size')
            ->display_as('advert_type_id', 'Advert Type')
            ->display_as('priority_id', 'Priority');
    $crud->set_relation('campaign_id', 'campaign', 'title');
    $crud->set_relation_n_n('advert_timing', 'advert_timing', 'timing', 'advert_id', 'timing_id', 'timing_id', 'advert_id');
    $crud->set_relation_n_n('advert_service_center_type', 'advert_service_center_type', 'service_center_type', 'advert_id', 'service_center_type_id', 'name', 'advert_id');
    $crud->set_relation('advert_size_id', 'advert_size', '{width} x {height}');
    $crud->set_relation('advert_type_id', 'advert_type', 'name');
    $crud->set_relation('priority_id', 'priority', 'name');
    $crud->required_fields('title', 'price', 'file_url', 'is_deleted', 'campaign_id', 'advert_size_id', 'advert_type_id', 'priority_id');

    $crud->set_subject('Advert');
    $crud->set_field_upload("file_url", "assets/images");
    $crud->unique_fields('title');
    $crud->callback_before_insert(array($this,'check_advert_title'));
    //$crud->callback_after_insert(array($this,'check_unique_advert_title'));

    $output = $crud->render();

    $this->wide($output);
}

0 个答案:

没有答案