I discovered a bug in the Route.php file. the reg expression used for finding extensions only works if no parameters are passed in the URL. I have temporarily modified my Routes.php file to find the extension anywhere in the string and used str_replace to remove the .json from the url and I no longer get the action missing error. I still get the template missing error though.
On Wednesday, October 14, 2015 at 2:02:24 PM UTC+7, heavyKevy wrote: > > I have gone through the documentation, which is a bit too vague, and tried > many things, but I still am getting an error that the template file is > missing. > > I had this working sending back a json response in 3.0 using ext='json', > yet after updating to 3.1 it is broken. > > I checked the migration guide and tried changing ext to _ext, setting up > the Routes with: > Router::extensions(['json']); > > in the controller method I am using the _serialize key which is supposed > to render without the template: > $this->set('_serialize', ['salesPeople']); > > The JsonView class does not appear to be loading and I don't see in the > documentation where I am supposed to set it. > The documentation says ' you can automatically leverage the new view > classes' By enabling RequestHandlerComponent in your application, and > enabling support for the json and or xml extensions, but I have enabled > it in the Initialize method of the controller and enabled the 'json' > extension as mentioned earlier and it is still not working. > > Here is the method in question: > public function getSalesPeopleSelectList() { > $this->request->accepts('json'); // No direct access via browser > URL > $dealerId = $this->request->params['pass'][0]; > $this->RequestHandler->renderAs($this, 'ajax'); > //$this->viewClass = 'Json'; > $this->loadModel('SalesPeople'); > $salesPeople = > $this->Purchases->SalesPeople->find('list')->where(['is_active'=>'1','user_id'=>$dealerId]); > > //for salespeople options for autocomplete > $this->set(compact('salesPeople')); > $this->set('_serialize', ['salesPeople']); > } > > > When I enable the _ext = json I get the following error: > > 2015-10-14 06:57:36 Error: > [Cake\Controller\Exception\MissingActionException] Action > PurchasesController::getSalesPeopleSelectList.json() could not be found, or > is not accessible. > Exception Attributes: array ( > 'controller' => 'PurchasesController', > 'action' => 'getSalesPeopleSelectList.json', > 'prefix' => '', > 'plugin' => NULL, > ) > Request URL: /Subaru/purchases/get-sales-people-select-list.json/47 > Stack Trace: > #0 > C:\WebServer\cake\subaru\vendor\cakephp\cakephp\src\Routing\Dispatcher.php(114): > > Cake\Controller\Controller->invokeAction() > #1 > C:\WebServer\cake\subaru\vendor\cakephp\cakephp\src\Routing\Dispatcher.php(87): > > Cake\Routing\Dispatcher->_invoke(Object(App\Controller\PurchasesController)) > #2 C:\WebServer\webdocs\Subaru\index.php(42): > Cake\Routing\Dispatcher->dispatch(Object(Cake\Network\Request), > Object(Cake\Network\Response)) > #3 {main} > > What have I missed? > > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.