Skip to content

Commit

Permalink
update docs according to latest dev-master
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Jul 16, 2018
1 parent 5664bf0 commit 9e76fee
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 27 deletions.
14 changes: 13 additions & 1 deletion guide/active-endpoint.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
## Active Endpoint
# Active Endpoint

Active Endpoint takes the inherited get, post, put & delete reoureces and transforms them to a task specific request types like from the REST structure defintion [See general infomrations](README.md):

|name|type|description
|----|----|-------
|index()|get|List all items `/users`.
|view($id)|get|Get a specific item `/users/$id`.
|insert(array $data)|post|Create new record `/users`.
|update($id, array $data)|put|Update an existing record `/users/$id`.
|remove($id)|delete|Remove an existing record `/users/$id`.

An Active endpoint is similar to the ActiveRecord pattern. It extends the {{luya\headless\ActiveEndpoint}} by model loading ability in order to find single and multiple data sets for a given endpoint.

Expand All @@ -21,6 +31,8 @@ class ApiUser extends ActiveEndpoint
}
```

## Retrieve data

Now you can use the `findOne()` and `findAll()` methods for the given Endpoint (ApiUser) in order to foreach all records as a model object or retrieve a single records.

```php
Expand Down
19 changes: 18 additions & 1 deletion guide/cms.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
## Get CMS Content
# LUYA CMS MODULE

When you have installed the [luya-module-cms] on your API you can also retrieve menu data and render content of a given CMS Page.

## Build a Menu (Navigation)

A very basic example of how to iterate through the menu for a given container and language id:

```php
$items = Menu::find()->container(2)->language(1)->response($client);

foreach ($items as $item) {
echo $item->item->title; // the title of the language corresponding item
echo $item->id; // the $navId
}
```

## Render CMS Content

In order to get the CMS content retrieve the page content for a given nav id and language:

Expand Down
25 changes: 2 additions & 23 deletions guide/endpoint.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Endpoint

## Basic call methods

Every endpoint has built in request methods for the current EndpointName defintion.

The basic request methods are:
The basic request methods of an Endpoint are:

|name|type|description
|----|----|-------
Expand All @@ -13,16 +11,6 @@ The basic request methods are:
|put()|put|
|delete()|delete|

Which then are inherited by the already task specific request types like from the REST structure defintion [See general infomrations](README.md):

|name|type|description
|----|----|-------
|index()|get|List all items `/users`.
|view($id)|get|Get a specific item `/users/$id`.
|insert(array $data)|post|Create new record `/users`.
|update($id, array $data)|put|Update an existing record `/users/$id`.
|remove($id)|delete|Remove an existing record `/users/$id`.

## Custom Endpoint Requests

In order to make custom endpoint requests for a given custom url with paramters, whether is post get or patch use:
Expand Down Expand Up @@ -90,16 +78,7 @@ class UserController extends \luya\admin\ngrest\base\Api

## Expand

Assumning you only want to expand for index() events you can also override the find method like this:

```php
public static function index()
{
return parent::index()->setExpand(['users', 'image']);
}
```

If you want to expand every get request you could also override `get()`:
If you want to expand every get request you can override the existing `get()` method:

```php
public static function get()
Expand Down
6 changes: 4 additions & 2 deletions guide/pagination.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Pagination

An API Response can contain pagination informations in order to only a certain amount of items for a page. The API must return the Pagination headers `X-Pagination-Total-Count`, `X-Pagination-Page-Count`, `X-Pagination-Current-Page` and `X-Pagination-Per-Page`.

## Endpoint

A pagination example with `Endpoint`:
A pagination example with `Endpoint`. Of course the API must support the Pagination X-Header data which is the default behavior for Yii Rest APIS:

```php
$client = new Client('API_TOKEN', 'http://localhost/luya-kickstarter/public_html');
Expand All @@ -24,7 +26,7 @@ A pagination example with `ActiveEndpoint`:

```php
$client = new Client('API_TOKEN', 'http://localhost/luya-kickstarter/public_html');
$response = ApiAdminLang::find()->setPage($_GET['page])->all($client);
$response = ApiAdminLang::find()->setPage($_GET['page'])->all($client);
foreach ($reponse->getModels() as $item) {
var_dump($item);
}
Expand Down

0 comments on commit 9e76fee

Please sign in to comment.