我是一个新手拉拉维尔用户,并尝试使用教程和文档编写我的代码。当我尝试打开网站时,会出现加载动画,之后,菜单和内容分成页面的任一侧。我只想在单击菜单按钮时更改内容划分。
这些是我的路线.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'));
这是我的默认.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>
这里的链接正确吗?
我的阿贾克斯.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());
}
}
这些是控制台日志:
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)
你可以帮我吗?
我找不到您的菜单和内容分开的原因。也许你可以重新阅读你的Javascript,因为在我看来,分裂问题就在那里。
至于你的链接。如果我 http://laravel.com/docs/routing 阅读文档,我希望链接URL::to_route('abouts')
和URL::to_route('articles')
,因为您使用命名路由。
并且您正在使用刀片引擎(因为您的文件被命名为 default。刀片.php)。因此,您可以写{{ URL::to_route('abouts') }}
代替<?php echo URL::to_route('abouts'); ?>
希望这有什么帮助,亨德里克·扬