다음은 내 라우팅 파일의 일부입니다. 나는 /recipe
또는 /recipe/{id}
URL 년대를 방문 할 때마다 그러나, 나는라우트 그룹 관련 문제
클래스 레시피를 재 선언 할 수 없습니다 오류를 얻을.
Recipe는 내 모델 이름입니다. btw.
Route::group(array('before' => 'auth'), function(){
Route::any('/logout', '[email protected]');
Route::get('/recipe/add', '[email protected]');
Route::post('/recipe/add', '[email protected]');
});
Route::any('/', '[email protected]');
Route::get('/recipe', '[email protected]');
Route::get('/recipe/{id}', '[email protected]');
나는 더 이상 오류가의를 발생하지 아래로 라우팅 파일을 변경하는 경우. 그러나, URL 년대는 분명히에만 로그인 한 사람들에 의해 액세스 할 수 있습니다 의미하는 '전'=> '인증'의 영향을받습니다.
Route::group(array('before' => 'auth'), function(){
Route::any('/logout', '[email protected]');
Route::get('/recipe/add', '[email protected]');
Route::post('/recipe/add', '[email protected]');
Route::any('/', '[email protected]');
Route::get('/recipe', '[email protected]');
Route::get('/recipe/{id}', '[email protected]');
});
내가 잘못 그룹을 사용하고 있는가, 아니면 내가 뭔가를 놓친 거지.
는편집 : 는 컨트롤러 파일은 다음과 같다 :
<?
class RecipeController extends BaseController
{
protected $layout = 'layouts.home';
public function showIndex()
{
$this->layout->content = View::make('recipe.index')->with('recipes', Recipe::paginate(15));
}
public function showAdd()
{
$this->layout->content = View::make('recipe.add');
}
public function actionAdd()
{
$recipe = new Recipe;
$recipe->creator = Auth::user()->id;
$recipe->title = Input::get('name');
$recipe->serves = Input::get('serves');
if (Input::hasFile('image')){
$fileName = date('m_d_Y_h_i_s_a', time()).'__'.str_replace(' ', '', Input::file('image')->getClientOriginalName());
Input::file('image')->move('uploads', $fileName);
$recipe->image = $fileName;
}
$recipe->save();
Log::info(Input::get('method'));
foreach (Input::get('method') as $index => $item){
$method = new MethodItem();
$method->content = $item;
$method->order = $index;
$recipe->Method()->save($method);
}
return Redirect::to('/recipe')->with('message','Wrong Username or Password');
}
public function showItem($id)
{
$recipe = Recipe::findOrFail($id);
$this->layout->content = View::make('recipe.item')->with('recipe', $recipe);
}
}
그리고 모델 :
<?php
class Recipe extends Eloquent{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'recipes';
public function Creator()
{
return $this->belongsTo('User', 'creator');
}
public function Method(){
return $this->hasmany('MethodItem', 'recipe')->orderBy('order');
}
}
편집이이 방법에 문제가 나타납니다
Laravel (또는 작곡가) 자동 공급기가 작동 중입니다. 컨트롤러 런타임에서 class_exists('Recipe', false)
으로 감지 된 것처럼 래서 피 모델이 인스턴스화되지 않은 것처럼 보입니다. 그러나 class_exists('Recipe', true)
을 실행하면 오류가 발생합니다.
EDIT3
그래서 정렬 또는 내가 찾은 답은 조리법 클래스 (및 파일 이름, 플러스에 대한 모든 참조를) 이름을 변경하는 것입니다. 그런 다음 recipe.php라는 빈 파일을 만들어야했습니다. 이것은 엄청난 해킹을 느낀다. 그러나 그것은 작동한다. 그래서 지금 그것과 함께 고집 할 예정이다. 컨트롤러가 Eloquent 모델과 완전히 별개의 이름을 필요로 할까?
오류를 더 붙여 넣을 수 있습니까? 파일, 영향받은 줄? – Stromgren
전체 오류 : Symfony \ Component \ Debug \ Exception \ FatalErrorException 클래스를 다시 선언 할 수 없습니다. Recipe – Braders
오류를 일으키는 파일을 말하지 않습니까? 레시피 클래스가 붙여 넣은 코드의 어디에서든 선언되어서는 안됩니다. – Stromgren