Mostrando entradas con la etiqueta CodeIgniter. Mostrar todas las entradas
Mostrando entradas con la etiqueta CodeIgniter. Mostrar todas las entradas

jueves, 30 de enero de 2014

Disallowed Key Characters WTF??!!

For any weird reason, when I send some forms  this message is displayed:

Disallowed Key Characters

WTF? What I changed?? I don't know. I only know one thing: when this message appeared, I had to start debugging the FRAMEWORK, not my code, not your code, just the framework.

I found the problem in file system/core/Input.php, line 727, function _clean_input_keys{}

When I have a POST field containing "-", this doesnt match the preg_match("/^[a-z0-9:_\/-]+$/i", $str), I dont know why because the "-" IS HERE!!! then ...

I run this: var_dump(preg_match("/^[a-z0-9:_\/-]+$/i", '-')); die(); and of course was TRUE.

Conclusion: I don't know WTF is happening (It's like a devil '-' different from '-'), but, if you are seeing "Disallowed Key Characters" message and you have a post field called, for example "login-submit", rename this field to "login_submit" and maybe all the things start working again.

domingo, 12 de enero de 2014

Codeigniter dinamic route from database

What if we want to route from a db table? I search all the web and I dont find a solution that makes me happy, so, I build one.

File /core/MY_Router.php: we extend the core router to add the database functionality.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
CUSTOM ROUTER FUNCTION TO CHECK FOR CITY SLUG PLUS CONTROLLERS */
 class MY_Router extends CI_Router{

public function __construct(){
        parent::__construct();
        $this->config =& load_class('Config', 'core');
        $this->uri =& load_class('URI', 'core');

        require_once(BASEPATH.'database/DB'.EXT);
        $this->db = DB();
    }


public function _set_routing(){

$db_routes = $this->db
->where('active', 1)
->get('routes')
->result();

foreach ($db_routes as $route) {

$this->routes[$route->slug] = 'coupons/index/' . $city->slug;
$this->routes[$route->slug . '/(:any)'] = 'coupons/index/' . $city->slug . '/$1';
}

parent::_set_routing();
}
}

We need to change one character in system/core/Router.php to avoid overwrite the routes array.

In line 141 change this:
$this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; 

to this:
$this->routes += ( ! isset($route) OR ! is_array($route)) ? array() : $route;

(NOTE THE + SIGN)

That's all. Efective and Beautiful.

jueves, 19 de diciembre de 2013

codeigniter debug helper

Little helper to print_r variables with pre

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('pr'))
{
    function pr($thing)
    {
        echo '<pre>';
        var_dump($thing);
        echo '</pre>';
        die();        
    }   
}

sábado, 2 de marzo de 2013

codeigniter debug error 500

Bueno y otra vez me paso esto de no poder ver que carajo de error es lo que está pasando. Y otra vez me había olvidado como mostrarlo.

De nuevo a buscar y esta vez si que lo posteo acá para que quede registrado para la próxima vez que me olvide o para cualquier otra alma en pena que lo necesite:

editamos el index.php de codeigniter y agregamos:

if (defined('ENVIRONMENT'))
{
switch (ENVIRONMENT)
{
case 'development':
error_reporting(E_ALL);
ini_set('display_errors', TRUE);  // <------ esa linea
break;
case 'testing':
case 'production':
error_reporting(0);
break;

default:
exit('The application environment is not set correctly.');
}
}

domingo, 17 de febrero de 2013

instalando sendmail en debian, installing sendmail debian

Tratando de hacer funcionar la clase email de codeigniter sobre un debian me doy cuenta que este no tiene instalado sendmail, ni ninguna otra cosa capaz de sacar un mail al exterior.

Manos a la obra:

HOW TO rápido para instalar SENDMAIL en Debian:

apt-get install sendmail

Módulo de autentificación:

apt-get install sasl-bin
apt-get install libsasl-modules-plain
apt-get install libsasl-digestmd5-des

Después ejecutar:

/usr/share/sendmail/update_auth
Si necesitamos que se autentifiquen al enviar:

/etc/mail/default-auth-info
y lanzar de nuevo:
/usr/share/sendmail/update_auth

Soporte TSL.

 apt-get install openssl

después ejecutamos:

/usr/share/sendmail/update_tls
a continuación, nos indicará que para que sendmail pueda usar STARTTSL, es necesario

añadir la siguiente línea:
include(`/etc/mail/tls/starttls.m4')dnl
al archivo:
/etc/mail/sendmail.mc
en mi caso ya estaba añadida.

después hay que ejecutar:

sendmailconfig
y finalmente reiniciar sendmail:
/etc/init.d/sendmail restart

Si queremos un servidor POP, podemos instalar IPOPD, que complementa a SENDMAIL.
Los pasos para su instalación son muy simples si utilizamos apt-get:
apt-get install ipopd

y ya está.

viernes, 8 de febrero de 2013

activar mod_rewrite en apache - activar archivos .htaccess

Resulta que por default viene desactivado. Para activarlo hacemos:

a2enmod rewrite

eso lo que hace es activar el modulo "rewrite"

luego de eso editamos

nano /etc/apache2/sites-enabled/000-default

y buscamos donde diga "AllowOverride None" lo cambiamos por "AllowOverride All"

Reiniciamos apache y listo!

sábado, 21 de julio de 2012

Codeigniter: eliminar index.php de la url (remove index.php from url)

Para sacar el feo index.php de la url tenemos que editar el archivo .htaccess en la raiz del framework. (si no existe lo creamos)
RewriteEngine on RewriteCond $1 !^(index.php|css|js|images|robots.txt) RewriteRule ^(.*)$ nombreDeLaCarpetaDondeEstaElFramework/index.php/$1 [L]
despues editar el config.php de codeigniter:
$config['index_page'] = ''; //$config['index_page'] = 'index.php';