He probado algunos (no todos) de los frameworks web que hay en el mercado, para Java (Struts), PHP (Cakephp), y Ruby (Ruby on Rails). Paso a enumerar ventajas y desventajas segun mi humilde opinion:
* Struts: Ventajas: ninguna, es pesado, hay que configurar uno o más xmls gigantes, en fin, no me gusta para nada, y no lo volvería a usar.
* Cakephp: Muy buen entorno inspirado en rails, anda bien con php 4 y 5, anda en casi cualquier hosting (todos soportan php). Desventajas: es php, es un lenguaje bastante feo. y le falta la capacidad sintáctica de ruby como para tener un framework realmente excelente.
* Ruby On Rails: La diva de los entornos de desarrollo web,
excelente, super cómodo, elegante, rápido, extensible, etc etc. desventajas: no todos los hostingss soportan ruby on rails. Mi hosting (bluehost) si. y la verdad que anda bastante lindo.
Conclusión: Estoy volviendo al poderoso Ruby on Rails. Subiendo la productividad y la calidad de los sitios :)
jueves, 25 de octubre de 2007
Frameworks de desarrollo web
0 comentarios Categorías: cakephp, desarrollo, internet, java, php, programacion, ruby on rails, web
jueves, 13 de septiembre de 2007
El Truncate de cakephp me rompe el layout
agregar en views/helpers/advtext.php
class AdvtextHelper extends Helper {
/**
* Truncates text.
*
* Cuts a string to the length of $length and replaces the last characters
* with the ending if the text is longer than length.
*
* @param string $text String to truncate.
* @param integer $length Length of returned string, including ellipsis.
* @param string $ending Ending to be appended to the trimmed string.
* @param boolean $exact If false, $text will not be cut mid-word
* @param boolean $considerHtml If true, HTML tags would be handled correctly
* @return string Trimmed string.
*/
function truncate($text, $length = 100, $ending = '...', $exact = true, $considerHtml = false) {
if ($considerHtml) {
// if the plain text is shorter than the maximum length, return the whole text
if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
return $text;
}
// splits all html-tags to scanable lines
preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER);
$total_length = strlen($ending);
$open_tags = array();
$truncate = '';
foreach ($lines as $line_matchings) {
// if there is any html-tag in this line, handle it and add it (uncounted) to the output
if (!empty($line_matchings[1])) {
// if it's an "empty element" with or without xhtml-conform closing slash (f.e.
)
if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $line_matchings[1])) {
// do nothing
// if tag is a closing tag (f.e. )
} else if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $line_matchings[1], $tag_matchings)) {
// delete tag from $open_tags list
$pos = array_search($tag_matchings[1], $open_tags);
if ($pos !== false) {
unset($open_tags[$pos]);
}
// if tag is an opening tag (f.e. <b>)
} else if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) {
// add tag to the beginning of $open_tags list
array_unshift($open_tags, strtolower($tag_matchings[1]));
}
// add html-tag to $truncate'd text
$truncate .= $line_matchings[1];
}
// calculate the length of the plain text part of the line; handle entities as one character
$content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', ' ', $line_matchings[2]));
if ($total_length+$content_length > $length) {
// the number of characters which are left
$left = $length - $total_length;
$entities_length = 0;
// search for html entities
if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) {
// calculate the real length of all entities in the legal range
foreach ($entities[0] as $entity) {
if ($entity[1]+1-$entities_length <= $left) {
$left--;
$entities_length += strlen($entity[0]);
} else {
// no more characters left
break;
}
}
}
$truncate .= substr($line_matchings[2], 0, $left+$entities_length);
// maximum lenght is reached, so get off the loop
break;
} else {
$truncate .= $line_matchings[2];
$total_length += $content_length;
}
// if the maximum length is reached, get off the loop
if($total_length >= $length) {
break;
}
}
} else {
if (strlen($text) <= $length) {
return $text;
} else {
$truncate = substr($text, 0, $length - strlen($ending));
}
}
// if the words shouldn't be cut in the middle...
if (!$exact) {
// ...search the last occurance of a space...
$spacepos = strrpos($truncate, ' ');
if (isset($spacepos)) {
// ...and cut the text in this position
$truncate = substr($truncate, 0, $spacepos);
}
}
// add the defined ending to the text
$truncate .= $ending;
if($considerHtml) {
// close all unclosed html-tags
foreach ($open_tags as $tag) {
$truncate .= '';
}
}
return $truncate;
}
}
?>
el helper, se usa igual que html->truncate, pero con un parametro extra, que en true toma en cuenta el html para le truncado, y hasta lo cierra bien y todo.
<?=$advtext->truncate($text,600,'[...]',false,true)?> asi lo uso yo.
0 comentarios Categorías: cakephp, helpers, programacion
miércoles, 11 de julio de 2007
CakePhp y webroot
Las aplicaciones que estuve haciendo en cakephp andaban de lujo en mi server local, pero cuando las subía al server de producción, se rompía el htmlHelper y le agregaba /webroot/ a todas las urls,
es decir donde deberia decir www.example.com ponia www.example.com/webroot/ y asi
example.com/home era example.com/webroot/home etc.
Por lo que pude leer en la web, a nadie más le pasó, o a unos pocos, pero, hete aquí, que problema solucionado, simplemente edite webroot/index.php
define('WEBROOT_DIR', '/');
y leesto.
un solo problema, no usen WEBROOT_DIR en la aplicación porque queda apuntando a /.
esto parece solucionar el problema, pero si a alguien se le ocurre algo mejor, espero comentarios o insultos!
hastalavista
0 comentarios Categorías: cakephp, desarrollo, php, programacion, web
martes, 26 de junio de 2007
CakePhp + phpcaptcha
excelente! necesitaba un captcha para cakephp, y este chabon lo hace re facil. El unico problema fue que me tiraba la ultima letra en blanco. A veces las ultimas dos.
El tema es que buscando y buscando en foros y demas, la unica respuesta que encontraba era algo como, phpcaptcha hace
$iLineColour = imagecolorallocate($this->oImage, rand(100, 250), rand(100, 250), rand(100, 250));
y entonces el "iluminado" concluia que es imposible que te escriba en blanco.
Ahora.
A vos.
Iluminado programador.
Tipito sobrador de los foros.
Si si, a vos que contestaste eso.
Una pregunta.
¿Que pasa cuando queres reservar más colores de los que podés con imagecolorallocate?
¿que te devuelve?
¿En que color pinta las cosas si usas el valor devuelto?
Bueno pibe, te doy la respuesta porque el resto de la gente que lee este foro (nadie) se lo merece. En BLANCO.
Ah! mira vos, asi que era eso?
y por que pasa?
no tengo idea, por que trata de reservar más colores de los que puede.
donde?
y bueno, reservando colores para las líneas.... o sea...
solucion rapida y pedorra: achicar el numero de lineas
cambiar
define('CAPTCHA_NUM_LINES', 70);
a
define('CAPTCHA_NUM_LINES', 50);
ya funciona(en mi caso)
pero lo que esto deberia hacer es reservar unos n colores aleatorios(ponele 50) al principio y luego utilizar un color al azar de ese grupo.
Queda como tarea para la casa.
Chabon del foro: NO TE TENEMOS MIEDO! que respuesta pelotuda que diste....
0 comentarios Categorías: cakephp, php, programacion, web
Configurar CakePhp
Que perno que es esto, pero el problema, como siempre, estaba entre la silla y el teclado, el problema que tengo (siempre) es que tengo dos configuraciones distintas, una de desarrollo en mi compu y otra, producción en el server que corresponda.
Ya me estoy acostumbrando a eclipse (o será que eclipse se está acostumbrando a mi??) pero siempre cometo los mismos errores al copiar un sitio local a un server.
El problema de hoy en particular fue que estuve unas 5 horas peleando con configuraciones y editando archivos... y era solo que me habia olvidado de copiar la base de datos... que moquero.
Pero estoy convergiendo a alguna configuración decente (espero).
Pero más allá de eso, crear un nuevo sitio con cakephp no debería tomar más de 10 minutos.
eso sí, no se olviden de apuntar bien CAKE_CORE_INCLUDE_PATH a donde tienen su cake, y de crear la base de datos...
0 comentarios Categorías: cakephp, desarrollo, php, web
lunes, 28 de mayo de 2007
CakePhp
Y bueno, hace rato que probe Ruby on Rails, fascinante, pero luego me vi obligado (por el hosting) a trabajar con php, asi que me hice un pequeño framework inspirado en RoR, pero muy muy muy basico.
Hete aquí que despues buceando por la web, encontré por ahi este framework groso para php, se llama cake php y es como rails para php, la verdad, es bastante groso, es como el "hazte la fama" de "hazte la fama y héchate a dormir".
Pero (siempre hay un pero), siendo tan bonito como es, tambien tiene algunas cosillas que a uno le gustaria mejorar/ampliar/modificar, asi que agregué internacionalizacion (a la 1.1 que no tenia, la 1.2 que esta por salir ya tiene incorporado) y un par de helpers que fui necesitando. Capaz que algun día los publico en algun lado (capaz que aca, por que no).
Ampliaremos.
0 comentarios Categorías: cakephp, php, programacion, web