tigrang / cakephp-datatable

JQuery DataTable plugin server-side processing component for CakePHP
47 stars 29 forks source link

conflict with others requests #50

Closed fdalex closed 10 years ago

fdalex commented 10 years ago

Hi, I have an issue and i dont know how to solve it ... I installed the plugin and it's working great, my table and data are displayed well, but it looks like all requests in my controller MachinesController are redirected to your plugin. In my view index i have the table displayed and the action buttons View/Edit/Delete. When i press Delete, i have this error :

Notice (8): Undefined index: model [APP\Plugin\DataTable\Controller\Component\DataTableComponent.php, line 118] Notice (8): Undefined index: language [CORE\Cake\I18n\L10n.php, line 379] Notice (8): Undefined index: locale [CORE\Cake\I18n\L10n.php, line 381] Notice (8): Undefined index: localeFallback [CORE\Cake\I18n\L10n.php, line 382] Notice (8): Undefined index: locale [CORE\Cake\I18n\L10n.php, line 385] Notice (8): Undefined index: charset [CORE\Cake\I18n\L10n.php, line 386] Notice (8): Undefined index: direction [CORE\Cake\I18n\L10n.php, line 387]

I also have this error in my view "Add" (datatable is not supposed to be used here). I have an ajax request on a button of this page and the previous error appears here.

When I remove the public $components = array( ... ) from the MachinesController, this error does not appear. Do you have an idea how to solve my problem ? I dont want datatable to be loaded out of index view, it seems the problem is around here ...

fdalex commented 10 years ago

Hi again, I kinda solved my problem by adding the component in a different way. In the documentation, datatable component is added like this :


class MyController extends AppController {
    ...
    public $components = array(
        'DataTable.DataTable' => array( ... )
    );
    ...
}

I'm adding the component (and the helper) this way :


class MyController extends AppController {
    ...
    function __construct($request = null, $response = null) {
        parent::__construct($request, $response);
        if ($this->action == "index") {
            $this->components = array(
                'DataTable.DataTable' => array( ... )
            );
            $this->helpers = array(
                'DataTable.DataTable' => array( ... )
            );
    );
    ...
}

Now it's working great and only in index page for this controller.

tigrang commented 10 years ago

Hey, by default the trigger for the component to treat the request as a datatable one is if the request is an ajax one and the action is in triggerAction (by default, just index). I'm not sure why you're delete and add are being treated as a datatable request because while its an ajax request, its not in triggerAction (by default).

fdalex commented 10 years ago

As far as i could understand, it seems to be a problem with the load of $components and not an ajax problem. I did an ajax request on my index.ctp and it's working fine. With my "auto-solution" I load $components (and $helper) only for index.ctp and there are no more problems. The issue title is kinda incorrect.