我正在使用CakePHP進行培訓。目前我有一個問題。 我不知道如何使用json數據進行分頁。 我的應用程序將調用API並接收JSON數據。 格式看起來像CakePHP - 如何使用json數據進行分頁?
{"success":1,"films":[{"film_id":"384","title":"GROSSE WONDERFUL","description":"A Epic Drama of a Cat And a Explorer who must Redeem a Moose in Australia","release_year":"2006","language_id":"1","original_language_id":null,"rental_duration":"5","rental_rate":"4.99","length":"49","replacement_cost":"19.99","rating":"R","special_features":"Behind the Scenes","last_update":"2006-02-15 05:03:42"},{"film_id":"984","title":"WONDERFUL DROP","description":"A Boring Panorama of a Woman And a Madman who must Overcome a Butler in A U-Boat","release_year":"2006","language_id":"1","original_language_id":null,"rental_duration":"3","rental_rate":"2.99","length":"126","replacement_cost":"20.99","rating":"NC-17","special_features":"Commentaries","last_update":"2006-02-15 05:03:42"}]}
這是PHP代碼
$data = array('filmId' => $search_data['filmId'], 'filmTitle' => $search_data['filmTitle'], 'releaseYear' => $search_data['releaseYear'], 'rating' => $search_data['rating']);
$HttpSocket = new HttpSocket();
$records = $HttpSocket->post($apiFilmsByConditions, $data);
$records = json_decode($records, true);
我嘗試使用CakePHP的PAGINATE但似乎這會從數據庫中獲取數據,而不是從API。
這是API鏈接http://oxuhandmade.com/api/get_all_films.php
你能幫助我在這種情況下?
你不分頁數組。如果你正在使用的API沒有分頁或一些等價物,你想要將數組分成塊,並將每個塊視爲一個頁面。 **實現緩存**。 – AD7six
不幸的是,api沒有分頁。你想告訴我關於實現緩存的更多細節嗎? (對不起,因爲我在CakePHP中很新)。 –
P.S:這是API鏈接http://oxuhandmade.com/api/get_all_films.php –