我在尝试理解 laravel 时遇到了一个小问题,需要一些帮助。
我有一个“约会”模型、控制器和各种视图。
模型:
class Appointment extends Eloquent {
protected $primaryKey = 'appointment_ID';
protected $fillable = array('puser_ID', 'apt_date', 'apt_time', 'purpose');
public $timestamps = false;
}
控制器:
class AppointmentsController extends BaseController{
public $restful = true;
public function getIndex(){
return View::make('appointments.index')
->with('title','Docket: Appointments & Scheduling')
->with('appointments', Appointment::OrderBy('apt_time')->get());
}
public function getView($appointment_ID){
return View::make('appointments.view')
->with('title', 'Appointment View')
->with('appointment', Appointment::find($appointment_ID));
}
public function getNew(){
return View::make('appointments.index')
->with('title', 'Add A New Appointment');
}
}
“添加新约会”查看代码:
extends('layouts.default')
@section('content')
<h1>Add A New Appointment</h1>
{{ Form::open(array('url'=>'appointments/create', 'method'=>'post')) }}
<p>
{{Form::label('puserID', 'User ID')}}<br/>
{{Form::text('puser_ID'}}
</p>
<p>
{{Form::label('aptDate', 'Appointment Date')}}<br/>
{{Form::text('apt_date')}}
</p>
<p>
{{Form::label('aptTime', 'Contact Number 1')}}<br/>
{{Form::text('aptTime'}}
</p>
<p>
{{Form::label('purpose', 'Purpose of Visit')}}<br/>
{{Form::text('purpose'}}
</p>
<p> {{Form::submit('Add Appointment')}}</p>
{{ Form::close() }}
@endsection
和我的 Routes.php 文件(已更新):
Route::get('appointments',array('as'=>'appointments','uses'=>'AppointmentsController@getIndex'));
Route::get('appointments/{appointment_ID}',array('as'=>'appointment','uses'=>'AppointmentsController@getView'));
Route::get('appointments/new',array('as'=>'newAppointment','uses'=>'AppointmentsController@getNew') );
我正在尝试使用索引视图中的按钮从“索引”视图(列出所有约会)到“添加新约会”视图:
<p>{{ HTML::linkRoute('newAppointment', 'New Appointment') }}</p>
但是当我从索引视图中按下“新约会”按钮时,代码会抛出“试图获取非对象的属性”错误。
请帮忙。
默认/布局按要求查看:
<!DOCTYPE html>
<html>
<head>
<title>{{$title}}</title>
</head>
<body>
@if(Session::has('message'))
<p style="color: green;">{{ Session::get('message') }}</p>
@endif
@yield('content')
</body>
</html>
错误信息:
ErrorException
Trying to get property of non-object
open: /Library/WebServer/Documents/laravel-master/app/storage/views/5258152a378521b65c6fd9801aedd9fd
<?php $__env->startSection('content'); ?>
<h1><?php echo e($appointment->puser_ID); ?></h1>
<p><small><?php echo e($appointment->apt_date); ?></small></p>
<p><small><?php echo e($appointment->apt_time); ?></small></p>
<p><small><?php echo e($appointment->purpose); ?></small></p>