첫 번째 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 데이터를 읽지 않으려 고해도 빈 화면 만 표시됩니다. 아파치하는 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';
})
아직 빈 화면이 나타납니다.
여기 밴드의/new.twig 내가 생각하지만 문제는이 전에이다 : 어떤 생각에 대한
{% 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 행에서 제 유효 확인자가 올바르게 선택되지 않은 것으로 보입니다.'''var validators = {{validators | 원시}};'''' –
예! 그런데 [브라우저 콘솔] (https://learn.userfrosting.com/background/client-side)을 사용하여 자바 스크립트 오류를 디버깅 할 수 있습니다. – alexw