Jump to content

Llamar a front controller AJAX


Recommended Posts

Tengo un fichero llamado nadie.tpl cuyo controlador es NadieController.php, quiero que mediante una consulta de AJAX usar una función del controlador. El problema es  al introducir la url en la consulta de AJAX que no me funciona, he probado poniendo nadie, nadie.php, NadieController, NadieController.ph, etc. Los ficheros están de la siguiente manera:

nadie.tp (Ubicación: themes/classic/templates)

{extends file='page.tpl'}
{block name='page_title'}
<span class="sitemap-title">{l s='Plantilla descargable' d='Shop.Theme'}</span>
{/block}
{block name='page_content_container'}
<section>
<p><label>Introduce ancho:</label> <input type="text" id="name" name="name" maxlength="8" size="10" /></p>
<p><label>Introduce alto:</label> <input type="text" id="name" name="name" maxlength="8" size="10" /></p>
<button onclick="myFunction()">Click me</button>

<p id="demo"></p>
</section>

{literal}
<script>
function myFunction() {
  document.getElementById("demo");
  console.log("Entro myfuncion");
  $.ajax(
            {
                type: 'POST',
                data: {action:'getPDF'},
                url: No se como llamar aqui a NadieController.php,
                
                success: function (response) {
                    console.log(response);
                }
            }
    );
}
</script>
{/literal}
{/block}

NadieController.php (Ubicación: controllers/fronts)

<?php
class NadieControllerCore extends FrontController
{

public $php_self = 'nadie';

public function initContent()
{
parent::initContent();
if(isset($_POST['action']) && !empty($_POST['action'])) {
    echo "<script>console.log( 'Entro IF' );</script>";
    $action = $_POST['action'];
    switch($action) {
        case 'getPDF' : getPDF();break;
        // ...etc...
    }
}

$this->setTemplate('nadie');

}


public static function getPDF(){
ob_start();
require('vendor/fpdf/fpdf.php');
$pdf = new FPDF('P','mm',array(20,10));
$pdf->AddPage();
$pdf->Output();
}


}

 

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...