2016-10-12 2 views
0

Ich erstellen eine Helper-Liste mit meiner Datenbank, PU-Inhalt in Feld "cont" Ich benutze TinyMCE, aber wenn ich Wert in db html Element nicht speichert speichert, wie Ich kann mein Feld mit HTML-Code schreiben? wenn i db Klasse von Prestashop verwenden kann ich htmlentities-Funktion verwenden, meine Daten zu speichern, aber ich verstehe nicht, wie diesemüssen Feldwert vor dem Einfügen in die Datenbank mit Hilfsformular

in meinem fields_form Array verwenden, arbeitet
Db::getInstance()->autoExecute(_DB_PREFIX_.'pdf_files', array(
       'content' => pSQL(htmlentities($content)) 
      ), 
       'INSERT'); 

dieser Code genau wie ich in meinem Code wollen, ich nicht wirklich wissen, wo ich

htmlentities($content) 

hier verwenden kann, ist mein Objektmodell und mein Controller

<?php 
class PdfData extends ObjectModel{ 
    public $id; 
    public $name; 
    public $cont; 
    public $head_1; 
    public $head_2; 
    public $head_3; 
    public $head_4; 
    public $head_5; 
    public $inst; 
    public $facebook; 


    /** 
    * @see ObjectModel::$definition 
    */ 
    public static $definition = array(
     'table' => 'pdf_files', 
     'primary' => 'id', 
     'fields' => array(
      'name' => array(
       'type' => 'varchar', 
       'validate' => 'isGenericName', 
       'required' => true, 
       'class' => 'lg' 
      ), 
      'head_1' => array(
       'type' => 'varchar', 
       'validate' => 'isGenericName', 
       'required' => false, 
       'class' => 'lg' 
      ), 
      'head_2' => array(
       'type' => 'varchar', 
       'validate' => 'isGenericName', 
       'required' => false, 
       'class' => 'lg' 
      ), 
      'head_3' => array(
       'type' => 'varchar', 
       'value' => 'lal', 
       'validate' => 'isGenericName', 
       'required' => false, 
       'class' => 'lg' 
      ), 
      'head_4' => array(
       'type' => 'varchar', 
       'validate' => 'isGenericName', 
       'required' => false, 
       'class' => 'lg' 
      ), 
      'head_5' => array(
       'type' => 'varchar', 
       'validate' => 'isGenericName', 
       'required' => false, 
       'class' => 'lg' 
      ), 
      'inst' => array(
       'type' => 'bool', 
       //'validate' => 'isGenericName', 
       'required' => false, 
       'class' => 'lg' 
      ), 
      'facebook' => array(
       'type' => 'bool', 
       //'validate' => 'isGenericName', 
       'required' => false, 
       'class' => 'lg' 
      ), 
      'cont' => array(
       'type' => 'text', 
       'validate' => 'isString', 
       'required' => false, 
       'class' => 'lg' 
      ), 
     ), 
    ); 
} 

class PdfListController extends ModuleAdminController{ 
    const CONTROLLER_NAME = 'PdfList'; 
    public $displayName = 'PDFer'; 

    public function __construct(){ 
     $this->bootstrap = true; 
     $this->className = 'PdfData'; 
     $this->table = 'pdf_files'; 
      //Tools::getValue('id_product'); 
     $this->fields_list = array(
      'id' => array(
       'title' => 'ID', 
       'width' => 'auto', 
       'type' => 'int' 
      ), 
      'name' => array(
       'title' => $this->l('Name'), 
       'width' => 'auto', 
       'type' => 'varchar' 
      ), 
      'cont'=>array(
       'title' => $this->l('content'), 
       'width' => 'auto', 
       'type' => 'varchar' 
      ) 

     ); 
     $this->identifier = 'id'; 
     $this->bulk_actions = array(
      'delete' => array(
       'text' => $this->l('Delete selected'), 
       'confirm' => $this->l('Delete selected items?') 
      ) 

     ); 

     parent::__construct(); 
     $this->callAction(); 
    } 
    private function callAction() { 
     $actionName = 'process' . ucfirst(trim($_GET['action'])); 

     if(method_exists($this, $actionName)) { 
      $this->$actionName(); 
     } 
    } 

    public function renderList() 
    { 
     $this->addRowAction('download'); 
     $this->addRowAction('delete'); 
     $this->addRowAction('edit'); 

     return parent::renderList(); 

    } 
    public function processDelete() 
    { 
     $sql= "DELETE FROM `"._DB_PREFIX_."pdf_files` WHERE `ps_pdf_files`.`id` = ". Tools::getValue('id'); 
     $return = Db::getInstance()->execute($sql); 
     return $return; 
    } 
    public function processDownload() 
    { 
     //var_dump(Configuration::get(pdfer::HEAD_3));die; 
     require_once _PS_MODULE_DIR_ . 'pdfer/classes/pdf/HTMLTemplatePdf.php'; 
     $sql = "SELECT * FROM "._DB_PREFIX_."pdf_files WHERE id = " . Tools::getValue('id'); 
     $pdf = new stdClass(); 
     $pdfData = Db::getInstance()->getRow($sql); 
     $pdf->cont = html_entity_decode($pdfData["cont"]); 
     $pdf->name = $pdfData["name"]; 
     $pdf->head_1 = $pdfData["head_1"]; 
     $pdf->head_2 = $pdfData["head_2"]; 
     $pdf->head_3 = $pdfData["head_3"]; 
     $pdf->head_4 = $pdfData["head_4"]; 
     $pdf->head_5 = $pdfData["head_5"]; 
     //$pdf->header = html_entity_decode($pdfData["head"]); 
     $pdf->path_logo = _PS_MODULE_DIR_.'pdfer/views/templates/images/header_logo.jpg'; 
     $pdf->path_footer = _PS_MODULE_DIR_.'pdfer/views/templates/images/footer_signature.jpg'; 
     $pdf->path_facebook = _PS_MODULE_DIR_.'pdfer/views/templates/images/facebook.jpg'; 
     $pdf->path_inst = _PS_MODULE_DIR_.'pdfer/views/templates/images/inst.jpg'; 
     $pdf->include_inst = (string)Configuration::get(pdfer::CHECK_IMAGE_INST); 
     $pdf->include_facebook = (string)Configuration::get(pdfer::CHECK_IMAGE_FACEBOOK); 
     $pdfGen = new PDF($pdf, 'Pdf', $this->context->smarty); 

     $content = $pdfGen->render(false); 

     header("ContentType: application/pdf"); 
     header("Content-disposition: attachment; filename=\"$pdf->name.pdf\""); 
     header("Content-Length: " . strlen($content)); 
     echo $content; 
     exit; 
    } 
    public function displayDownloadLink($token = null, $id, $name = null) 
    { 
     $tpl = $this->createTemplate('helpers/list/list_action_view.tpl'); 
     if (!array_key_exists('Download', self::$cache_lang)) 
      self::$cache_lang['Download'] = $this->l('Download'); 

     $tpl->assign(array(
      'href' => static::$currentIndex .'&'.$this->identifier.'='.$id.'&action=download&'.$this->table.'&token='.($token != null ? $token : $this->token), 
      'action' => self::$cache_lang['Download'], 
      'id' => $id 
     )); 

     return $tpl->fetch(); 
    } 


    /** 
    * @return string 
    */ 
    public function renderForm() { 
     // Building the Add/Edit form 

     $this->fields_value['head_1'] = (string)Configuration::get(pdfer::HEAD_1); 
     $this->fields_value['head_2'] = (string)Configuration::get(pdfer::HEAD_2); 
     $this->fields_value['head_3'] = (string)Configuration::get(pdfer::HEAD_3); 
     $this->fields_value['head_4'] = (string)Configuration::get(pdfer::HEAD_4); 
     $this->fields_value['head_5'] = (string)Configuration::get(pdfer::HEAD_5); 

     $this->fields_form = array(
      'tinymce' => true, 
      'legend' => array(
       'title' => $this->l('New Pdf') 
      ), 
      'input' => array(
       array(
        'type' => 'text', 
        'label' => $this->l('Name'), 
        'name' => 'name', 
        'class' => 'lg', 
        'required' => true, 
        'desc' => $this->l('adadada'), 
        ), 
       array(
        'type' => 'textarea', 
        'label' => $this->l('Content'), 
        'name' => 'cont', 
        //'class' => 'lg', 
        'required' => false, 
        'autoload_rte' => true, 
       ), 
       array(
        'type' => 'hidden', 
        'label' => $this->l('Content'), 
        'name' => 'head_1', 
        //'class' => 'lg', 
        'required' => false, 
        'autoload_rte' => true, 
       ), 
       array(
        'type' => 'hidden', 
        'label' => $this->l('Content'), 
        'name' => 'head_2', 
        //'class' => 'lg', 
        'required' => false, 
        'autoload_rte' => true, 
       ), 
       array(
        'type' => 'hidden', 
        'label' => $this->l('Content'), 
        'name' => 'head_3', 
        //'class' => 'lg', 
        'required' => false, 
        'autoload_rte' => true, 
       ), 
       array(
        'type' => 'hidden', 
        'label' => $this->l('Content'), 
        'name' => 'head_4', 
        //'class' => 'lg', 
        'required' => false, 
        'autoload_rte' => true, 
       ), 
       array(
        'type' => 'hidden', 
        'label' => $this->l('Content'), 
        'name' => 'head_5', 
        //'class' => 'lg', 
        'required' => false, 
        'autoload_rte' => true, 
       ), 
       array(
        'type' => 'hidden', 
        'label' => $this->l('Content'), 
        'name' => 'inst', 
        //'class' => 'lg', 
        'required' => false, 
        'autoload_rte' => true, 
       ), 
       array(
        'type' => 'hidden', 
        'label' => $this->l('Content'), 
        'name' => 'facebook', 
        //'class' => 'lg', 
        'required' => false, 
        'autoload_rte' => true, 
       ), 
      ), 
       'submit' => array(
        'title' => $this->l('Save'), 
        //'class' => 'button' 
       ) 
    ); 
     return parent::renderForm(); 
    } 
} 

here's picture, in first i enter some text, 2 i edit, but there is text only

+0

Ändern Sie zuerst das 'validate' in 'isGenericHTML'. Ich kann nicht sehr gut verstehen, was du machen willst. – sarcom

+0

Ich habe eine Form "cont", die ich mit Hilfe von TinyMCE bearbeite, wenn ich Wert von "cont" in DB speicher, dort zeigt nur Text, ohne irgendwelche HTML-Tags, wenn ich PDF-Datei mit diesem Inhalt erzeuge, gibt es nur Wörter , ohne Styling –

+0

sarcom, Validierungsfunktion nicht gefunden. isGenericHTML –

Antwort

0

Sie sollten pSQL (htmlentities ($ content)) nicht verwenden, um Inhalt in die Datenbanktabelle einzufügen.

Tye ersetzt es mit Tools :: htmlentitiesUTF8 ($ content) beim Speichern von HTML-Inhalten und verwenden Sie Tools :: htmlentitiesDecodeUTF8 ($ content), wenn Sie Daten aus der Datenbank extrahieren.

Verwandte Themen