Skip to content

Instantly share code, notes, and snippets.

@ijmorgado
ijmorgado / modx.tv.image.resourcefield.html
Created February 5, 2013 04:42
This is a way that I've used to retrieve an image template variable with output type=text and filtered by phpthumbof on the fly.....Very useful when we have tv's and wants to use the same image in different places and sizes.....
<img src="[[getResourceField:phpthumbof=`w=444&h=284&zc=1`? &id=`[[*slide1_home]]` &isTV=`1` &processTV=`1` &field=`imagen_nota`]]" alt="Imagen1" />
@ijmorgado
ijmorgado / zf_route.php
Last active December 11, 2015 21:58
This is a snippet of route in ZF2 to handle url's like /controller/action, /controller/action/param1/value1, /controller/action/param1/value1/param2/value2...perhaps that's not the best way to do that but comming soon I would like to handle url's with undefined number of params with just one routing rule....
<?php
// ...the other options before.....
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
@ijmorgado
ijmorgado / create_thumbnail_function.php
Last active February 12, 2019 01:49
This is a function to create thumbnail image(png, jpeg, jpg or gif) with specific height...is useful when we need to make tables with the same height for each row with image previews...if you really need the same width and whatever height, just change the order of params in the aspect ratio operations (lines 17 and 18)...
public function createThumbnail($source_folder, $thumbs_folder, $source_file, $extension, $thumbHeight){
if ($extension == 'gif') {
$imgt = "ImageGIF";
$imgcreatefrom = "ImageCreateFromGIF";
}else if($extension == 'jpg' || $extension == 'jpeg'){
$imgt = "ImageJPEG";
$imgcreatefrom = "ImageCreateFromJPEG";
}else if ($extension == 'png') {
$imgt = "ImagePNG";
$imgcreatefrom = "ImageCreateFromPNG";
@ijmorgado
ijmorgado / zf2_join.php
Created January 28, 2013 04:58
That's a small function for a Table Gateway model that executes a SQL Join between data of 2 tables and returns the resultset as an array....simply but useful when we work with multiples tables and relationships......It works for ZF2....
public function getOrderedByCategory(){
$sql = new Sql($this->tableGateway->getAdapter());
$select = $sql->select('alb_album')->where('alb_album.activo = 1 ORDER BY alb_album.id_categoria ASC');
$join = $select->join('alb_categoria','alb_album.id_categoria = alb_categoria.id_categoria',array('nombre_categoria'=>'nombre'));
$statement = $sql->prepareStatementForSqlObject($join);
$result = $statement->execute();
$rows = array_values(iterator_to_array($result));
return $rows;
}
@ijmorgado
ijmorgado / import_csv.sql
Created January 27, 2013 07:29
That's a small sql script to import a csv file without headers...just a bunch of data...I don't know why I had a trouble with the server when I tried other samples....
LOAD DATA local INFILE '/path/to/file.csv'
INTO TABLE name_scheme.name_of_table
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
IGNORE 0 LINES
(field1,field2,field3,field4);