Jump to content

PHP Function Automatically


Angel Moral
 Share

Recommended Posts

$this -> context -> controller -> addJS($this -> _path . '/views/js/front.js');

add the JS code into the module's front.js which in turn has to be loaded by the module using the PS built in functions.

You need to study the PS or other modules code to understand how it supposed to work.

Share this post


Link to post
Share on other sites

i dont know where is module's front.js. I have not create a module, i created a controller in controllers/front/NadieController.php and i would link to call it in nadie.tpl. I resolve the error in syntax. Now my files look like this:

nadie.tpl (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: here i need to call NadieController,
                
                success: function (response) {
                    console.log(response);
                }
            }
    );
}
</script>
{/literal}
{/block}

 

NadieController.php

<?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();
}


}

 

Share this post


Link to post
Share on other sites

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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More