私は初心者の開発者で、Laravel を使用してコーディングを始めました。
私の問題は、メニューをクリックしてこのコンテンツを変更可能にできないことです。
この状況で Ajax を使用する方法について、私は本当に混乱しています。
私のroutes.php:
Route::get('articles',array('as'=>'articles','uses'=>'articles@index'));
Route::get('author/(:any)', array('as'=>'article','uses'=>'articles@view'));
Route::get('abouts',array('as'=>'abouts','uses'=>'abouts@index'));
私のdefault.blade.php(まもなくスクリプトに含まれます)
<!DOCTYPE html>
<head>
<title>{{$title}}</title>
{{ HTML::script('js/jquery.min.js') }}
{{ HTML::script('js/ajax.js') }}
.......
</head>
<body>
........
<div id="wrapper">
<div id="page">
{{ $content }}
</div>
<!-- SIDEBAR -->
<div id="sidebar">
<div id="sidebar-content">
<ul id="menu">
<li class="current"><a href="<?php echo URL::to_route('articles'); ?>">ANASAYFA</a></li>
<li><a href="<?php echo URL::to_route('abouts'); ?>">HAKKIMIZDA</a></li>
.......
<script type="text/javascript">var BASE = "<?php echo URL::base(); ?>";</script>
</body>
</html>
私のビューは div/#content 内にあります。
私のajax.js:
$(document).ready(function() {
$('#sidebar-content ul li a').click(function(e) {
// prevent the links default action
// from firing
e.preventDefault();
// attempt to GET the new content
$.get(BASE +'#content', function(data) {
$('#content').html(data);
console.log(data);
});
})
});
私の記事コントローラー:
<?php
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());
}
public function get_view($id){
$this->layout->title = "Hizmetlerimiz";
$this->layout->content = View::make('articles.view')
->with('article',Article::find($id));
}
}