2016-12-21 5 views
1

私は最初のUserfrostingアプリを作成していますが、いくつかの簡単なことを試していますが、最初のハードルに落ちています。Userfrosting - ログにエラーのない空白の画面を投稿する

CREATE TABLE `uf_band` (
`id` int(11) NOT NULL AUTO_INCREMENT, 
`band_name` text NOT NULL, 
`band_description` longtext NOT NULL, 
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 
`modified_at` timestamp NULL DEFAULT NULL, 
PRIMARY KEY (`id`) 
) 

initialize.php::ルートの

$table_band = new \UserFrosting\DatabaseTable($app->config('db')['db_prefix'] . "band", [ 
    "band_name", 
    "band_description", 
    "created_at", 
    "modified_at" 
]); 

のindex.php:

$app->get('/bands/new/?', function() use ($app) { 
    $controller = new UF\BandController($app); 
    return $controller->newBand(); 
}); 

新しいバンド私は、データベーステーブルにバンドを追加してフォームを作成しようとしていますGETを使用してフォームを正常に動作します。 BandController.php

public function newBand(){ 
    if (!$this->_app->user->checkAccess('uri_bands')){ 
     $this->_app->notFound(); 
    } 
    $this->_app->render('bands/new.twig', []); 
} 

と私がテストしnewBandコントローラにこれを追加した場合、私は大丈夫です新しいバンドのフォームをロードするとき、それはデータベースへの書き込み:

$new_band = new Band([ 
     "band_name" => "band_name", 
     "band_description" => "band_description" 
    ]); 
    $new_band->save(); 
    $id = $new_band->id; 

問題があります投稿を使用して保存します。値をハードコードしてPOSTデータを読み込もうとしても、空白の画面しか表示されません。 Apacheのerror.logにには、エラーメッセージと何もありません:

public function saveBand(){ 
    $new_band = new Band([ 
     "band_name" => "band_name", 
     "band_description" => "band_description" 
    ]); 
    $new_band->save(); 
    $id = $new_band->id; 
} 

私は私のPOSTルートを交換する場合

のindex.php

$app->post('/bands/new/?', function() use ($app) {  
    $controller = new UF\BandController($app); 
    return $controller->saveBand(); 
}); 

BandController.php

$app->post('/bands/new/?', function() use ($app) {  
    echo 'post'; 
}) 

まだ空白の画面しか表示されません。任意の考えのための

{% extends "layouts/layout-dashboard.twig" %} 

{% set page_group = "dashboard" %} 

{% block page %}  
    {% set page = page | merge({ 
     "title"   : "Add New Band", 
     "description" : "" 
    }) %} 
    {{ parent() }} 
{% endblock %} 

{% block content %} 
<h1>{{page.title}}</h1> 
<p>{{page.description}}</p> 

<div class="row"> 
    <div class="col-lg-6"> 
     <div class="panel panel-primary"> 
      <div class="panel-heading"> 
       <h3 class="panel-title"><i class="fa fa-users"></i>Add New Band</h3> 
      </div> 
      <div class="panel-body"> 
       <form class="form-horizontal" role="form" name="bands" action="{{site.uri.public}}/bands/new" method="post"> 

        <div class="form-group"> 
         <label for="input_band" class="col-sm-4 control-label">Band Name</label> 
         <div class="col-sm-8"> 
          <input type="text" id="input_title" class="form-control" name="band_name" placeholder="Please enter the band name"> 
          <!--<p class="help-block">Enter the band name here</p>--> 
         </div> 
        </div> 

        <div class="form-group"> 
         <label for="input_title" class="col-sm-4 control-label">Description</label> 
         <div class="col-sm-8"> 
          <textarea type="text" id="input_title" class="form-control" name="band_description" placeholder="Please enter a description of the band. This may be displayed publically"></textarea> 
          <!--<p class="help-block">This will become the new title for all users in the selected group.</p> --> 
         </div> 
        </div> 

        <div class="form-group"> 
         <label for="input_group" class="col-sm-4 control-label">Genre</label> 
         <div class="col-sm-8"> 
          <select id="input_group" class="form-control select2" name="genre_id"> 
           {% for group in groups %} 
            <option value="{{group.id}}">{{group.name}}</option> 
           {% endfor %} 
          </select> 
         </div> 
        </div> 

        <div class="form-group text-center"> 
         <button type="submit" class="btn btn-success text-center">Add Band</button> 
        </div> 
       </form> 
      </div> 
     </div> 
    </div> 
</div> 

{% endblock %} 
{% block page_scripts %} 
    <script> 

$(document).ready(function() { 
    // Load the validator rules for this form 
    var validators = {{validators | raw}}; 
    ufFormSubmit(
     $("form[name='add_band']"), 
     validators, 
     $("#userfrosting-alerts"), 
     function(data, statusText, jqXHR) { 
      // Reload the page on success 
      window.location.reload(true); 
     } 
    ); 
}); 

</script> 
{% endblock %} 

ありがとう:私は、問題は、この前だと思いますけれどもここ

はバンド/ new.twigです。エラーメッセージが表示されないので、これは私をうまくやってくれます!

答えて

3

あなたはcsrfトークンを忘れてしまったようです。

あなたは、この非表示の入力フィールドを追加することができます

<input type="hidden" name="{{csrf_key}}" value="{{csrf_token}}">

here続きを読むに。

+0

ありがとうございます - 私のバリデータは、私のjavascriptを壊しているnew.twigのこの行で正しくピックアップされていないようです: '' 'var validators = {{validators |生)}; '' '' –

+0

うん!ところで、[ブラウザコンソール](https://learn.userfrosting.com/background/client-side)を使ってJavascriptエラーをデバッグすることができます。 – alexw

関連する問題