Skip to content

Instantly share code, notes, and snippets.

@joelmiguelvalente
Last active August 31, 2020 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelmiguelvalente/a69b34d3e20a53bb19f5001599dbea5f to your computer and use it in GitHub Desktop.
Save joelmiguelvalente/a69b34d3e20a53bb19f5001599dbea5f to your computer and use it in GitHub Desktop.
Ajax buscador
<?php if ( ! defined('TS_HEADER')) exit('No se permite el acceso directo al script');
/**
* Controlador AJAX
*
* @name ajax.buscador.php
* @author Miguel92
*/
/**********************************\
* (VARIABLES POR DEFAULT) *
\*********************************/
// NIVELES DE ACCESO Y PLANTILLAS DE CADA ACCIÓN
$files = array(
'buscador-buscar' => array('n' => 0, 'p' => 'buscar'),
'buscador-usuario' => array('n' => 0, 'p' => 'usuario'),
);
/**********************************\
* (VARIABLES LOCALES ESTE ARCHIVO) *
\*********************************/
// REDEFINIR VARIABLES
$tsPage = 'php_files/p.buscador.'.$files[$action]['p'];
$tsLevel = $files[$action]['n'];
$tsAjax = empty($files[$action]['p']) ? 1 : 0;
/**********************************\
* (INSTRUCCIONES DE CODIGO) *
\*********************************/
// DEPENDE EL NIVEL
$tsLevelMsg = $tsCore->setLevel($tsLevel, true);
if($tsLevelMsg != 1) { echo '0: '.$tsLevelMsg; die();}
// CLASE
include("../class/c.buscador.php");
$tsBuscador = new tsBuscador();
//
// CODIGO
switch($action){
case 'buscador-buscar':
//<---
$words = $tsCore->setSecure(trim($_POST['word']));
$resultados = $tsBuscador->SearchAjax($words);
$smarty->assign('tsResultados', $resultados['data']);
$smarty->assign('tsWord', $words);
$smarty->assign('tsTotal', $resultados['total']);
//--->
break;
case 'buscador-usuario':
# Asignamos la función
$smarty->assign('tsListaU', $tsBuscador->BuscarUsuarios());
break;
}
?>
@joelmiguelvalente
Copy link
Author

Se realizó una actualización!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment