나는 페이지에서 많은 일을하고 있고 어딘가에서 갈등을 느끼고 있다고 생각합니다. 기본적으로 내 페이지에는 처음에 입력과 빈 div가 표시됩니다. 입력이 제공되고 제출되면 페이지가 데이터로 가득 찬 div로 새로 고쳐집니다. 사용자는이 데이터 중 일부를 선택하고 마지막으로 다시 제출할 수 있습니다.
이것이 나의 견해
{% block main %}
<div class="col-md-4">
<section class="panel panel-default">
<header class="panel-heading">
<h3 class="panel-title">Terminal</h3>
</header>
<div class="panel-body">
<form action="{{ path('NickAlertBundle_terminalSearch') }}" method="post" enctype="multipart/form-data" class="terminalForm" id="terminalForm">
<div class="row">
<div class="col-md-12">
<input type="text" class="addMargin" id="terminal_command" name="terminal_command" placeholder=">">
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-4">
<input type="submit" class="btn btn-default" id="terminal_submit" value="Submit">
</div>
</div>
</form>
</div>
</section>
</div>
<div class="col-md-8" id="terminal-window">
<table class="terminalAvailability">
{% if data is defined %}
<form action="{{ path('NickAlertBundle_terminalCreate') }}" method="post" enctype="multipart/form-data" class="terminalForm">
{% for info in data %}
<tr>
<td class="flightNumber">{{ info.flightNumber }}</td>
<td class="details">{{ info.from ~ info.to }}</td>
{% for seat, availability in info.seats %}
<td class="seatClass">
<label for="{{ seat }}">
<span>{{ seat ~ availability }}</span>
</label>
<input type="checkbox" id="{{ seat }}" name="seats[{{ info.flightNumber }}][]" style="display: none;" value="{{ seat }}" />
</td>
{% endfor %}
<td class="otherInfo">{{ info.other }}</td>
</tr>
{% endfor %}
<div class="row">
<div class="col-md-8 col-md-offset-4">
<input type="submit" class="btn btn-default" value="Submit">
</div>
</div>
</form>
{% endif %}
</table>
</div>
<div class="modal"></div>
{% endblock %}
첫 번째 div는 입력이고 두 번째 div는 데이터가 표시되고 선택되고 다시 제출되는 div입니다.
그런 다음 컨트롤러 작업이 있습니다.
public function terminalAction()
{
return $this->render('NickAlertBundle:Page:terminal.html.twig');
}
public function terminalSearchAction(Request $request)
{
try {
$terminal_command = strtoupper($request->get('terminal_command'));
$error = array();
if (!$terminal_command) {
$error[] = "Please enter the Command";
}
if (count($error)) {
echo "There were errors adding the alert.\n\n";
foreach ($error as $item) {
echo $item . "\n";
}
die();
}
$uapiService = $this->container->get('alert_bundle.api_service');
$commandData = $apiService->terminalService($terminal_command);
return $this->render('NickAlertBundle:Page:terminal.html.twig', array(
'data' => $commandData,
));
}catch (Exception $e) {
}
}
public function terminalCreateAction(Request $request)
{
try {
foreach ($request->request->get('seats') as $row) {
foreach ($row as $seat) {
var_dump($seat);
}
}
return $this->render('NickAlertBundle:Page:terminal.html.twig');
}catch (Exception $e) {
}
}
그리고 마지막으로 내 경로
NickAlertBundle_terminal:
pattern: /terminal
defaults: { _controller: NickAlertBundle:Alert:terminal }
methods: [GET]
NickAlertBundle_terminalSearch:
pattern: /terminal
defaults: { _controller: NickAlertBundle:Alert:terminalSearch }
methods: [POST]
NickAlertBundle_terminalCreate:
pattern: /terminal
defaults: { _controller: NickAlertBundle:Alert:terminalCreate }
methods: [POST]
So the page is initially displayed fine. The user then enters some input, submits it, and the response data is then displayed in the div. So this means the first two routes work perfectly. With the data in the div, the user can select some data, and then submit it. However, when this data is submitted, they are displayed with
There were errors adding the alert. Please enter the Command
This error is for the second action, and should not have anything to do with the third action. The second form has its path set to NickAlertBundle_terminalCreate so why would it cross wires with the other action?
Thanks
NickAlertBundle_terminalCreate
will always solve to NickAlertBundle_terminalSearch
, because the RouteMatcher will always match the pattern /terminal
+ method POST
to the first route with these rules.
NickAlertBundle_terminalSearch
같은 패턴을 주지 /terminal/search
않겠습니까?
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다