douzhi8488 2015-01-21 19:15
浏览 32

Laravel:未定义的变量内容

I have setup a Route:

Route::resource('conferences', 'ConferencesController)

Artisan therefore shows me a route:

POST conferences | conferences.store | ConferencesController@store

When I submit a Form from the create View, I get the error that a variable in my layout file has not been defined. Undefined variable: content is shown, nothing has been posted.

I opened my form like this:

{{ Form::open(array('url' => '/conferences', 'class' => 'conference-form')) }}

And finally, my store method in ConferencesController looks like this:

public function store()
{
    $validator = Validator::make(Input::all(), Conference::$rules);

    if($validator->passes()){
        $conference = new Conference();
        $conference->title = Input::get('title');
        $conference->description = Input::get('description');
        $conference->location = Input::get('location');
        $conference->plannedTime = Input::get('plannedTime');
        $conference->save();

        Mail::pretend();
        Mail::send('emails.conference.create', ['title' => Input::get('title'), 'location' => Input::get('location'), 'plannedTime' => Input::get('plannedTime')], function($message){
            $message->to('email')->subject('Een nieuw evenement is gemaakt.');
        });

        Redirect::to('/conferences')->with('message', 'Nieuw event is aangemaakt!');
    } else {
        Redirect::to('/')->with('message', 'Iets ging mis');
    }
}

How do I fix this error?

** EDIT: Added create method **

public function create(){
    $this->layout->content = View::make('conferences.create');
}
  • 写回答

1条回答 默认 最新

  • doz95923 2015-01-21 19:53
    关注

    This should be really straight forward. In your views directory we usually have a folder called layouts where we put the page structure something like:

    // default.blade.php
    <html>
     <head> </head>
     <body>
       @yield('content'); // this is where your views will be loaded
     </body>
    </html>
    

    then in your case you should create a conferences folder and then a file create.blade.php in it.

    @extends('layouts.default')
    @section('content')
      // your forms etc
    @stop
    

    And in your create method inside ConferencesController

    public function create() {
     return View::make('conferences.create');
    }
    

    And one last thing, when you try to send the email you should be passing an email address inside the to() function and you are passing a string

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?