# |
Jul 3rd 2018, 09:33 |
slackebot4 |
} }); }); |
# |
Jul 3rd 2018, 09:33 |
james.phillips |
Router::prefix('api', function ($routes) { //$routes->setExtensions(['json']); $routes->prefix('v1', function ($routes) { //valid api routes $API_RESOURCES = [ 'CrmContacts', 'CrmEvents', ]; foreach ($API_RESOURCES as $apiResource) { $routes->resources($apiResource, [ 'inflect' => 'dasherize' ]); |
# |
Jul 3rd 2018, 09:32 |
james.phillips |
ok.. i fixed it but im confused... |
# |
Jul 3rd 2018, 09:29 |
slackebot4 |
associated correctly....Maybe its somethign outside of this code messing it up |
# |
Jul 3rd 2018, 09:29 |
james.phillips |
If I put a typo in on purpose i get "detail": "CrmEvents is not associated with CrmEventSubtype" Correct...If I put the correct name in I get A route matching \"array (\n 'controller' => 'CrmEventSubtypes',\n '_method' => 'GET',\n 'action' => 'view',\n 0 => 2,\n 'prefix' => 'api/v1',\n 'plugin' => NULL,\n '_ext' => NULL,\n)\" could not be found. ...... Thou....futher down the debug I can see event data with the subtype data |
# |
Jul 3rd 2018, 09:26 |
james.phillips |
Do I need to tell my api CrmEvents controller where the CrmEventsSubypes model is...I assumed it would already know |
# |
Jul 3rd 2018, 09:20 |
josbeir |
@tim hahaha |
# |
Jul 3rd 2018, 09:18 |
james.phillips |
there isnt a CrmEventSubtypes controller as its just a model... Its a related to CrmEvents and I have a controller within the api codebase for CrmEvents... Events model is working so I assume $event->getSubject()->query->contain([ 'CrmEventSubtypes', ]); would just bring back that related data |
# |
Jul 3rd 2018, 09:16 |
bernat |
Ok, thanks. I'm doing it but some piece is missing. |
# |
Jul 3rd 2018, 09:15 |
bernat |
Thanks @neon1024. So I presume Cakephp has no support for this. |
# |
Jul 3rd 2018, 09:15 |
neon1024 |
I don’t know how to use the Response object to stream, but I bet you can. Probably best check out the PSR7 standard to see what the functionality is |
# |
Jul 3rd 2018, 09:15 |
neon1024 |
This is what I used, and I streamed directly from the Controller, without using the Response object |
# |
Jul 3rd 2018, 09:14 |
neon1024 |
https://www.sitepoint.com/php-streaming-output-buffering-explained/ |
# |
Jul 3rd 2018, 09:14 |
bernat |
I know how to do it without using the response object but I'm wondering how to use it for that if possible. |
# |
Jul 3rd 2018, 09:14 |
bernat |
but no response object |
# |
Jul 3rd 2018, 09:13 |
neon1024 |
No, I used a Cake Controller |
# |
Jul 3rd 2018, 09:13 |
james.phillips |
I assume if i do query->contain([ then it looks at related models rather than controllers |
# |
Jul 3rd 2018, 09:13 |
bernat |
So you used vanilla PHP for that, did you? |
# |
Jul 3rd 2018, 09:13 |
neon1024 |
@bernat I did it once for a Javascript stream, and I just used the `ob_flush` methods, let me see if I can find the code |
# |
Jul 3rd 2018, 09:13 |
james.phillips |
thanks @bravo-kernel. The tables and entites are setup and work if I go throu the main app rather than the api... The api has its own versions of the some of the controllers.. I will have a think |
# |
Jul 3rd 2018, 09:12 |
bernat |
There's a CallbackStream example but I think it returns the full content in one call. |
# |
Jul 3rd 2018, 09:11 |
bernat |
Yes |
# |
Jul 3rd 2018, 09:11 |
neon1024 |
Oh, you want to stream the file? |
# |
Jul 3rd 2018, 09:11 |
bernat |
@neon1024, which example there allows to send the file contents as they are generated? |
# |
Jul 3rd 2018, 09:10 |
bravo-kernel |
@james.phillips make sure your tables and entities are in place and... that you have added all required controllers to the ApiResoures in routes.php |
# |
Jul 3rd 2018, 09:09 |
neon1024 |
https://book.cakephp.org/3.0/en/controllers/request-response.html#sending-files |
# |
Jul 3rd 2018, 09:08 |
bernat |
Hi. I'm trying to send a file in the http response so that it's downloaded by the browser. The file will be big and I want to send it as I'm building it. How would it be done in CakePHP3? |
# |
Jul 3rd 2018, 09:08 |
james.phillips |
and get A route matching \"array (\n 'controller' => 'CrmEventSubtypes' well CrmEventSubtypes is a model related to events so not sure why its looking as it as a controller.. |
# |
Jul 3rd 2018, 09:07 |
james.phillips |
I added $this->Crud->on('beforeFind', function (Event $event) { $event->getSubject()->query->contain([ 'CrmEventSubtypes', ]); }); |
# |
Jul 3rd 2018, 09:01 |
james.phillips |
im getting a werid error that implies ive done something stupid elsewhere... |
# |
Jul 3rd 2018, 08:59 |
tim |
Both should work anyway |
# |
Jul 3rd 2018, 08:59 |
james.phillips |
Im sure ive look there and didnt find anything and you found it in 2 secs....I'm getting too old |
# |
Jul 3rd 2018, 08:58 |
james.phillips |
@tim amazing i was looking at http://crud.readthedocs.io/en/latest/listeners/related-models.html and getting confused |
# |
Jul 3rd 2018, 08:57 |
tim |
https://crud-json-api.readthedocs.io/en/latest/api-usage-advanced/inclusion.html |
# |
Jul 3rd 2018, 08:56 |
james.phillips |
now Im just working out how to return related models... |
# |
Jul 3rd 2018, 08:56 |
james.phillips |
@tim thanks I was missing return $this->Crud->execute(); |
# |
Jul 3rd 2018, 08:55 |
tim |
@josbeir Btw I saw you highfived your wife :P I put my gf in the garden because she's bad luck when it comes to football. Last EK, every time she left for the bathroom or to get a drink, Belgium scored. So at 0-2 she left and we won. Glad to do my part |
# |
Jul 3rd 2018, 08:53 |
slackebot4 |
Array ( [header] => Content-Type: application/x-www-form-urlencoded api-key: foo Connection: close User-Agent: CakePHP [method] => POST [protocol_version] => 1.1 [ignore_errors] => 1 [timeout] => 30 [max_redirects] => 0 ) ``` |
# |
Jul 3rd 2018, 08:53 |
slackebot4 |
[ssl_verify_host] => 1 [redirect] => [headers] => Array ( [Content-Type] => application/json [api-key] => foo ) ) ``` And the config of `Cake\Http\Client\Adapter\Stream` ``` [_adapter:protected] => Cake\Http\Client\Adapter\Stream Object ( [_context:protected] => Resource id #299 [_contextOptions:protected] => |
# |
Jul 3rd 2018, 08:53 |
louis |
Good morning ! I don’t get why `Cake\Http\Client\Adapter\Stream Object` not setting the correct Header for content type. Here is my config of Http Client : ``` [_config:protected] => Array ( [host] => [port] => [scheme] => https [timeout] => 30 [ssl_verify_peer] => 1 [ssl_verify_peer_name] => 1 [ssl_verify_depth] => 5 |
# |
Jul 3rd 2018, 08:53 |
neon1024 |
Morning |