tigrang / cakephp-datatable

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

extra view processing not working #57

Closed mplabs closed 9 years ago

mplabs commented 9 years ago

I'm trying to get the extra view processing to work. I disabled autoRender and created a /app/View/[Model]/datatable/[config_name].ctp file. This file is not processed, all I get is an empty response. What am I doing wrong?

mplabs commented 9 years ago

The problem was that I set _serialize in my AppController. This will cause JsonView::render to not render the datatable view file.

tigrang commented 9 years ago

Can you paste the relevant code? Thanks. On Feb 8, 2015 8:38 AM, "Felix Dürrwald" notifications@github.com wrote:

The problem was that I set _serialize in my AppController. This will cause JsonView::render to not render the datatable view file.

— Reply to this email directly or view it on GitHub https://github.com/tigrang/cakephp-datatable/issues/57#issuecomment-73418549 .

mplabs commented 9 years ago

In my AppController:beforeFilter() function I had $this->set('_serialize', array('user'));

Now in [CORE]/Cake/View/JsonView.php:103-109 you have

public function render($view = null, $layout = null) {
  $return = null;
  if (isset($this->viewVars['_serialize'])) {
    $return = $this->_serialize($this->viewVars['_serialize']);
  } elseif ($view !== false && $this->_getViewFileName($view)) {
    $return = parent::render($view, false);
  }
[...]

Because of that, if you have set the _serialize view variable, the JsonView will not render any template you might have in [APP]/View/{model}/datatable/{config}.ctp but will instead just dump your variables, hence you have no view processing.

I don't know if that is actually a bug or if it should just be stated in the docs as an edge-case.

tigrang commented 9 years ago

You are right. Let me look into this.

tigrang commented 9 years ago

Why do you have a _serialize in AppController::beforeFilter() though?

mplabs commented 9 years ago

I have a javascript application running in the background that will fetch certain pages or just data. A lot of the time, I need the logged in user for these requests. That's why I was setting it. I am now changing it to just hav the _serialize set when I really need it.

tigrang commented 9 years ago

Fixing it is pretty trivial, but I feel like _serialize shouldn't be set in the first place. I'm going to close this issue.

Thanks for trying out the new version btw :) Any other issues or things you wish were different?