How to use materialize features in php with javascript

0

Is it possible to use materialize in a php file next to javascript? in return of a php function I want to issue a Materialize.toast (); but I'm not getting it, I already referenced the file that has all css calls and materialize in php and even then it did not work, I'm trying to do as follows in the php file.

<?php include("../head.php"); // chamadas css e materialize

  echo '<script>Materialize.toast(" teste ", 4500, "blue rounded");</script>'
?>
    
asked by anonymous 23.11.2018 / 17:42

1 answer

0

You can do this with session variables.

File with your function:

<?php

...
// Inicia a sessão
session_start();
// Define a variável de sessão com o título do alerta
$_SESSION['toast']['title'] = 'Teste';
// Redireciona para a index
header('Location: index.php');

index.php

<?php
    session_start();
    ...
?>

...
<script>
    // Verifica se a variável existe
    <?php if (isset($_SESSION['toast']['title'])) { ?>
        Materialize.toast(<?= $_SESSION['toast']['title'] ?>)

        // Destrói a variável
        <?php unset($_SESSION['toast']['title']); ?>
    <?php } ?>
</script>
    
24.11.2018 / 20:40