Skip to content

Commit 0a02bad

Browse files
committed
Release version 1.1.1
- Fix route store bug
1 parent 1e74e81 commit 0a02bad

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

README.md

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,34 @@ CONFIGURATION
105105
class ApiController extends yidas\rest\Controller {}
106106
```
107107

108-
2. Add a pair of routes for this controller into `\application\config\routes.php` to enable RESTful API methods:
108+
2. Add and implement action methods referring by [Build Methods](#build-methods).
109+
110+
Then you could access RESTful API:
111+
112+
```
113+
https://yourname.com/resources/ajax
114+
https://yourname.com/resources/ajax/123
115+
```
116+
117+
> `resources` is Controller name
118+
119+
### Routes Setting
120+
121+
If you want to define controller as resource for URI, for example:
122+
123+
```
124+
https://yourname.com/resources
125+
https://yourname.com/resources/123
126+
```
127+
128+
You could add a pair of routes for this controller into `\application\config\routes.php` to enable RESTful API methods:
109129

110130
```php
111131
$route['resource_name'] = '[Controller]/route';
112132
$route['resource_name/(:num)'] = '[Controller]/route/$1';
113133
```
114134

115-
> You could skip this route setting if you just use `index` method of the controller.
135+
> You don't need set routes if you just use `index` method of the controller.
116136
117137
---
118138

@@ -131,11 +151,11 @@ The base RESTful API controller is `yidas\rest\Controller`, the following table
131151
|DELETE |/photos |delete |Delete the entire collection. |
132152

133153

134-
### Overrided Methods:
154+
### Build Methods:
135155

136156
You could make a resource controller by referring the [Template of Resource Controller](https://github.com/yidas/codeigniter-rest/blob/dev/examples/RestController.php).
137157

138-
The following methods with arguments could be overrided when you need to defind response and open it:
158+
The following methods with arguments could be add when you need to defind response and open it:
139159

140160
```php
141161
public function index() {}
@@ -149,6 +169,39 @@ protected function delete($resourceID=null) {}
149169
>
150170
> `$resourceID` is the addressed identity of the resource from request
151171
172+
### Custom Routes & Methods
173+
174+
The default routing methods are below setting:
175+
176+
```php
177+
protected $routes = [
178+
'index' => 'index',
179+
'store' => 'store',
180+
'show' => 'show',
181+
'update' => 'update',
182+
'delete' => 'delete',
183+
];
184+
```
185+
186+
You could override to defind your own routing while creating a resource controller:
187+
188+
```php
189+
class ApiController extends yidas\rest\Controller {
190+
191+
protected $routes = [
192+
       'index' => '_list',
193+
'store' => 'save',
194+
'show' => 'display',
195+
'update' => 'edit',
196+
'delete' => 'destory',
197+
];
198+
}
199+
```
200+
201+
> The keys are refered to Action of Resource Controller table.
202+
>
203+
> For example: REST list `index` action will run `_list` method.
204+
152205

153206
### Usage
154207

src/rest/Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function route($resourceID=NULL)
106106
switch ($this->request->getMethod()) {
107107
case 'POST':
108108
if (!$resourceID) {
109-
return $this->_action(['delete', $this->request->getBodyParams()]);
109+
return $this->_action(['store', $this->request->getBodyParams()]);
110110
}
111111
break;
112112
case 'PUT':

0 commit comments

Comments
 (0)