我是Laravel的新手,我创建了虚拟主机http://example.com并在此域的文件夹中安装了Laravel但是当我尝试访问此域时,我得到了这个

<?php
class Product extends Eloquent {
protected appends = array('category');
public function category()
{
return $this->belongsTo('Models\Category',
'category_id');
}
}
Run Code Online (Sandbox Code Playgroud)
如何实现呢?
我有问题laravel 4.我想处理发生的错误,404 Not Found或任何其他错误.但我想在发生此类错误时调用控制器.我试过这个:
App::missing(function($exception)
{
return Response::view('errors.404', array('error'=>$exception), 404);
});
Run Code Online (Sandbox Code Playgroud)
但实际上代码不是我的目的,我想要这样的东西:
//I know this code doesn't work, I've just wanted to show the claim
App::missing('HomeController@error');
App::error('HomeController@error');
// or ...
Run Code Online (Sandbox Code Playgroud)
有没有办法在调用特定控制器的方法时处理错误?
在Laravel 4中,我正在设置我的本地开发机器(我的笔记本电脑),然后我有我的生产服务器.
在我的/bootstrap/start.php中
$env = $app->detectEnvironment(array(
'local' => array('MacBook-Pro-2.local'),
'production' => array('ripken'),
));
Run Code Online (Sandbox Code Playgroud)
然后我在我的根目录中创建了一个.env.local.php,其中包含以下内容:
<?php
return [
// Database Connection Settings
'db_host' => '127.0.0.1',
'db_name' => 'censored',
'db_user' => 'censored',
'db_password' => 'censored'
];
Run Code Online (Sandbox Code Playgroud)
那部分有效.但是,我去了我的生产服务器并创建了同样的文件,名为.env.production.php,并且它没有加载该文件中的变量.我不知道是什么让我想到这样做,但我重命名了文件.env.php而没有"生产"的名称,它的工作原理.
因此,我的问题是,为什么.env.production.php不起作用?我认为这就是Laravel的好人们想要我命名我的各种环境文件.
如果我的网站将只允许用户查看自己提交的数据,并且从来没有数据的另一个用户已提交(即不一般"帖子"等) - 那么有没有真正在我的网站XSS风险?
我仍然会致力于XSS解决方案(如httmlspecialchars()等) - 但我很好奇攻击者是否可以通过查看自己的XSS攻击获得任何收益?
我是laravel的新手,现在就学习它.我在routes.php文件中提供以下路线
Route::resource('contacts', 'ContactsController');
Run Code Online (Sandbox Code Playgroud)
但是当我在浏览器中加载我的页面时,它会给我以下错误
Unhandled Exception
Message:
Call to undefined method Laravel\Routing\Route::resource()
Location:
/Users/zafarsaleem/Sites/learning-laravel/application/routes.php on line 35
Run Code Online (Sandbox Code Playgroud)
我的完整routes.php文件如下
Route::resource('contacts', 'ContactsController');
Route::get('/', function() //<------- This is line 35
{
return View::make('home.index');
});
Run Code Online (Sandbox Code Playgroud)
如何删除此错误?
编辑
ContactsController代码如下,我想要使用index()函数
class ContactsController extends BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
Contact::all();
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
// …Run Code Online (Sandbox Code Playgroud) 我想知道如何区分子资源中不同父资源的请求.
考虑子资源评论,由帖子和用户共享.注释控制器如何知道正确的父资源是什么?
我有这些路线:
Route::resource('posts', 'PostsController');
Route::resource('posts.comments', 'CommentsController');
Route::resource('users', 'UsersController');
Route::resource('users.comments', 'CommentsController');
Run Code Online (Sandbox Code Playgroud)
在CommentsController,我有这个功能:
public function index($parent_id) {
// return multiple comments here
}
Run Code Online (Sandbox Code Playgroud)
因此,我可能希望显示属于某个帖子的所有评论或属于用户的所有评论,但在这种情况下,如何CommentsController判断是否$parent_id引用帖子或用户?
我目前正尝试如下路线:
/account/
account_id,则用户登录; 显示他的帐户信息/account/
create,则用户想要创建帐户; 创造它/account/我的路线是这样设定的:
Route::get('account', function() {
if (Session::has('account_id'))
return 'AccountsController@show';
else
return 'AccountsController@index';
});
Route::post('account', function() {
if (Input::has('create')) {
return 'AccountsController@create';
else
return 'AccountsController@login';
)};
Run Code Online (Sandbox Code Playgroud)
这有点像我对Rails的处理,但我不知道如何指向控制器方法.我只是得到了返回的字符串.我没有在Laravel文档中找到它(我发现它很差,或者我搜索错了?)在任何其他网络教程中都没有.
我对 laravel4 很陌生,但有一些 codeigniter 背景。我尝试弄清楚如何将 url 路由到控制器方法
我的网址应该是这样的
/admin/products{controller_name}/parser{controller_method}
Run Code Online (Sandbox Code Playgroud)
比控制器
<?php namespace App\Controllers\Admin;
use App\Models\Product;
use Image, Input, Notification, Redirect, Sentry, Str;
class ProductsController extends \BaseController {
public function index()
{
return \View::make('admin.products.index');
}
public function parser()
{
return \View::make('admin.products.parser');
}
}
Route::group(array('prefix' => 'admin', 'before' => 'auth.admin'), function()
{
Route::resource('products', 'App\Controllers\Admin\ProductsController');
Route::resource('products/parser', 'App\Controllers\Admin\ProductsController@parser');
});
Run Code Online (Sandbox Code Playgroud) 所以我写了一个嵌套资源的简单应用程序:帖子和评论.当然,帖子是父母,评论是孩子,每个一对一相关.很简单.现在我想要评论索引(和创建,POST)页面生活posts/{post_id}/comments,更新(PUT)生活/posts/{post_id}/comments/{comment_id}.所以我尝试了这个:
Route::resource('posts', 'PostsController');
Route::group(array('prefix' => 'posts/{post_id}'), function() {
Route::resource('comments', 'CommentsController');
});
Run Code Online (Sandbox Code Playgroud)
但由于路由名称已注册为,因此无法正常工作posts.{post_id}.comments.create.基本上post_id占位符被计为路线的一部分,并不是很整洁.任何方式做得很好还是我应该逐个编写路由并摆脱group/Route :: resource/prefix的事情?