xiaohutai / jsonapi

[Bolt Extension] JSON API for Bolt CMS
https://market.bolt.cm/view/bolt/jsonapi
MIT License
55 stars 18 forks source link

Cannot include individual fields #53

Closed luispabon closed 7 years ago

luispabon commented 7 years ago

GET http://localhost:17000/api/pages?include=page.slug,page,title,page.image

Uncaught Exception: StorageException

StorageException in Relations.php line 205: 
Unable to load collection values. Ensure that EntityManager is set on Bolt\Storage\Collection\Relations

     * {@inheritdoc}
     */
    public function offsetGet($offset)
    {
        if ($this->em === null) {
            throw new StorageException('Unable to load collection values. Ensure that EntityManager is set on ' . __CLASS__);
        }
        $collection = new LazyCollection();
        $proxies = $this->getField($offset);
        foreach ($proxies as $proxy) {
            $collection->add(new EntityProxy($proxy->to_contenttype, $proxy->to_id, $this->em));

Google this Exception

Stack trace

# 1 Bolt\Storage\Collection\Relations::offsetGet("title") 
[root]/extensions/vendor/bolt/jsonapi/src/Action/FetchAction.php # line 74
# 2 Bolt\Extension\Bolt\JsonApi\Action\FetchAction::fetchIncludes([array], [array], ParameterCollection) 
[root]/extensions/vendor/bolt/jsonapi/src/Action/ContentListAction.php # line 43
# 3 Bolt\Extension\Bolt\JsonApi\Action\ContentListAction::handle("pages", Request, ParameterCollection) 
# 4 call_user_func_array([array], [array]) 
[root]/vendor/symfony/http-kernel/HttpKernel.php # line 144
# 5 Symfony\Component\HttpKernel\HttpKernel::handleRaw(Request, 1) 
[root]/vendor/symfony/http-kernel/HttpKernel.php # line 64
# 6 Symfony\Component\HttpKernel\HttpKernel::handle(Request, 1, [true]) 
[root]/vendor/silex/silex/src/Silex/Application.php # line 586
# 7 Silex\Application::handle(Request) 
[root]/vendor/silex/silex/src/Silex/Application.php # line 563
# 8 Silex\Application::run(Request) 
[root]/vendor/bolt/bolt/src/Application.php # line 93
# 9 Bolt\Application::run() 
[root]/public/index.php # line 12
Request data

content (empty)
languages   en_US 
en
charsets    (empty)
encodings   gzip 
deflate 
sdch 
br
acceptableContentTypes  text/html 
application/xhtml+xml 
image/webp 
application/xml 
*/*
pathInfo    /api/pages
requestUri  /api/pages?include=page.slug,page,title,page.image
baseUrl (empty)
basePath    (empty)
method  GET
Attributes

_controller (empty) 
handle
contentType pages
_route  jsonapi.listContent
_route_params   contentType => pages
zone    frontend
parameters  search => (empty) 
contentType => (empty) 
page => (empty) 
sort => (empty) 
filters => (empty) 
contains => (empty) 
includes => (empty) 
fields => (empty)
Query

include page.slug,page,title,page.image
Cookies

PHPSESSID   b4rifvi0i865fn5hrpsb51sba1
_ga GA1.1.1965330181.1495195827
Phpstorm-346801e0   c3506b39-cb30-4224-a11e-093063ea3ce7
bolt_authtoken_4e22597a41e739ae2170528a44cd47d5 (Click to reveal sensitive data)
bolt_session_4e22597a41e739ae2170528a44cd47d5   (Click to reveal sensitive data)
Headers

cookie  (Click to reveal sensitive data)
accept-language en-US,en;q=0.8
accept-encoding gzip, deflate, sdch, br
dnt 1
accept  text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
user-agent  Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.114 Safari/537.36 Vivaldi/1.9.818.50
upgrade-insecure-requests   1
connection  keep-alive
host    localhost:17000
content-length  (empty)
content-type    (empty)
x-php-ob-level  (empty)
Server

HOSTNAME    0a252a935985
HOME    /var/www
TERM    linux
PATH    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD /application
USER    www-data
HTTP_COOKIE (Click to reveal sensitive data)
HTTP_ACCEPT_LANGUAGE    en-US,en;q=0.8
HTTP_ACCEPT_ENCODING    gzip, deflate, sdch, br
HTTP_DNT    1
HTTP_ACCEPT text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
HTTP_USER_AGENT Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.114 Safari/537.36 Vivaldi/1.9.818.50
HTTP_UPGRADE_INSECURE_REQUESTS  1
HTTP_CONNECTION keep-alive
HTTP_HOST   localhost:17000
REDIRECT_STATUS 200
SERVER_NAME (empty)
SERVER_PORT 80
SERVER_ADDR 172.22.0.6
REMOTE_PORT 45692
REMOTE_ADDR 172.22.0.1
SERVER_SOFTWARE nginx/1.13.0
GATEWAY_INTERFACE   CGI/1.1
REQUEST_SCHEME  http
SERVER_PROTOCOL HTTP/1.1
DOCUMENT_ROOT   /application/public
DOCUMENT_URI    /index.php//api/pages
REQUEST_URI /api/pages?include=page.slug,page,title,page.image
SCRIPT_NAME /index.php
CONTENT_LENGTH  (empty)
CONTENT_TYPE    (empty)
REQUEST_METHOD  GET
QUERY_STRING    include=page.slug,page,title,page.image
PHP_VALUE   error_log=/var/log/nginx/application_php_errors.log
SCRIPT_FILENAME /application/public/index.php
FCGI_ROLE   RESPONDER
PHP_SELF    /index.php
REQUEST_TIME_FLOAT  (empty)
REQUEST_TIME    (empty)
Session

authentication  (Click to reveal sensitive data)
_csrf/bolt  (Click to reveal sensitive data)
stack   (empty)
_csrf/form  (Click to reveal sensitive data)
Raistlfiren commented 7 years ago

Thanks for reporting the bugs @luispabon! I will take a look at the issues and try to fix them soon.

luispabon commented 7 years ago

:+1:

Raistlfiren commented 7 years ago

@luispabon Please try the following - /pages?include=page&fields[page]=slug,image&fields[pages]page,title

xiaohutai commented 7 years ago

Cleaning up some issues.

GET http://localhost:17000/api/pages?include=page.slug,page,title,page.image

I suppose you intended: page.title instead of page,title:

-page.slug,page,title,page.image
+page.slug,page.title,page.image

Use this:

/pages?include=page&fields[page]=slug,image&fields[pages]=page,title