Php 非对象误差的拉威尔性质

Php 非对象误差的拉威尔性质,php,laravel,laravel-4,Php,Laravel,Laravel 4,我在试图理解拉雷维尔时遇到了一个小问题,需要一些帮助 我有一个“约会”模型、控制器和各种视图 型号: class Appointment extends Eloquent { protected $primaryKey = 'appointment_ID'; protected $fillable = array('puser_ID', 'apt_date', 'apt_time', 'purpose'); public $timestamps = false;

我在试图理解拉雷维尔时遇到了一个小问题,需要一些帮助

我有一个“约会”模型、控制器和各种视图

型号:
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
我正在尝试使用索引视图中的按钮从“索引”视图(列出所有约会)转到“添加新约会”视图:

<p>{{ HTML::linkRoute('newAppointment', 'New Appointment') }}</p>
{{HTML::linkRoute('newAppointment','newAppointment')}

但是当我从索引视图中按下“newappointment”按钮时,代码抛出了“试图获取非对象的属性”错误

请帮忙

按要求显示默认/布局视图:

<!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>

{{$title}}
@if(会话::has('message'))

{{{Session::get('message')}

@恩迪夫 @产量(‘含量’)
错误消息:

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>
ErrorException
正在尝试获取非对象的属性
打开:/Library/WebServer/Documents/laravel master/app/storage/views/5258152A378521B65C6FD9801AED9FD

getNew()中的视图不应该是索引中的不同视图?例如:
View::make('appointments.new')
View::make('appoints.index')的实例

编辑 您在
表单::text()
中有sintax错误。您必须关闭所有
表单::text()
中的括号。如果无法解决此问题,请发布您的
布局/默认视图

编辑2 不应该

Route::get('appointments/new',array('as'=>'newAppointment','uses'=>'AppointmentsController@getNew')    );
实例:

Route::get('appointments/new',array('as'=>'newAppointment','uses'=>'UsersController@getNew')    );
?迁移:后

<?php
} 控制器:

public function show($id)
{
    $post = Post::find($id)->toArray();
    return View::make('detail', compact('post'));
}
显示:detail.blade.php

@extends("layouts.master")

@section('content')
{{$post['id']}}
{{$post['title']}}
@stop

返回的值是对象。可以使用toArray()将对象返回到数组()。当您获取值以使用刀片模板显示元素时,如{{$post['id']}

引发错误的行/文件是哪行/文件?日志没有明确说明,但在显示的代码中,它看起来是“appointment.view”代码。此代码只输出4个字段,如。。。“./app/storage/views/5258152a…..fd:3”请向我们显示沉闷的错误消息。或者,您是否有可用的错误日志(可能是的)-您的开发服务器环境是什么?我已将其附加到上面的内容中。开发服务器环境是使用PHP5.4.4的MAMP。是的,它应该是“appoints.new”。我把它改成测试用的。但这并不能解决问题。谢谢你指出这一点。我做了一些改变,但并没有解决问题。布局/默认视图:{{$title}}@if(Session::has('message'))

{{Session::get('message')}}

@endif@yield('content')代码似乎引用了我创建的早期模型。我有另一个模型、控制器和一组视图,我正在尝试用类似的功能创建一个不同的模型。为什么它引用了旧的模型?只是引用了。问题仍然存在。我把它作为appointmentsController@getNew在我这里的代码中。这个问题仍然存在。我做了一些更改,试图隔离问题。这个UsersController@getNew是我所做的改变的残余。我恢复了一切。
/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('posts', function(Blueprint $table)
    {
        $table->increments('id');
        $table->string('title');
        $table->string('read_more');
        $table->string('content');
        $table->unsignedInteger('comment_count');
        $table->timestamps();
        $table->engine = 'MyISAM';
    });
    DB::statement('ALTER TABLE posts ADD FULLTEXT search(title, content)');
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
   Schema::table('posts', function(Blueprint $table){
       $table->dropIndex('search');
       $table->drop();
   });
}
public function show($id)
{
    $post = Post::find($id)->toArray();
    return View::make('detail', compact('post'));
}
@extends("layouts.master")

@section('content')
{{$post['id']}}
{{$post['title']}}
@stop