Displaying API xml data on laravel 4 blade view -
i developing website search items amazon product advertising api. have search box on views/layouts/master.blade.php following code:
{{ form::open(array('url' => 'amazonapi/api.php', 'method' => 'get')) }} {{ form::text('itemsearch', 'search ...', ) }} {{ form::submit('search') }}
the form posting api file following code:
<?php if(isset($_get['booksearch'])) { /* example usage of amazon product advertising api */ include("amazon_api_class.php"); $obj = new amazonproductapi(); $result ='' ; try { $result = $obj->searchproducts($_get['booksearch'], amazonproductapi::dvd, "title"); } catch(exception $e) { echo $e->getmessage(); } print_r($result->items); ?>
after searching navigated file , displays valid xml data amazon. can see, api file php file in public/assets/amazonapi folder hence cant extend layouts when styling xml. please let me know how should include api code in views/searches/index.blade.php blade view such can extend layout on like:
@extends('layouts.mylayout') @section('content') //the api code goes here @stop
also let me know correct way should open form.
i guide in simple , more laravel
way. can create folder libraries
under app
directory , place amazon api files in libraries
folder.
now in composer.json
add "app/your_amozon_api_library_folder_name"
in classmap ,
"autoload": { "classmap": [ "app/commands", "app/controllers", "app/models", "app/your_amozon_api_library_folder_name",
now dump autoload using composer dump-autoload or php composer.phar dump-autoload
amozon api's loaded global use.
suppose have homecontroller search method, put api codes in search method,
public function search(){ if(isset($_get['booksearch'])) { /* example usage of amazon product advertising api */ //include("amazon_api_class.php"); no need include $obj = new amazonproductapi(); $result ='' ; try { $result = $obj->searchproducts($_get['booksearch'], amazonproductapi::dvd, "title"); } catch(exception $e) { echo $e->getmessage(); } //print_r($result->items); return view::make('your view name')->with('items',$result->items); } }
Comments
Post a Comment