0

私は、Amazon の本を照​​会し、本のカテゴリと関連性で並べ替える検索バーを備えた Web サイトを構築しています。次のように、レイアウトにフォームを作成しました。

  {{ Form::open(array('action' => 'home/api', 'method' => 'GET', 'class' => 'search1')) }}
        {{ Form::text('booksearch', 'Search...', array('class' => 'searchinput searchbooks', 'placeholder' => 'Search...')) }}
            {{ Form::select('category', array(
                '1' => 'All Books',
                '2' => 'All Textbooks',
                '3' => 'Business & Finance Textbooks',
                '4' => 'Communication & Journalism Textbooks',
                '5' => 'Computer Science Textbooks',
                '6' => 'Education Textbooks',
                '7' => 'Engineering Textbooks',
                '8' => 'Humanities Textbooks',
                '9' => 'Law Textbooks',
                '10' => 'Medicine & Health Sciences Textbooks',
                '11' => 'Reference Textbooks',
                '12' => 'Science & Mathematics Textbooks',
                '13' => 'Social Sciences Textbooks'

            ), '1', array('class'=>'btn btn-primary')) }}

            {{ Form::select('sort', array(
                '1' => 'Relevance',
                '2' => 'Alphabetical: A to Z',
                '3' => 'Alphabetical: Z to A',
                '4' => 'Bestselling',
                '5' => 'Average customer review',
                '6' => 'Price: low to high',
                '7' => 'Price: high to low',
                '8' => 'Publication date: newer to older'

            ), '1', array('class'=>'btn btn-primary')) }}

            {{ Form::submit('Search', array('class'=>'btn btn-primary submitbook')) }}

    {{ Form::close() }}

私はこれをroutes.phpに持っています:

Route::controller('/', 'HomeController');
Route::controller('home/api', 'HomeController@Search');

私のホームコントローラーで:

public function getIndex()
{
    return View::make('home.index');
}
public function getSearch()
{
    return View::make('home.api');
}

次に、次のコードを使用して、views/home/api.blade.php の下にフォームが送信される api ファイルを設定します。

 <?php
//Enter your IDs
define("Access_Key_ID", "myaccesskeyhere");
define("Associate_tag", "x00a7-20");
//Set up the operation in the request


if(!empty($_GET['booksearch']) && !empty($_GET['category']) && !empty($_GET['sort'])) {
    $booksearch = '';
    $category = '';
    $sort = '';
    $SearchIndex = '';
    $Keywords = '';
}


function ItemSearch($SearchIndex, $Keywords){
//Set the values for some of the parameters
$Operation = "ItemSearch";
$Version = "2011-08-01";
$ResponseGroup = "ItemAttributes,Offers";
//User interface provides values
//for $SearchIndex and $Keywords

//Define the request
$request=
"http://webservices.amazon.com/onca/xml"
. "?Service=AWSECommerceService"
. "&AssociateTag=" . Associate_tag
. "&AWSAccessKeyId=" . Access_Key_ID
. "&Operation=" . $Operation
. "&Version=" . $Version
. "&SearchIndex=" . $SearchIndex
. "&Keywords=" . $Keywords
. "&Signature=" . [Request Signature]
. "&ResponseGroup=" . $ResponseGroup;
//Catch the response in the $response object
$response = file_get_contents($request);
$parsed_xml = simplexml_load_string($response);
printSearchResults($parsed_xml, $SearchIndex);
}
?>

フォームにアクセスしようとするとこのエラーが発生するため、どこが間違っているのか教えてください。

Class HomeController@Search does not exist
4

1 に答える 1

2

Route::controller()2 番目のパラメーターとして関数名を取得しません。

Route::controller('home/api', 'HomeController@Search');この行を API コントローラーに変更する必要ApiControllerがありますRoute::controller('home/api', 'ApiController');

そして、ApiController.phpフォルダにを作成できapp/controllersます。関数を作成getIndexし、検索ロジックを入れます。

于 2013-07-09T06:13:14.007 に答える