Skip to content

Instantly share code, notes, and snippets.

@nucklearproject
nucklearproject / gist:3717763
Created September 13, 2012 21:21
Jquery plugin para centrar verticalmente una imagen
$.fn.vCenter = function(){
this.each(function(){
parent_height = $(this).parent().height();
image_height = $(this).height();
top_margin = (parent_height - image_height)/2;
});
return this.each(function() {
$(this).css( 'margin-top' , top_margin);
});
@nucklearproject
nucklearproject / gist:3717801
Created September 13, 2012 21:26
Imprimir el valor de un field desde cualquier entidad de Drupal.-
/* Usamos directamente la API de drupal. field_get_items()
Si antes hacias esto echo $node->field_subtitle['und'][0]['value'];
Aunque funciona olvidate de volver a hacerlo!
*/
/*
Tomamos como referencia un field creado en la entidad user.
*/
$user = user_load(1);
@nucklearproject
nucklearproject / .htaccess
Created September 14, 2012 21:05
.htaccess YII
DirectoryIndex index.php
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
@nucklearproject
nucklearproject / gist:3724841
Created September 14, 2012 21:08
main.php config file YII
<?php
// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Web Application',
@nucklearproject
nucklearproject / gist:3725307
Created September 14, 2012 22:21
Pasos para crear un modulo /crud con la herramienta GII de YII framework
1. Suponiendo que ya sabemos como manejarnos con GII, pasamos a crear un modulo:
Module Generator > Module ID * (Aca le ponemos el nombre que queramos)
2. Activamos el modulo desde nuestro main.php en este caso he creado un modulo llamado test.
'modules'=>array(
'test',
......
3. Creamos un model, suponiendo que tengo una tabla llamada testlist:
@nucklearproject
nucklearproject / gist:3725549
Created September 14, 2012 23:15
Usar un campo tipo ENUM como un select list en YII
/* Suponiendo que hemos creado nuestro CRUD. creamos un componente - Obviamente lo guardamos como ZHtml.php dentro de nuestra carpeta components, no hace falta inicializarlo si en nuestro main.php tenemos el autoload
'import'=>array(
'application.models.*',
'application.components.*',
),
.....
*/
<?php
My .gitignore YII
#editors
*.swp
.buildpath
.project
.settings
nbproject
.idea
*.sublime-project
*sublime-workspace
@nucklearproject
nucklearproject / gist:3758096
Created September 20, 2012 20:16
CCK field Update with drupal_write_record()
File created in webroot.
<?php
error_reporting(E_ALL);
require_once 'includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
drupal_flush_all_caches();
$results = db_query('select nid from node where type="store"');
@nucklearproject
nucklearproject / gist:3762249
Created September 21, 2012 15:43
Save and return to edit new or update node.
<?php
/**
* @file
* Replace the submit button to node creation forms that
* allows the content author to return to edit the node
*/
/**
* Implementation of hook_form_alter().
@nucklearproject
nucklearproject / gist:3768738
Created September 23, 2012 03:30
Drush commands
Generate makefile
FOLDER$drush generate-makefile NAMEFILE.make
Download with make files
$drush make FILE.make FOLDER
Fresh install
FOLDER$drush site-install --account-name=admin --account-pass=admin --db-url=mysql://root:PASS@localhost/DATABASE
List installed themes and modules