Skip to content

Instantly share code, notes, and snippets.

@SilasRodrigues19
Created March 21, 2023 15:56
Show Gist options
  • Save SilasRodrigues19/db9ae2ff64fefb8a27ad5852a0466891 to your computer and use it in GitHub Desktop.
Save SilasRodrigues19/db9ae2ff64fefb8a27ad5852a0466891 to your computer and use it in GitHub Desktop.

Revisions

  1. SilasRodrigues19 created this gist Mar 21, 2023.
    5 changes: 5 additions & 0 deletions autoload.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    <?php

    $autoload['helper'] = array('url', 'html', 'file', 'basic'); // basic nome do helper que eu criei pra exibir mensagem de erro

    ?>
    67 changes: 67 additions & 0 deletions basic_helper.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,67 @@
    <?php

    function notify($title, $msg, $type, $width)
    {
    $_SESSION['title'] = $title;
    $_SESSION['msg'] = $msg;
    $_SESSION['type'] = $type;
    $_SESSION['width'] = $width;

    }

    function showMessage()
    {
    if(isset($_SESSION['title'])) {
    echo alertBox($_SESSION['title'], $_SESSION['msg'], $_SESSION['type'], $_SESSION['width']);

    unset($_SESSION['title']);
    unset($_SESSION['msg']);
    unset($_SESSION['type']);
    unset($_SESSION['width']);
    }
    }


    function alertBox($title, $msg, $type, $width)
    {
    switch( $type ) {
    case 'erro':
    case 'error':
    case 'danger':
    $type = 'alert-danger';
    $icon = 'icon-park-solid:close-one';
    $title = 'Error!';
    break;
    case 'ok':
    case 'success':
    $type = 'alert-success';
    $icon = 'akar-icons:circle-check-fill';
    $title = 'Success!';
    break;
    case 'aviso':
    case 'warning':
    $type = 'alert-warning';
    $icon = 'ph:warning-circle-fill';
    $title = 'Warning!';
    break;
    case 'info':
    $type = 'alert-info';
    $icon = 'akar-icons:info-fill';
    $title = 'Info';
    break;
    default:
    $type = 'alert-default';
    $icon = 'mdi mdi-alert-circle mr-2';
    $title = 'Warning!';
    }

    $title = '';

    $box = "<div class=\"col-md-6 py-4 my-2 d-flex justify-content-center w-100 showMessage\">
    <span class=\"$width text-center alert $type\" role=\"alert\">
    <span class=\"iconify mb-1\" data-icon=\"$icon\"></span> <strong> $title </strong> $msg
    </span>
    </div>";

    return $box;
    }
    29 changes: 29 additions & 0 deletions example_model.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    <?php

    public function insertResource($dados)
    {

    $verify = "SELECT resource_link FROM resource WHERE resource_link = '".$dados['resource_link']."'";
    $execute = $this->db->query($verify);

    if($execute->num_rows() > 0) {
    notify('', 'Este link já foi cadastrado', 'warning', 'w-50');
    return false;
    } else {

    $insert = "INSERT INTO resource (resource_name, resource_description, resource_link)
    VALUES ('{$dados['resource_name']}', " . $this->db->escape($dados['resource_description']) . ", '{$dados['resource_link']}')";

    $execute = $this->db->query($insert);

    if($execute) {
    $insert = "INSERT INTO resource_category (`category_id`, `resource_id`) VALUES ({$dados['resource_category']}, {$dados['resource_id']})";
    $execute = $this->db->query($insert);
    return true;
    }

    return false;

    }

    ?>