Skip to content

Instantly share code, notes, and snippets.

Avatar

Alberto Fernández kroatoanweb

View GitHub Profile
View exec-defer-finally.php
<?php
$handle = fopen($location, 'r+');
if ($handle === false) {
return false;
}
try {
$firstLine = fgets($handle, 1024);
@kroatoanweb
kroatoanweb / base.html.twig
Last active Aug 8, 2016
Repetir el contenido de un bloque dentro de una plantilla twig
View base.html.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 Aug 5, 2016
Detectar peticiones Ajax en twig
View detect-ajax-request-twig.twig
{% extends app.request.xmlHttpRequest
? '::ajax.html.twig'
: '::base.html.twig' %}
{# contenido #}
@kroatoanweb
kroatoanweb / detect-ajax-request-symfony.php
Created Aug 5, 2016
Detectar peticiones AJAX con Symfony
View detect-ajax-request-symfony.php
<?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 Aug 11, 2017
Como detectar una petición ajax en PHP plano.
View detect-ajax-request-plain.php
<?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
View mockbuilder-post.php
<?php
namespace Tests\AppBundle\Manager;
use AppBundle\Manager\DocumentManager;
class DocumentManagerTest extends \PHPUnit_Framework_TestCase
{
public function testAddDocument()
{
View mockbuilder-pre.php
<?php
namespace Tests\AppBundle\Manager;
use AppBundle\Manager\DocumentManager;
use AppBundle\Document\Post;
class DocumentManagerTest extends \PHPUnit_Framework_TestCase
{
public function testAddDocument()
View optimizar-tablas-mysql.php
<?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';
View htaccess-sin-www
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^tudominio.com$ [NC]
RewriteRule ^(.*)$ http://tudominio.com/$1 [L,R=301]
View htaccess-con-www
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.tudominio.com$ [NC]
RewriteRule ^(.*)$ http://www.tudominio.com/$1 [L,R=301]