Issue
this is what I have in my routes:
Router::scope('/', function ($routes) {
$routes->extensions(['json']);
$routes->resources('CustomerCompanies', [
'map' => [
'get_by_account' => [
'action' => 'get_by_account',
'method' => 'GET',
]
]
]);
This is my method get_by_account
inside CustomerCompaniesController.php
:
/**
* Pagination method by Customer Account id
*
* @param string|null $id Customer Account id.
* @return void Redirects to index.
* @throws \Cake\Network\Exception\NotFoundException When record not found.
*/
public function get_by_account($customer_account_id = null)
{
}
Relations:
CustomerAccounts
hasManyCustomerCompanies
CustomerCompanies
belongsToCustomerAccounts
I want to return a list of CustomerCompanies that belong to a particular CustomerAccount by supplying the CustomerAccount id and I get back in json results.
Do I need to change something in the get_by_account to indicate the param? and if so, how?
UPDATE
This is what I saw in the documents:
Solution
You have to define the :id
route element, which is being passed by default (there is currently no way to pass further custom route elements). You can do that either in the array key of your map entry
'map' => [
'get_by_account/:id' => [
'action' => 'get_by_account',
'method' => 'GET',
]
]
or via the path
option (by default, the key is set as the value for the path
option)
'map' => [
'get_by_account' => [
'action' => 'get_by_account',
'method' => 'GET',
'path' => 'get_by_account/:id'
]
]
See also
- Cookbook > Routing > Mapping Additional Resource Routes
- Source > \Cake\Routing\RouteBuilder::$_resourceMap
Answered By - ndm
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.