将资产文件链接到Laravel4中的视图 [英] Linking asset files to views in Laravel4
问题描述
我是新手,学习laravel 4来创建应用程序.我正在尝试使用laravel刀片将twitter bootstrap3文件链接到视图.我安装了一个新的laravel应用程序文件夹.
Hi I am newbie learning laravel 4 for creating an application. I am trying to link twitter bootstrap3 files to views using laravel blades. I installed a new laravel application folder.
要从URL路径中删除public,我删除了public文件夹中的所有文件,并将其保留在public文件夹之外.我根据index.php文件中的上述更改更改了路径.根据我的需要,我在应用程序中将有两个部分,一个部分用于用户,另一部分用于管理员.
To remove public from url path i removed all the file in public folder and kept outside of public folder. I changed paths as per the above changes in index.php file.As per my needs i will have two sections in my application one is for users and another is for admin.
为此,我如下更改了route.php文件.
So for this i changed my routes.php file like this below.
Route::get('/', 'HomeController@index');
Route::get('/admin', 'AdminController@index');
我创建了两个控制器,一个用于用户,另一个用于管理员,分别名为HomeController和AdminController.这两个文件如下所示.
I created two controllers one for users and another for admin named as HomeController and AdminController. Both files will look like below.
HomeController for Users
<?php
class HomeController extends BaseController {
public function index()
{
return View::make('index');
}
}
AdminController for admin section
<?php
class AdminController extends BaseController {
public function index()
{
return View::make('admin.index');
}
}
现在我在admin部分的views文件夹下创建了admin文件夹.那就是为什么当URL像这样的http://localhost/laravel/admin
时,我保持admin.index
来调用管理索引页面的原因.
Now i created admin folder under views folder for admin section. Thats why i kept admin.index
to call admin index page when the url is like this http://localhost/laravel/admin
.
现在我创建了assets文件夹,其中具有用于css文件的css文件夹,用于js文件夹的js文件和用于图像的图像文件夹.我想将这些CSS和JS文件链接到我的管理员视图.因此,我创建了如下的layout.blade.php
.
Now i created assets folder which has css folder for css files, js folder js files and images folder for images. I want to link these css and js files to my admin view. So i created a layout.blade.php
like below.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Laravel</title>
<link rel="stylesheet" href="{{ asset('assets/css/bootstrap.css') }}">
<link rel="stylesheet" href="{{ asset('assets/css/style.css') }}">
<script type="text/javascript" src="{{ asset('assets/js/jquery-1.10.1.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('assets/js/bootstrap.min.js') }}"></script>
</head>
<body>
@yield('content')
</body>
</html>
此后,我将视图更改为如下所示.
After this i changed my view into like this below.
@extends('layout')
@section('content')
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<p>Here Comes Admin Section</p>
</div>
</div>
</div>
@stop
但是资产没有链接.我可以知道我要去哪里了吗.
But the assets are not linking. May i know where i am going wrong.
推荐答案
如果您的资产文件夹位于laravel的公共文件夹中,则请使用以下命令:
If your asset folder is inside public folder of laravel then user this:
假设您的文件夹结构为 public/assets/css/bootstrap :然后
Suppose your folder structure is public/assets/css/bootstrap: Then
<script src="{{ URL::asset('assets/css/bootstrap.css') }}"></script>
这篇关于将资产文件链接到Laravel4中的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!