Cakephp MeioUpload removeOrginal - cakephp

removeOriginal Dont work on MeioUpload !
i have this code in my post model :
/model/post.php
public $actsAs = array(
'MeioUpload.MeioUpload' => array(
'avatar' =>array(
'thumbnails' => true ,
'thumbsizes' => array('small' => array('width'=>100, 'height'=>100)),
'thumbnailQuality' => 75,
'thumbnailDir' => 'thumb',
'removeOriginal' => true
)
)
);
i want to upload thumbs only , I do not need the source picture .
(cakephp 2.1.2)
thanks

This Behaviour is depreciated and no longer supported (https://github.com/jrbasso/MeioUpload) but I had the same problem and have no need to migrate yet.
For anyone in the same boat as me, you can fix it as follows:
Open Model/Behavior/MeioUploadBehavior.php
Look for this block of code which appears TWICE:
// If the file is an image, try to make the thumbnails
if ((count($options['thumbsizes']) > 0) && count($options['allowedExt']) > 0 && in_array($data[$model->alias][$fieldName]['type'], $this->_imageTypes)) {
$this->_createThumbnails($model, $data, $fieldName, $saveAs, $ext, $options);
}
After the SECOND occurrence insert the following code (which does appear already under the first occurence):
if ($options['removeOriginal']) {
$this->_removeOriginal($saveAs);
}
I did this in my project and seems to be working just fine so far!

Related

TYPO3 findAll() return empty data

I'm newbie with TYPO3.
I'm facing with this issue, can not get data from database.
I have a plugin with this configure
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Locations.' . $_EXTKEY,
'Locationsfe',
array(
'Location' => 'list, show, showprice, listprice, listcategory, scan,sharedoffice',
'Category' => 'list, show',
'Pricing' => 'list, show, showprice, listprice, scan, test',
'Template' => 'list, show',
),
// non-cacheable actions
array(
'Location' => '',
'Category' => '',
'Pricing' => 'test',
'Template' => '',
)
);
And in my controller I have this function
public function testAction() {
// Get current language
$currentLanguage = $GLOBALS['TSFE']->sys_language_uid;
$pricing = $this->pricingRepository->findAll();
print_r($pricing);
die('Passed');
}
I also added this line to Constants
plugin.tx_locations.persistence.storagePid = 164
I also created a typo Script
plugin.tx_locations {
view {
templateRootPath = {$plugin.tx_locations.view.templateRootPath}
partialRootPath = {$plugin.tx_locations.view.partialRootPath}
layoutRootPath = {$plugin.tx_locations.view.layoutRootPath}
}
persistence {
storagePid = 164
}
features {
# uncomment the following line to enable the new Property Mapper.
# rewrittenPropertyMapper = 1
}
}
But all of above does not work. Just white page return.
I also read this
extbase repository findAll() returns result null
So, what happen? I don't know why. Can you help me to figure it out please.
Thanks in advance.
Ok i suppose you have created some records from model type pricing in your backend right ;).
Then please try this in your controller:
$this->pricingRepository->setDefaultQuerySettings($this->pricingRepository->createQuery()->getQuerySettings()->setRespectStoragePage(false)); /* here we ignore the storage pid to be sure that we look in the entire system, if this works we have some hints that somthing with the storage pid is wrong */
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->pricingRepository); /*please use this for debugging is much easier with this :D*/
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->pricingRepository->findAll());
can you post the debugs please.
sorry i can't comment i don't have the right reputation :(

How to know webroot in core.php

I'm using CakePHP 2.3.1.
Our server has some independent applications in one server. So I want to change session.cookie_path setting following the Cookbook :
Configure::write('Session', array(
'defaults' => 'php',
'ini' => array(
'session.cookie_path' => '/app/dir'
)
));
I could change it successfully with this. But here is a problem. I need to set session.cookie_path value to webroot dynamically (without string literal value such as '/app/dir').
I've tried to use $this->webroot following this Q&A, but of course it does not work because there is no controller in the file app/Config/core.php.
Any ideas?
I realized a php variable is available : $_SERVER['REQUEST_URI'].
So I could solve the problem.
$requestURI = $_SERVER['REQUEST_URI'];
$webroot = preg_replace('/(^\/[^\/]+\/).*$/', '$1', $requestURI);
//echo $webroot;
Configure::write('Session', array(
'defaults' => 'cake',
'ini' => array(
'session.cookie_path' => $webroot // looks like '/app/'
)
));
But this solution does not have reusability enough : it would not work for apps located in deeper directories such as /apps/app1/.
I'm still awaiting a better solution.

CakeDC search plugin - check if flag is set

I'm using the cakeDC search plugin in my cake app (2.2). As part of a basic search form I want to ensure only live records are returned (live being a flag in the database - a tinyint, 0 for deleted, 1 for live).
I've tried doing this in my controller:
$isLive = array('live' => '1');
$this->passedArgs = set::merge($this->passedArgs, $isLive);
But it didnt work...
I found this question but the answer didnt really help. Could anyone tell me where I'm going wrong?
Thanks in advance.
Solved, I missed the filterArgs in the model:
public $filterArgs = array(
'username' => array('type' => 'like'),
'company' => array('type' => 'like'),
'live' => array('type' => 'value')
);
Hopefully this will help someone

CakePHP 2.1.0: How to Create "Down for Maintenance" Page

I'm trying to implement something like Mark Story's "Down for Maintenance" page using CakePHP 2.1.0. I'm pretty close to achieving this, but I'm running into two issues that I could use some help with. First of all, here is all of the relevant code (six files):
1) app/Config/bootstrap.php:
Configure::write('App.maintenance', true);
2) app/Config/core.php:
Configure::write('debug', 1);
...
Configure::write('Exception', array(
'handler' => 'ErrorHandler::handleException',
'renderer' => 'AppExceptionRenderer',
'log' => true
));
3) app/Controller/AppController.php:
if (Configure::read('App.maintenance') == true) {
App::uses('DownForMaintenanceException', 'Error/Exception');
throw new DownForMaintenanceException(null);
}
4) app/Lib/Error/Exception/DownForMaintenanceException.php:
<?php
class DownForMaintenanceException extends CakeException {}
5) app/Lib/Error/AppExceptionRenderer.php:
<?php
App::uses('ExceptionRenderer', 'Error');
class AppExceptionRenderer extends ExceptionRenderer {
function _outputMessage($template) {
// Call the "beforeFilter" method so that the "Page Not Found" page will
// know if the user is logged in or not and, therefore, show the links that
// it is supposed to show.
if (Configure::read('App.maintenance') == false)
{
$this->controller->beforeFilter();
}
parent::_outputMessage($template);
}
public function downForMaintenance() {
$url = $this->controller->request->here();
$code = 403;
$this->controller->response->statusCode($code);
$this->controller->set(array(
'code' => $code,
'url' => h($url),
'isMobile' => $this->controller->RequestHandler->isMobile(),
'logged_in' => false,
'title_for_layout' => 'Down for Maintenance'
));
$this->_outputMessage($this->template);
}
}
6) app/View/Errors/down_for_maintenance.ctp:
<p>Down for Maintenance</p>
Now, for the two issues I'm experiencing. First, this code only works when debug is set higher than 1. Is there anything I can do about that? Does that indicate that I'm going about this the wrong way? The second issue is that, although I'm setting the "isMobile" and "logged_in" view variables to boolean values in the "downForMaintenance" method, the "app/View/Layouts/default.ctp" file is seeing them as strings. What can I do about that?
Thanks!
here is a quick and dirty maintenance page for cakephp
in public index.php
define('MAINTENANCE', 0);
if(MAINTENANCE > 0 && $_SERVER['REMOTE_ADDR'] !='188.YOUR.IP.HERE')
{
require('maintenance.php'); die();
}
Then just change MAINTENANCE = 1 when you want to take your site down and it will still be viewable from your home/office.
BONUS: Works with all versions of cake!
A more elegant way would be to add a route overriding any other one at the very top of routes.php:
//Uncomment to set the site to "under construction"
Router::connect('/*', array('controller' => 'pages', 'action' => 'underConstruction'));
//any other route should be underneath
If you want to add any condition you can also do it here:
define('MAINTENANCE', 0);
if(MAINTENANCE > 0 && $_SERVER['REMOTE_ADDR'] !='188.YOUR.IP.HERE')
Router::connect('/*', array('controller' => 'pages', 'action' => 'underConstruction'));
}
We'll need to create a custom Dispatch Filter,CakePHP has you covered.
check below link
http://josediazgonzalez.com/2013/12/13/simple-application-maintenance-mode/

CakePHP page with no headers/footers

In a download page for a blob from a database, how would I make it so that no other output is sent? Right now it's sending the header, debug info, and a footer. How do I make it so that none of that is sent, just for that view?
you can create an clear layout (e.g. empty.ctp ) in you layouts folder, only with
<?php echo $content_for_layout ?>
and then in you action where you're getting your blob data use that layout
$this->layout = 'empty.ctp';
and also to disable debugging, in your controllers use
Configure::write('debug',0);
if you're unable to create new layout you could try this.
$this->layout = null;
$this->render("view_name");
If you're using this to download files, you should use the Media view in cakePHP
http://book.cakephp.org/view/1094/Media-Views
$this->view = 'Media';
$params = array(
'id' => 'example.zip',
'name' => 'example',
'download' => true,
'extension' => 'zip', // must be lower case
'path' => APP . 'files' . DS // don't forget terminal 'DS'
);
CakePhp 2.3 users :
use Sending files from the Book
CakePhp 2.x users :
use '$this->viewClass' instead of '$this->view'
copy-paste ready full solution, right in any controller file:
<?php
public function download($file) {
$fsTarget = APP.WEBROOT_DIR.DS.'files'.DS.$file; // files located in 'files' folder under webroot
if (false == file_exists($fsTarget)){
throw new NotFoundException(__('Invalid file'));
}
$pathinfo = pathinfo($fsTarget);
$this->viewClass = 'Media';
$params = array(
'id' => $file,
'name' => $pathinfo['filename'], // without extension
'download' => true,
'extension' => $pathinfo['extension'], // must be lower case
'path' => dirname($fsTarget) . DS // don't forget terminal 'DS'
);
$this->set($params);
}
Hope this helps!

Resources