2014-10-30 116 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]'); 

它有线但工作!