I am building a pdf conversion utility for my user.
I am working in CakePhp and my controller is receiving Ajax call.
Why i am getting Notice:8 error
Controller:
public function convertToPdf() {
$this->autoRender = false;
$pdf = new WkHtmlToPdf;
//$this->RequestHandler->respondAs('json');
// echo $convertData = json_encode($inputVal);
if ($this->RequestHandler->isAjax()) {
$pdfName = uniqid();
if ($_FILES['conversionSourceFile']) {
echo "File";
$pdf->addPage($_FILES['conversionSourceFile']['tmp_name']);
} elseif ($_POST['conversionSourceUrl']) {
echo "Url";
$pdf->addPage($_POST['conversionSourceUrl']);
} elseif ($_POST['conversionSourceHtml']) {
echo "Html";
$pdf->addPage('<html>' . $_POST['conversionSourceHtml'] . '</html>');
}
$saveToPath = 'upload/' . $pdfName . '.pdf';
if ($pdf->saveAs($saveToPath)) {
echo 'upload/' . $pdfName . '.pdf';
}
}
}
Error:
Notice (8): Undefined index: conversionSourceFile [APP/Controller/PdfsController.php, line 42]
Code Context
if ($this->RequestHandler->isAjax()) {
$pdfName = uniqid();
if ($_FILES['conversionSourceFile']) {
PdfsController::convertToPdf() - APP/Controller/PdfsController.php, line 42
ReflectionMethod::invokeArgs() - [internal], line ??
Controller::invokeAction() - CORE/Cake/Controller/Controller.php, line 486
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 187
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 162
[main] - APP/webroot/index.php, line 109
To avoid notice in your code you have to use isset() OR !empty().
Using isset() and !empty() you can check whether variable is set and does not have an empty value.
e.g,
if (isset($_FILES['conversionSourceFile'])) {
// your code
}
OR
if (!empty($_FILES['conversionSourceFile'])) {
// your code
}
Simply check to isset $_FILES superglobal variable to prevent notice when not set.
if (isset($_FILES['conversionSourceFile'])) {
// Do more stuff
}
You need to check the first condition, with an "isset" or "!empty ()", like:
if(isset($_FILES['conversionSourceFile'])){...}
I solved the error "Notice (8): Undefined index" changing the order var $ uses.
before:
class GastosController extends AppController {
var $uses = array('Comprobante','Gasto','TipoGasto');
...
...
..
After:
class GastosController extends AppController {
var $uses = array('Gasto','Comprobante','TipoGasto');
..
..
..
Put the name that corresponds to the class (Gasto) first.
Related
i have this error in my prestashop 1.7 project when i enable mode degub:
ContextErrorException Notice: Undefined index: product in ps_sharebuttons.php line 138.
the line 138 looks like :
$key = 'ps_sharebuttons|' . $params['product']['id_product'];
full code:
public function renderWidget($hookName, array $params)
{
$key = 'ps_sharebuttons|' . $params['product']['id_product'];
if (!empty($params['product']['id_product_attribute'])) {
$key .= '|' . $params['product']['id_product_attribute'];
}
if (!$this->isCached($this->templateFile, $this->getCacheId($key))) {
$this->smarty->assign($this->getWidgetVariables($hookName, $params));
}
please help!
Well this seems an issue with the ps_sharebuttons module, check for an up-to-date version, maybe ?
If you just want get rid of the warning, just modify the code as follow :
public function renderWidget($hookName, array $params)
{
if (isset($params['product'])) {
$key = 'ps_sharebuttons|' . $params['product']['id_product'];
rest of the code here ...
}
i have php mvc project .
This is my router class.
router class job is include controller in main index page of website.
its work on localhost but when i uploaded on my host not working
what i do ?
<?php
class route
{
function __construct()
{
if(empty($_GET['url']))
{
$url = "index";
}
else
{
$url = $_GET['url'];
}
$url = explode("/",$url);
if(!empty($url[0]))
{
$controllername = "controllers/".$url[0].".php";
if(file_exists($controllername))
{
require($controllername);
$object = new $url[0];
//$object->loadmodel($url[0]);
if(!empty($url[1]))
{
if(method_exists($object,$url[1]))
{
if(!empty($url[2]))
{
$object->$url[1]($url[2]);
}
else
{
$object->$url[1]();
}
}
else
{
echo "Error";
}
}
else
{
echo "Error";
}
}
else
{
echo "Error";
}
}
}
}
this is my error in error_log
thrown in /home/mogeir/public_html/libs/route.php PHP Notice: Array
to string conversion in /home/mogeir/public_html/libs/route.php on
line 33 PHP Notice: Undefined property: admin::$Array in
/home/mogeir/public_html/libs/route.php on line 33 PHP Fatal error:
Uncaught Error: Function name must be a string in
/home/mogeir/public_html/libs/route.php:33
Use the following function call forms instead - the commented ones are correct alternatives too. See call_user_func and call_user_func_array.
if (!empty($url[2])) {
$object->{$url[1]}($url[2]);
// Alternative 1
// call_user_func(array($object, $url[1]), $url[2]);
// Alternative 2
// call_user_func_array(array($object, $url[1]), array($url[2]));
} else {
$object->{$url[1]}();
// Alternative 1
// call_user_func(array($object, $url[1]));
// Alternative 2
// call_user_func_array(array($object, $url[1]), array());
}
You said:
its work on localhost but when i uploaded on my host not working what i do ?
That has to do with the error reporting activation or with difference in PHP version.
I am working on a custom web shop project. Currently I am experiencing a strange error when using one of my classes:
namespace Services\MyServices;
class MyAppService {
protected function someMethod($transfer_id) {
...
$hash1 = sha1($someValue1);
$hash2 = sha1($someValue2);
$hash3 = sha1($someValue3);
// The following code is in line 144
$checkHash = (($hash1 == $transfer_id) || ($hash2 == $transfer_id) || ($hash3 == $transfer_id));
...
}
}
Fatal Error: Call to undefined function Services\MyAppService\ ()
Uncaught PHP Exception UndefinedFunctionException: "Attempted to call function " " from namespace "Services\MyAppService"." at /webspace/..../Services/MyAppService/MyAppService.php line 144
So line 144 is just a simple OR comparison, isn't it? What could be the problem here?
I have been receiving this notice and I don't understand why or how to fix it?
Notice: Undefined index: in /website/classes/Validate.php on line 56 Warning: exif_imagetype(): Filename cannot be empty in /website/classes/Validate.php on line 56
This is what I am doing to get this notice.
$validate = new Validate();
if($validate->fileCheck('file')){
echo "success";
}else{
echo "failed";
}
That is where I thought I am sending the file name to the class which I then use in the class like this.
public function fileCheck($name){
$allowed = array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF);
$file = exif_imagetype($_FILES[$name]['tmp_name']);
if(in_array($file, $allowed)){
return true;
}
return false;
}
If anyone could help me understand why it is throwing this Notice and how to solve it I would very much appreciate it.
I've written the following piece of code:
Class stackOverflowExample {
private $hash;
private $cookie_file;
public function __construct(){
#session_start();
if(isset($_SESSION['gc_hash'])){
$this->$hash = $_SESSION['gc_hash'];
}else{
$this->$hash = md5(time());
$_SESSION['gc_hash'] = $this->$hash;
}
$this->$cookie_file = "./cookies/{$this->$hash}.txt";
}
}
But I'm getting this error
Notice: Undefined variable: hash in
/var/www/gausie/gc/GeoCaching.Class.php on line 21
Fatal error: Cannot access empty property in
/var/www/gausie/gc/GeoCaching.Class.php on line 21
In the original code, line 21 refers to $this->$hash = $_SESSION['gc_hash'];.
I can't see why this is happening, although I'm new to OO PHP. Any ideas?
just replace $this->$hash by $this->hash
$this->$hash means variable with name equals to variable $hash value