I use the Upload plugin from https://github.com/josegonzalez/cakephp-upload
The problem is, while the main image is uploaded fine, it is not creating thumbnails.
Here is my model code
public $actsAs = array(
'Upload.Upload' => array(
'image' => array(
'thumbnailSizes' => array(
'featured' => '720x400',
'xsmall' => '98x98',
'small' => '152x110',
'medium' => '400x222',
'large' => '225x145',
'medium_home' => '232x128',
'xlarge' => '720x632',
'editorial' => '199x300',
'medium_editorial' => '180x249',
'small_editorial' => '152x211',
'xsmall_editorial' => '98x136'
),
'path' => '{ROOT}webroot{DS}uploads{DS}{model}{DS}{field}{DS}'
)
)
);
Any idea what should I change?
Add 'thumbnails' => true and also 'thumbnailMethod' => 'php' in you array and the code will look like:
public $actsAs = array(
'Upload.Upload' => array(
'image' => array(
'thumbnails' => true,
'thumbnailMethod' => 'php',
'thumbnailSizes' => array(
'featured' => '720x400',
'xsmall' => '98x98',
'small' => '152x110',
'medium' => '400x222',
'large' => '225x145',
'medium_home' => '232x128',
'xlarge' => '720x632',
'editorial' => '199x300',
'medium_editorial' => '180x249',
'small_editorial' => '152x211',
'xsmall_editorial' => '98x136'
),
'path' => '{ROOT}webroot{DS}uploads{DS}{model}{DS}{field}{DS}'
)
)
);
I used the code below and it works fine for me:
public $actsAs = array(
'Upload.Upload' => array(
'photo' => array(
'fields' => array(
'dir' => 'photo_dir'
),
'deleteOnUpdate' => true,
'thumbnails' => true,
'thumbnailSizes' => array(
'64x64' => '64x64'
),
'thumbnailMethod' => 'php'
)
)
);
Related
I am trying to get the item types that Order.Item.ItemType.show_type = 1. I have written the query but I want to show only Items that their ItemType.show_type = 1 not all items.
$brief = $this->Order->find('first', array(
'fields' => array(
'Order.*'
),
'conditions' => array(
'Order.order_id' => $orderId,
),
'contain' => array(
'Item' => array(
'fields' => array(
'Item.*', 'CHAR(64 + Item.num) AS letter'
),
'conditions' => array(
'Item.deleted' => 0,
),
'ItemType' => array(
'conditions' => array(
'ItemType.show_type' => 1
),
)
),
)
));
The query shouldn't show Item id = 25741
Associations:
// Order
public $hasMany = array(
'BriefInstalment' => array(
'foreignKey' => 'order_id'
)
);
// Item Model
public $belongsTo = array(
'Order',
'ItemType' => array(
'type' => 'inner'
)
);
// ItemType Model
public $hasMany = array('Item');
Print:
array(
'Order' => array(
'order_id' => '67817',
'service' => '',
),
'Item' => array(
(int) 0 => array(
'id' => '25741',
'order_id' => '67817',
'num' => '2',
'item_type_id' => '8',
'name' => '3-5 titles active',
'deleted' => false,
'ItemType' => array(), // <= how to remove this empty model
'Item' => array(
(int) 0 => array(
'letter' => 'B'
)
)
),
(int) 1 => array(
'id' => '25742',
'order_id' => '67817',
'num' => '3',
'item_type_id' => '2',
'name' => '1,000 pro active',
'deleted' => false,
'ItemType' => array(
'id' => '2',
'name' => 'Part Instalment',
'show_type' => true,
'deleted' => false
),
'Item' => array(
(int) 0 => array(
'letter' => 'C'
)
)
)
)
)
This could not be done using Countaible behaviour, but iwth the joins method, set the recursive to -1
$brief = $this->Order->find('first', array(
'recursive' => -1,
'fields' => array(
'Order.*'
),
'conditions' => array(
'Order.order_id' => $orderId,
),
'joins' => array(
array(
'table' => 'items',
'alias' => 'Item',
'type' => 'inner',
'conditions' => array(
'Order.id = Item.order_id'
)
),
array(
'table' => 'item_types',
'alias' => 'ItemType',
'type' => 'inner',
'conditions' => array(
'ItemType.id = Item.item_type_id'
)
),
)
));
You have to check if the table names are correct and also the foreign keys names.
Another solution would be to go through your results, and unset the empty ones
foreach($brief as $k => $v){
foreach($v['Item'] as $kk => $vv){
if(empty($vv['ItemType'])){
unset($brief[$k]['Item'][$kk];
}
}
}
debug($brief);
I have a "Products" extension with a db table "tx_xxxproducts_domain_model_product" having a field "accessories":
'accessories' => array(
'exclude' => 0,
'label' => 'LLL:EXT:xxx_products/Resources/Private/Language/locallang_db.xlf:tx_xxxproducts_domain_model_product.accessories',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('accessories', array(
'appearance' => array(
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference',
'collapseAll' => TRUE,
),
), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'])
),
This field should have references to images.
It works, but the file references only have the fields Title and Description.
How can I add Link and Alternative Text, as the default Images CType has?
Thank you.
I found the answer in tt_content's TCA:
'accessories' => array(
'exclude' => 0,
'label' => 'LLL:EXT:xxx_products/Resources/Private/Language/locallang_db.xlf:tx_xxxproducts_domain_model_product.accessories',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('accessories', array(
'appearance' => array(
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference',
'collapseAll' => TRUE,
),
'foreign_types' => array(
'0' => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
),
)
), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'])
),
Check the 'foreign_types' key.
TYPO3 v8 Change => https://docs.typo3.org/typo3cms/TCAReference/ColumnsConfig/Type/Inline.html#file-abstraction-layer
'overrideChildTca' => [
'types' => [
Instead of
'foreign_types' => [
add this in your array element 'config', after 'appearance' for example:
'foreign_types' => array(
'0' => array(
'showitem' => '--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => array(
'showitem' => '--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => array(
'showitem' => '--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => array(
'showitem' => '--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => array(
'showitem' => '--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => array(
'showitem' => '--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--palette--;;filePalette'
),
),
i'm trying to upload an image and make a thumbnail of this image by using this Behavior (github) tutorial
I'm using the blog tutorial on cakephp website.
I'm getting this following errors each time I want to upload the images. I'm dowloading an .jpeg file
Invalid file type. Only .jpg, .jpeg, .png, .gif allowed.
My Model/Post.php
<?php
class Post extends AppModel {
public $validate = array(
'title' => array(
'rule' => 'notEmpty'
),
'body' => array(
'rule' => 'notEmpty'
)
);
public $actsAs = array('ImageUpload' => array(
'image' => array(
'required' => false,
'directory' => 'img/uploads/',
'allowed_mime' => array('image/jpeg', 'image/pjpeg', 'image/gif', 'image/png'),
'allowed_extension' => array('.jpg', '.jpeg', '.png', '.gif'),
'allowed_size' => 2097152,
'random_filename' => true,
'resize' => array(
'thumb' => array(
'directory' => 'img/uploads/thumbs/',
'phpThumb' => array(
'far' => 1,
'bg' => 'FFFFFF',
'zc' => 0
),
'width' => 230,
'height' => 150
),
'max' => array(
'directory' => 'img/uploads/thumbs/',
'phpThumb' => array(
//'far' => 1,
//'bg' => 'FFFFFF',
'zc' => 0
),
'width' => 400,
'height' => 300
)
)
)
)
);
}
I have a problem with an HABTM relation... I have two models: Tablets habtm Terms. When I query for a term, I can get the tablets but not the terms related to the tablets. My model file seems fine, the table in the database also, the query is ok, where shold I look for the problem ?!
Term model :
class Term extends AppModel {
var $name = 'Term';
var $displayField = 'term';
var $actsAs = array('Searchable','ExtendAssociations','Tree', 'Containable');
var $validate = array(
'term' => array(
'rule' => 'notEmpty'
)
);
var $belongsTo = array(
'WordType' => array(
'className' => 'WordType',
'foreignKey' => 'word_type_id'
),
'ParentTerm' =>
array( 'className' => 'Term',
'foreignKey' => 'parent_id'
)
);
var $hasAndBelongsToMany = array(
'Tablet' =>
array(
'className' => 'Tablet',
'joinTable' => 'tablets_terms',
'foreignKey' => 'term_id',
'associationForeignKey' => 'tablet_id',
'unique' => true,
)
);
}
Tablet model :
class Tablet extends AppModel {
var $name = 'Tablet';
var $displayField = 'no_museum';
var $actsAs = array ('Searchable','ExtendAssociations', 'Containable');
var $belongsTo = array( 'DateDay','DateMonth','Collection', 'Period', 'ArchLoc', 'ArchSite', 'Genre','Month', 'Year','Project', 'Collection','Ruler', 'MainVerb', 'Official','MainAction');
var $hasMany = array('TabletFile');
var $hasAndBelongsToMany = array(
'Tag' =>
array(
'className' => 'Tag',
'joinTable' => 'tablets_tags',
'foreignKey' => 'tablet_id',
'associationForeignKey' => 'tag_id',
'unique' => true,
),
'FromPerson' =>
array(
'className' => 'FromPerson',
'joinTable' => 'from_people_tablets',
'foreignKey' => 'tablet_id',
'associationForeignKey' => 'term_id',
'unique' => true,
),
'ToPerson' =>
array(
'className' => 'ToPerson',
'joinTable' => 'tablets_to_people',
'foreignKey' => 'tablet_id',
'associationForeignKey' => 'term_id',
'unique' => true,
),
'FromLocation' =>
array(
'className' => 'FromLocation',
'joinTable' => 'from_locations_tablets',
'foreignKey' => 'tablet_id',
'associationForeignKey' => 'term_id',
'unique' => true,
),
'ToLocation' =>
array(
'className' => 'ToLocation',
'joinTable' => 'tablets_to_locations',
'foreignKey' => 'tablet_id',
'associationForeignKey' => 'term_id',
'unique' => true,
),
'Language' =>
array(
'className' => 'Language',
'joinTable' => 'languages_tablets',
'foreignKey' => 'tablet_id',
'associationForeignKey' => 'language_id',
'unique' => true,
),
'Group' =>
array(
'className' => 'Group',
'joinTable' => 'groups_tablets',
'foreignKey' => 'tablet_id',
'associationForeignKey' => 'group_id',
'unique' => true,
),
'Term' =>
array(
'className' => 'Term',
'joinTable' => 'tablets_terms',
'foreignKey' => 'tablet_id',
'associationForeignKey' => 'term_id',
'unique' => true,
),
'Keyword' =>
array(
'className' => 'Keyword',
'joinTable' => 'keywords_tablets',
'foreignKey' => 'tablet_id',
'associationForeignKey' => 'keyword_id',
'unique' => true,
)
);
function beforeSave() {
$termIds = $this->_getTermIds();
if(!empty($termIds)) {
if(!isset($this->data['Term']['Term'])) {
$this->data['Term']['Term'] = $termIds;
} else {
foreach($termIds as $termId) {
$this->data['Term']['Term'][] = $termId;
}
}
}
//debug($this);
return true;
}
function _getTermIds() {
$terms=$this->data['Tablet']['translit'];
$terms= str_replace(array('\r\n', '\r', '\n','\n\r','\t'), ' ', $terms);
$terms = trim($terms, chr(173));
mb_internal_encoding("UTF-8");
mb_regex_encoding("UTF-8");
$terms = mb_ereg_replace('\s+', ' ', $terms);
$terms = explode(" ", $terms);
$terms=array_map('trim', $terms);
$anti_terms = array('#tablet','1.','2.','3.','4.','5.','6.','7.','7.','9.','10.','11.','12.','13.','14.','15.','16.','17.','18.','19.','20.','1\'.','2\'.','3\'.','4\'.','5\'.','Rev.',
'Obv.','#tablet','#obverse','#reverse','S1','S2','C1','C2','C3','C4','C5','C6','C7','C8','C9', '\r', '\n','\r\n', '\t',''. ' ', null, chr(173), 'x', '[x]','[...]' );
foreach($terms as $key => $term) {
if(in_array($term, $anti_terms) || is_numeric($term)) {
unset($terms[$key]);
}
}
if(Set::filter($terms)) {
foreach($terms as $term) {
$this->Tablet->Term = $this->Term;
$existingTerm = $this->Tablet->Term->find('first', array('conditions' => array('Term.term' => $term)));
if(!$existingTerm) {
$this->Term->create();
$this->Term->saveField('term', $term);
$termIds[] = $this->Term->id;
}
else {
$termIds[] = $existingTerm['Term']['id'];
}
}
return array_unique($termIds);
}
return false;
}
}
Term controller
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid term', true));
$this->redirect(array('action' => 'index'));
}
$term=$this->Term->find( 'first', array( 'conditions' => array('Term.id' => $id),/* 'recursive'=> 2 */ 'contain'=>array( 'WordType', 'Tablet' => array('Term') )));
$this->set('term', $term);
}
In the view :
<?php debug($term);?>
result :
Array
(
[Term] => Array
(
[id] => 626
[word_type_id] => 7
[term] => [ubi.]ku6
[sumerograms] =>
[translation] =>
[akkadian] =>
[comments] =>
[bibliography] =>
[parent_id] => 0
[lft] => 446
[rght] => 447
)
[WordType] => Array
(
[id] => 7
[word_type] => unknown
[parent_id] => 0
)
[Tablet] => Array
(
[0] => Array
(
[id] => 97
[arch_loc_id] =>
[arch_site_id] => 3
[period_id] => 1
[genre_id] => 2
[month_id] => 1
[year_id] => 3
[collection_id] => 14
[no_arch] =>
[no_museum] => AO
[no_cdli] => P220929
[no_etcsl] =>
[no_perso] => DP 279
[size] =>
[date_day] => 0
[date_month] => 0
[subject] => livraison de poissons par de nombreux pêcheurs pour Baranamtara
[translit] => Obv.
C1
1. 3 u tar.ku6
2. 2 geš’u 6 geš2 [ubi.]ku6
3. [1] [geš’u] [gir.ku6] [mun]
4. [1] [geš2] [3] [u] [ba]
5. [sila3] [i3-ku6]
etc etc bla bla long text.
[translation] =>
[abstract] =>
[epi_notes] =>
[comments] => Pour un festival !
[publications] => DP 279, Allotte de la Fuÿe, François M., 1912
[project_id] => 2
[ruler_id] => 61
[main_verb_id] => 345
[official_id] => 165
[main_action_id] => 9
[date_day_id] =>
[date_month_id] =>
[TabletsTerm] => Array
(
[id] => 19482
[tablet_id] => 97
[term_id] => 626
)
)
)
)
notice that cakephp created the model TabletsTerm and not TabletsTerms, is that a cue ?
Anyways I just do not know where to look anymore. Any suggestions ?
Thank you !
my problem is that can i give condition [ 'BookTitleMaster.id' => $xtitid, ] as like below
$bbookinfs = $this->BookStockin->BookIssue->find('all', array(
'conditions' => array('return_status' => 2),
'contain' => array(
'BookStockin' => array(
'BookTitleMaster' => array(
'BookTitleMaster.id' => $xtitid,
'fields' => array('id','title','sub_title','book_material_type_id','book_author_id','course_detail_id','isbn_no','book_publisher_id','pub_year','pub_place','desc','no_pages','volume'),
'BookMaterialType' => array('name'),
'CourseDetail' => array('name'),
'BookPublisher' => array('name'),
'BookAuthor' => array('name')
)
)
)
));
I believe that you miss is:
'conditions' => array('BookTitleMaster.id' => $xtitid),
So, your final code should be:
$bbookinfs = $this->BookStockin->BookIssue->find('all', array(
'conditions' => array('return_status' => 2),
'contain' => array(
'BookStockin' => array(
'BookTitleMaster' => array(
'conditions' => array('BookTitleMaster.id' => $xtitid),
'fields' => array('id','title','sub_title','book_material_type_id','book_author_id','course_detail_id','isbn_no','book_publisher_id','pub_year','pub_place','desc','no_pages','volume'),
'BookMaterialType' => array('name'),
'CourseDetail' => array('name'),
'BookPublisher' => array('name'),
'BookAuthor' => array('name')
)
)
)
));
HTH
Shouldn't it be:
'conditions' => array('BookTitleMaster.id' => $xtitid),