Ich habe nach Dokumentation zu diesem Problem gesucht. Aber fand keinen Wunsch.Prestashop 1.6: Erstellen und Senden von benutzerdefinierten Formular mit Admin-Controller
Ich weiß, wie man Admin-Vorlage mit Admin-Controller laden. ich ein Formular mit
<form action="{$link->getModuleLink('pushnotification', 'AdminPushNotification', [], true)|escape:'html'}" method="post">
Here "pushnotification" geschaffen haben, ist mein Modulnamen und "AdminPushNotification" name mein Admin-Controller ist.
wenn ich einreichen getroffen es http://example.com/en/module/pushnotification/AdminPushNotification URL geht, die somit keine gültige URL ist 404 Seite
bekommen Aber ich möchte das Formular abzuschicken und in der gleichen Seite zu bleiben.
Ich weiß nicht, wie Sie die Einreichung von Formularen in Admin Controller einreichen und bearbeiten.
Vielen Dank im Voraus
Struktur Meine Moduldatei: pushnotification Controller Admin AdminPushnotification.php Ansichten Vorlagen Admin pushnotificationform.tpl
Code My Admin Controller:
<?php
class AdminPushNotificationController extends ModuleAdminControllerCore
{
public function __construct() {
$this->bootstrap = true;
parent::__construct();
}
public function initContent()
{
parent::initContent();
$smarty = $this->context->smarty;
$this->context->smarty->assign(array(
'msg' => "",
'title' => ""
));
$content = $smarty->fetch(_PS_MODULE_DIR_ . 'pushnotification/views/templates/admin/pushnotificationform.tpl');
$this->context->smarty->assign(array(
'content' => $this->content . $content
));
}
public function postProcess()
{
if (Tools::isSubmit('sendTokenMessage'))
{
$title = Tools::getValue('title');
$msg = Tools::getValue('message');
$content = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'pushnotification/views/templates/admin/pushnotificationform.tpl');
$this->context->smarty->assign(array(
'content' => $this->content . $content,
'msg' => $msg,
'title' => $title
));
}
}
public function sendMessage($title,$msg)
{
$sql = " Select Token From Token";
$result = DB::getInstance()->execute($sql);
foreach($result as $row) {
$message = array("title" => $title, "text"=> $msg);
$message_status = send_notification($row["token"], $message);
}
return $message_status;
}
}
und meine pushnotificationform.tpl Code:
<div>
{if $msg!=""}
<p>{$msg}</p>
{/if}
</div>
<form action="{$link->getAdminLink('pushnotification', 'AdminPushNotification', [], true)|escape:'html'}" method="post">
<div style="padding-bottom:10px;" class="form-group">
<label for="" class="control-label col-lg-6">Title</label>
<div class="col-lg-6">
<input class="form-control input-lg" type="text" name="title" />
</div>
</div>
<div class="form-group">
<label for="" class="control-label col-lg-6">Message</label>
<div class="col-lg-6">
<textarea name="message" class="form-control" style="min-width: 100%"></textarea>
</div>
</div>
<input type="submit" name="sendTokenMessage" value="send" class="btn btn-default" />
</form>
Ich habe zu $ link-> getAdminLink geändert. Jetzt 404 Seite bekommen. Kannst du mir etwas über die Handhabung des Formulars im Admin-Controller geben? –
öffentliche Funktion postProcess() { if (Extras :: isSubmit ('sendTokenMessage')) { $ title = Extras :: getValue ('title'); $ msg = Extras :: getValue ('Nachricht'); $ content = $ this-> context-> smarty-> holen (_PS_MODULE_DIR_. 'Pushnotification/views/templates/admin/pushnotificationform.tpl'); $ this-> context-> smarty-> zuweisen (array ( 'content' => $ this-> content. $ Content, 'msg' => $ msg, 'title' => $ title )) ; } } –
Leider glaube ich nicht, es gibt etwas anderes als [dies] (http://blog.belvg.com/how-to-use-the-class-admincontroller-in-prestashop.html) aber wenn Sie können Ihren gesamten Controller-Code zeigen, ich könnte Ihnen weiterhelfen. – TheDrot