2014-10-30 113 views
0

我嘗試訪問我的tipos/index頁面時出現錯誤,我正在使用jerarey way generator的laravel 4框架來加速路由,控制器,模型的創建過程,等沒有關於model []的查詢結果

這是我的代碼:

路線:

Route::get('tipos/index', 
    array(
     'as' => 'index', 
     'uses' => '[email protected]') 
); 

型號:

class Tipo extends Eloquent{ 

    protected $guarded = array(); 

     public static $rules = array(
     'clave_tipo' => 'required', 
     'nombre_tipo' => 'required', 
     'status' => 'required', 
     'created_by' => 'required', 
    ); 
} 

控制器:

class TiposController extends BaseController { 

protected $tipo; 

public function index() 
    { 
     $tipos = $this->tipo->all(); 
     return View::make('tipos.index', compact('tipos')); 
    } 

Especific路線在我master.blade:

{{ link_to('tipos/index', trans('common/messages.tipos'))}} | 

index.blade:

@extends('layouts.master') 

@section('content') 
    <h1> 
     Tipos 
    </h1> 

<form name="form" id="form" method="post"> 

<a class="editar button clear" href="/sistema/crearTipo">Nuevo Tipo</a> 
    <input type="button" onclick="javascript:exportar();" value="Exportar" class="button" style="margin: 0px;"> 
    <input type="hidden" name="format" id="format" value="yy-mm-dd"> 
    <input type="hidden" name="excel" id="excel" value="false"> 
<br><br> 

<iframe name="x" height="0" width="0" style="display: none;"></iframe> 

<div class="title"> 
    <form name="form" id="form" method="post"> 
     <iframe name="x" height="0" width="0" style="display: none;"></iframe> 
     <table class="datatable" id="tipos"> 
      <thead> 
       <th>C&Oacute;DIGO</th> 
       <th>DESCRIPCI&Oacute;N</th> 
       <th>EDITAR</th> 
       <th>ELIMINAR</th> 
      </thead> 

     </table> 
    <div class="foot"> 

    </div> 
    </form> 
</div> 
@stop 

而且出現這個錯誤:照亮\數據庫\雄辯\ ModelNotFoundException 無查詢結果的模型[Tipo]。

如果有人能幫助我將不勝感激!

+0

您在數據庫中沒有記錄。在訪問視圖之前處理異常。 – 2014-10-30 16:34:17

+1

我沒有看到'''protected $ table ='';'''你在模型中! – ArjanSchouten 2014-10-30 16:37:36

+0

嗨,我添加到我的模型: protected $ table ='tipos'; 但仍然得到錯誤:模型[Tipo]沒有查詢結果。 – 2014-10-30 16:57:32

回答

1

解決了,我有tipos的兩條路線:

Route::resource('tipos', 'TiposController'); 

Route::get('tipos/index', 
    array(
     'as' => 'index', 
     'uses' => '[email protected]') 
); 

只需刪除重複的路線tipos /指數,並把在MI master.blade:

{{ link_to**_route**('tipos.index', trans({{'common/messages.tipos'))}} | 

這場衝突是因爲我需要mi主控器中的_route

謝謝!

0

您需要將Tipo模型注入控制器。

class TiposController extends BaseController { 

    protected $tipo; 

    function __construct(Tipo $tipo){ 
     $this->tipo = $tipo; 
    } 

} 

不知道爲什麼你會得到ModelNotFoundException,因爲你從未在控制器中注入模型。你的tipos表有記錄嗎?

0

我有同樣的問題。我把單索引列表放在索引路徑後面。然後我只在單個列表之前放置索引任務。然後它的工作。

Route::get('index', '[email protected]'); 

Route::get('/{task}', '[email protected]'); 

它有線但工作!