【发布时间】:2013-07-09 06:04:42
【问题描述】:
我正在开发一个网站,您可以在其中从亚马逊产品广告 API 中搜索商品。 我在views/layouts/master.blade.php 上有一个搜索框,代码如下:
{{ Form::open(array('url' => 'AmazonAPI/api.php', 'method' => 'GET')) }}
{{ Form::text('itemsearch', 'Search ...', ) }}
{{ Form::submit('Search') }}
表单正在使用以下代码发布到 api 文件:
<?php
if(isset($_GET['booksearch'])) {
/* Example usage of the 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);
?>
搜索后,您将导航到该文件,它会显示来自亚马逊的有效 xml 数据。但正如您所看到的,api 文件是我的 public/assets/AmazonAPI 文件夹中的一个 php 文件,因此在设置 xml 样式时我无法扩展我的布局。 请告诉我应该如何将我的 API 代码包含在 views/searches/index.blade.php 刀片视图中,以便我可以在其上扩展布局,例如:
@extends('layouts.mylayout')
@section('content')
//the api code goes here
@stop
还请告诉我打开表单的正确方法。
【问题讨论】:
-
你到底想做什么?你能详细说明一下吗?
-
我刚刚编辑了这个问题。请让我知道您需要澄清的地方
-
首先你为什么要把api代码放在
public/assets文件夹中?要么您无法正确解释您的问题,要么我无法理解。据我了解,您可以在任何控制器函数中调用此文件并返回具有所需结果的视图。 -
我的 api 代码在 public/assets 文件夹中,因为我无法弄清楚如何访问它们。请向我解释如何从控制器函数调用它并返回带有结果的视图。这就是答案!
标签: laravel laravel-4 amazon-product-api blade