0

私は初心者のlaravelユーザーで、チュートリアルとドキュメントでコードを書こうとしました。サイトを開こうとすると、ローディング アニメーションが発生し、その後、メニューとコンテンツがページの両側に分割されます。メニューボタンをクリックしたときだけコンテンツ分割を変更したい。

これらは私のroutes.phpです:

Route::controller(Controller::detect());
Route::get('articles', array('uses'=>'articles@index'));
Route::get('articles/(:any)', array('as'=>'article','uses'=>'articles@view'));
Route::get('abouts', array('as'=>'abouts','uses'=>'abouts@index'));

これは私の default.blade.php メニュー部分です:

<div id="sidebar-content">
   <ul id="menu">
       <li class="current"><a href="<?php echo URL::to('articles'); ?>">ANASAYFA</a></li>
       <li><a href="<?php echo URL::to('abouts'); ?>">HAKKIMIZDA</a></li>
   </ul>
</div>

ここのリンクは正しいですか?

私のajax.js

$(document).ready( function() {
    $("#sidebar-content ul li a").click( function(e){
        e.preventDefault();
        $('#content').load(this.href);
        console.log('This href =='+this.href);
        return false;
    });
});

リンクをクリックすると、ロード アニメーションが表示され、コンテンツが表示されません。
これは私の記事コントローラーです:

class Articles_Controller extends Base_Controller {
    public $restful = true;
    public $layout = 'layouts.default';

    public function get_index(){
        $this->layout->title = "Anasayfa";
        $this->layout->content = View::make('articles.index')->with('articles',Article::order_by('id')->get());
    }
}

これらは console.logs です:

GET http://localhost/~ytsejam/laravel/public/index.php/abouts  jquery.min.js (line 4)
This href ==http://localhost/~ytsejam/laravel/public/index.php/abouts   ajax.js (line 6)
GET http://localhost/~ytsejam/laravel/public/js/basic.js?_=13446   jquery.min.js (line 4)
GET http://localhost/~ytsejam/laravel/public/index.php/abouts jquery.min.js (line 5)
This href ==http://localhost/~ytsejam/laravel/public/index.php/abouts ajax.js (line 6)
GET http://localhost/~ytsejam/laravel/public/index.php/abouts jquery.min.js (line 5)
This href ==http://localhost/~ytsejam/laravel/public/index.php/abouts jquery.min.js (line 7)

手伝って頂けますか?

4

1 に答える 1

0

メニューとコンテンツが分割された理由が見つかりませんでした。分割の問題がそこにあるように見えるので、おそらくJavascriptを読み直すことができます。

あなたのリンクについて。ドキュメントhttp://laravel.com/docs/routingを読むと、名前付きルートを使用しているため、リンクはURL::to_route('abouts')とであると予想されます。URL::to_route('articles')

また、ブレードエンジンを使用しています (ファイルの名前がdefault.blade .php であるため)。{{ URL::to_route('abouts') }}したがって、代わりに書くことができます<?php echo URL::to_route('abouts'); ?>

これがお役に立てば幸いです、Hendrik Jan

于 2012-08-12T00:39:13.087 に答える