Skip to content

Instantly share code, notes, and snippets.

View kroatoanweb's full-sized avatar

Alberto Fernández kroatoanweb

View GitHub Profile
<?php
$handle = fopen($location, 'r+');
if ($handle === false) {
return false;
}
try {
$firstLine = fgets($handle, 1024);
@kroatoanweb
kroatoanweb / base.html.twig
Last active August 8, 2016 10:29
Repetir el contenido de un bloque dentro de una plantilla twig
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>{% block pagetitle %}{{ block('title') }} | MyPage{% endblock %}</title>
{% block stylesheets %}{% endblock %}
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
<meta name="title" content="{% block metatitle %}{{ block('title') }} | MyPage{% endblock %}"/>
</head>
<body>
@kroatoanweb
kroatoanweb / detect-ajax-request-twig.twig
Created August 5, 2016 10:15
Detectar peticiones Ajax en twig
{% extends app.request.xmlHttpRequest
? '::ajax.html.twig'
: '::base.html.twig' %}
{# contenido #}
@kroatoanweb
kroatoanweb / detect-ajax-request-symfony.php
Created August 5, 2016 10:11
Detectar peticiones AJAX con Symfony
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class DefaultController extends Controller
{
/**
@kroatoanweb
kroatoanweb / detect-ajax-request-plain.php
Last active August 11, 2017 14:09
Como detectar una petición ajax en PHP plano.
<?php
//Acciones que calculen el contenido
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
//Mostramos el contenido en el formato especifico para las llamadas ajax
//Acabamos con un return o un die para evitar seguir ejecutando el codigo
}
//Mostramos el contenido en el formato normal
<?php
namespace Tests\AppBundle\Manager;
use AppBundle\Manager\DocumentManager;
class DocumentManagerTest extends \PHPUnit_Framework_TestCase
{
public function testAddDocument()
{
<?php
namespace Tests\AppBundle\Manager;
use AppBundle\Manager\DocumentManager;
use AppBundle\Document\Post;
class DocumentManagerTest extends \PHPUnit_Framework_TestCase
{
public function testAddDocument()
<?php
/**
* Configuración de la aplicación
* Idealmente en un fichero aparte
*/
$dsn = 'mysql:dbname=nuestrabasededatos;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^tudominio.com$ [NC]
RewriteRule ^(.*)$ http://tudominio.com/$1 [L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.tudominio.com$ [NC]
RewriteRule ^(.*)$ http://www.tudominio.com/$1 [L,R=301]