Ver Mensaje Individual
  #16 (permalink)  
Antiguo 19/11/2010, 13:40
Avatar de tomymolina
tomymolina
 
Fecha de Ingreso: noviembre-2010
Mensajes: 50
Antigüedad: 13 años, 4 meses
Puntos: 1
Respuesta: Include dinamico con #

Bien ! Ahora si ! Era sencillo pero sino me pusieras los dos ultimos ejemplos no me enteraba. Os dejo el code que me quedo para si alguien tiene el mismo problema

Código:


<?php  

if(isset($_GET['q'])){ 
    parse_str($_GET['q'],$output); 
    echo '<pre>'; 
    print_r($output); 
    echo '</pre>'; 

/* Para saber si ai varias variables en la url */	
if (count($output) == 1){
	$next = '';//Si solo es #action=valor no escribimos nada
} 
elseif (count($output) == 2){
   $next = '&go='.$output["go"] ;
} 
elseif (count($output) == 3){
   $next = '&go='.$output["go"].'&id='.$output["id"] ;	
}

	
	switch($_GET['q']){
        case 'action=contacto':
        include ("files/contacto/index.php");
        break;
		
		case 'action=desing':
		include ("files/desing/index.php");
		break;
		
		case 'action=posts'.$next:
		include ("files/news/PHPNews/index.php");
		break;
		



        default:
        echo 'contenido por defecto';
    }

    exit; 
} 
?> 





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>ejemplo</title> 
<style type="text/css"> 
.menu{ width:50px; line-height:20px; font-family:Verdana, Geneva, sans-serif; font-size:10px; background:#F93; cursor:pointer; text-align:center; float:left; margin-right:5px;} 
#pp{ clear:both; margin-top:20px;} 
</style> 
<script type="text/javascript"> 
function http(){ 
    if(typeof window.XMLHttpRequest!='undefined'){ 
        return new XMLHttpRequest();     
    }else{ 
        try{ 
            return new ActiveXObject('Microsoft.XMLHTTP'); 
        }catch(e){ 
            alert('Su navegador no soporta AJAX'); 
            return false; 
        }     
    }     
} 
function request(url,callback,params){ 
    ns.p=params.q; 
    params.q=params.q.split('#').join('') 
    var H=new http(); 
    if(!H)return; 
    var p=''; 
    for(var i in params){ 
        p+='&'+i+'='+escape(params[i]);     
    } 
    H.open('get',url+'?'+p+'&'+Math.random(),true); 
    H.onreadystatechange=function(){ 
        if(H.readyState==4){ 
            callback(H.responseText); 
            H.onreadystatechange=function(){} 
            H.abort(); 
            H=null; 
        } 
    } 
    H.send(null); 
} 
var ns={} 
ns.p=-1; 
onload=function(){ 
        setInterval(function(){if(location.hash!=ns.p){request('<?php echo basename($_SERVER['PHP_SELF']) ?>',function(r){document.getElementById('pp').innerHTML=r;},{'q':location.hash});};},100); 
} 
</script> 
</head> 

<body> 
<div onclick="location.hash='action=desing'" class="menu">desing</div> 
<div onclick="location.hash='action=contacto'" class="menu">contacto</div> 
<div onclick="location.hash='action=posts&go=view&id=17'" class="menu">c</div> 
<div onclick="location.hash='action=posts&go=view&id=18'" class="menu">d</div> 

<div id="pp"></div> 

</body> 
</html>
Ahora el files/news/PHPNews/index.php para luego poder incluir mas urls:


Código:
<?php
$atras = "action=posts&go=";
switch ($_GET['q'])
{

case $atras.'add':
 	echo "añadir";
	break;
case $atras.'view':
	include('files/news/PHPNews/PHPPost.php');
	break;
case $atras.'edit':
	include('files/news/PHPNews/Manage/PHPEdit.php');
	break;
case $atras.'all':
 include ('files/news/PHPNews/all.php');
 break;
 
case 0:
default:
echo 'default';
// include ('files/news/PHPNews/all.php');
}
?>