Fatal Error: Call to undefined method FPDF - fatal-error

I got this error message. Please help me solve that.
Fatal error: Call to undefined method FPDF::check() in C:\xampp\htdocs\sikembul\application\views\viw_slip_gaji.php on line 38
this my code
<?php
$GLOBALS['a']=2;
$GLOBALS['alpha']=3;
$GLOBALS['beta']=5;
function check($num)
{
if ($num=="1")
{
global $a;
global $alpha;
global $beta;
$total = $a*$alpha*$beta;
$this->fpdf->Cell(50,5,'final',1,0,'L');
$this->fpdf->Cell(8,5,'xx.',1,0,'L');
$this->fpdf->Cell(20,5,$total,1,1,'R');
}
else
{
global $a;
global $alpha;
global $beta;
$total = $a-$alpha-$beta;
$this->fpdf->Cell(50,5,'final',1,0,'L');
$this->fpdf->Cell(8,5,'xx.',1,0,'L');
$this->fpdf->Cell(20,5,$total,1,1,'R');
}
}
$this->fpdf->FPDF('P','mm','A5');
$this->fpdf->SetMargins(10,10,10);
$this->fpdf->AddPage();
$this->fpdf->setFont('Times','B',9);
$this->fpdf->Cell(130,5,'Here Some Text to Display',0,1,'C');
$this->fpdf->check(1);
$this->fpdf->Output('generate.pdf','I');
?>
FYI, everything works fine when i disable the function.
Thanks for all of the help and comments.

You can try this. Passing the instance to the function may work. This is just a quick sample and may not work as expected, but it illustrates what I was suggesting in the comment.
<?php
$GLOBALS['a']=2;
$GLOBALS['alpha']=3;
$GLOBALS['beta']=5;
function check($num, &$fpdf)
{
global $a;
global $alpha;
global $beta;
if ($num=="1")
{
$total = $a*$alpha*$beta;
$fpdf->Cell(50,5,'final',1,0,'L');
$fpdf->Cell(8,5,'xx.',1,0,'L');
$fpdf->Cell(20,5,$total,1,1,'R');
}
else
{
$total = $a-$alpha-$beta;
$fpdf->Cell(50,5,'final',1,0,'L');
$fpdf->Cell(8,5,'xx.',1,0,'L');
$fpdf->Cell(20,5,$total,1,1,'R');
}
}
$this->fpdf->FPDF('P','mm','A5');
$this->fpdf->SetMargins(10,10,10);
$this->fpdf->AddPage();
$this->fpdf->setFont('Times','B',9);
$this->fpdf->Cell(130,5,'Here Some Text to Display',0,1,'C');
check(1, $this->fpdf);
$this->fpdf->Output('generate.pdf','I');
?>

Related

Yii, already define index but `Undefined Index`

I have already properly defined the index to be POST-ed but still it says Undefined Index
Below is my code:
in the _form.php:
<?php echo $form->labelEx($model,'clientPackagedService_id'); ?>
<?php $client = Client::model()->findByPk(1);?>
<?php echo $form->dropDownList($model, 'clientPackagedService_id', CHtml::listData($client->clientPackagedservices(array('condition'=>'client_id='.$client->id.' AND booking_id IS NULL')),'id','packagedServiceInfo'),
array(
'disabled'=>'disabled',
'prompt'=>'Select Packaged Service...',
'ajax' => array( 'type'=>'POST', //request type
'url'=>CController::createUrl('updateMasseuseAndStationListPSID'), //url to call.
//This line-> 'data'=>array('clientPackagedService_id'=>'js:this.value', 'dt'=>'js:$("#Booking_date").val()', 'timeStart'=>'js:$("#Booking_timeStart").val()'),
'dataType'=>'json',
'success'=>'js:function(data) {
//alert(data.masseuse);
var mass="#'.CHtml::activeId($model, 'masseuse_id').'";
$(mass).html(data.masseuse);
$(mass).trigger("chosen:updated");
$(mass+"_chzn").css("width","300px");
$(mass+"_chzn > .chzn-drop").css("width","298px");
var station="#'.CHtml::activeId($model, 'station_id').'";
$(station).html(data.station);
$(station).trigger("chosen:updated");
$(station+"_chzn").css("width","300px");
$(station+"_chzn > .chzn-drop").css("width","298px");
//alert(data.timeEnd);
var timeEnd="#'.CHtml::activeId($model, 'timeEnd').'";
$(timeEnd).val(data.timeEnd);
}',
)
)
); ?>
in the controller.php:
public function actionUpdateMasseuseAndStationListPSID(){
$sid = Booking::getServices($_POST['clientPackagedService_id']);
....(codes to update Masseuse, Station, and TimeEnd.
}
in the model.php
public static function getServices($cpsID){
$psID = Yii::app()->db->createCommand('SELECT packagedService_id FROM client_packagedservice WHERE id='.$cpsID)->queryAll();
$sID = Yii::app()->db->createCommand('SELECT service_id FROM packaged_service WHERE id = '.$psID)->queryAll();
return $sID;
}
As you can see, I have already posted the appropriate name $_POST['clientPackagedService_id'] in the controller.php, but I still get the Error 500: Undefined index: clientPackagedService_id.
Did I do something wrong somewhere? Please advise. Thanks
I think problem is the data your are posting with ajax request. This is your data:
'data'=>array('clientPackagedService_id'=>'js:this.value', 'dt'=>'js:$("#Booking_date").val()', 'timeStart'=>'js:$("#Booking_timeStart").val()'),
Try to change it into this:
'data'=>array('clientPackagedService_id'=>'js:$(this).value', 'dt'=>'js:$("#Booking_date").val()', 'timeStart'=>'js:$("#Booking_timeStart").val()'),
Best way for debugging ajax request is to inspect browser's console. You can see ajax's posted data and realize your problem.

Using forge.prefs always returns undefined

I'm trying to use forge.prefs to store variables but nothing seems to be saving.
I am using the following:
var all = forge.prefs.keys(function(keysArray){ return keysArray},
function(content){return content});
forge.logging.log(all);
But this always returns undefined
I am also having the same issue with setting, nothing seems to be working.
var set = forge.prefs.set(key,value,function(){},function(content){return content;});
forge.logging.log(set);
Again returns undefined and no error or anything.
Am I doing something wrong?
Using the docs found here
UPDATE
I won't to do something like the following:
var get = forge.prefs.get(key,
function(value){return value;},
function(error){forge.logging.log(error);
});
if(get){
// do something here
}else{
// do something here
}
Those methods are asynchronous which means that subsequent code might be executed before the callback success and error functions are returned. All subsequent code that relies on the outcome of this should run within the callback:
forge.prefs.keys(function(keysArray){ // success
forge.logging.log(keysArray);
// subsequent code relying on a positive outcome here ...
},
function(error){ // error
forge.logging.log('Something bad happened: ' + error);
});
forge.prefs.set(key, value, function(){ // success
forge.logging.log(key + ' was properly set);
// subsequent code relying on a positive outcome here ...
},
function(error){ // error
forge.logging.log('Something bad happened: ' + error);
});
UPDATE: use this to achieve the updated part of your question:
var get;
forge.prefs.get(key, function(value){ // success
get = value;
forge.logging.log('Found value: ' + get);
// subsequent code here ...
},
function(error){ // error
forge.logging.log('Something bad happened: ' + error);
});
It appears you're not returning anything in the forge.pref.set success function. Your return content; is in the error function so if it's not throwing an error you won't return anything.
Try this:
var set = forge.prefs.set(key,value,function(){ return value; },function(content){return content;});
forge.logging.log(set);

The youtube API sometimes throws error: Call to a member function children() on a non-object

When i launch the php script, sometime works fine, but many other times it retrieve me this errror
Fatal error: Call to a member function children() on a non-object in
/membri/americanhorizon/ytvideo/rilevametadatadaurlyoutube.php on line
21
This is the first part of the code
// set feed URL
$feedURL = 'http://gdata.youtube.com/feeds/api/videos/dZec2Lbr_r8';
// read feed into SimpleXML object
$entry = simplexml_load_file($feedURL);
$video = parseVideoEntry($entry);
function parseVideoEntry($entry) {
$obj= new stdClass;
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/'); //<----this is the doomed line 21
UPDATE: solution adopted
for ($i=0 ; $i< count($fileArray); $i++)
{
// set feed URL
$feedURL = 'http://gdata.youtube.com/feeds/api/videos/'.$fileArray[$i];
// read feed into SimpleXML object
$entry = simplexml_load_file($feedURL);
if (is_object($entry))
{
$video = parseVideoEntry($entry);
echo ($video->description."|".$video->length);
echo "<br>";
}
else
{
$i--;
}
}
In this mode i force the script to re-check the file that caused the error
You are first of all calling a function:
$entry = simplexml_load_file($feedURL);
That function has a return value. You find it documented on the manual page of that function:
http://php.net/simplexml_load_file
Then you use that return value in form of a variable $entry without verifying that the function call was successful.
Because of that, you run into an error next. However your error/mistake is how you treat the return value of the function.
Not dealing with return values properly is like calling for trouble. Read about the function you use, check the return value(s) and proceed according to success or error conditions.
$entry = simplexml_load_file($feedURL);
if (FALSE === $entry)
{
// youtube not available.
}
else
{
// that's what I love!
}
Sometimes? Really?
Take a look at this:
<?php
$dummy; //IN FACT, this var is NULL now
// Will throw exactly the same error you get
$dummy->children();
Why? Because, we can call method from an object type.
So, if you wanna avoid errors like this one, next time you would call the method ensure that it's "possible".
<?php
if ( is_object($dummy) && method_exists($dummy, 'children') ){
//sure it works
$dummy->children();
}

LuaJava Setting Error Handler for LuaState.pcall(a,b, error_function_index)?

I am trying to call:
LuaState.pcall(num_args,num_returns, error_handler_index).
I need to know how to set the error handler for this function. In fact, I think it would be nice it someone showed how to invoke a Lua function and get a numerical result back using LuaJava. This might save a lot of time and questions. I am looking but not finding the signature for the error function, and how to place it at the right point on the LuaState stack. All the Java->Lua examples are either printing a value with no return or they are setting values on a Java object passed in using Lua. I would like to see how to call a Lua function directly and get the result back.
Update: one solution is to pass no error handler using LuaState.pcall(1,1,0) by passing zero for the error handler:
String errorStr;
L.getGlobal("foo");
L.pushNumber(8.0);
int retCode=L.pcall(1,1,0);
if (retCode!=0){
errorStr = L.toString(-1);
}
double finalResult = L.toNumber(-1);
where calc.lua has been loaded:
function foo(n)
return n*2
end
Now is there a way to set an error handler as well? Thanks
If you also want the stack traceback (I'm sure you do :), you can pass debug.traceback as the error function. Take a peek at how it's implemented in AndroLua.
Basically, you have to make sure your stack is set up as follows:
Error handler (debug.traceback)
Function you want to call
Parameters
You can do it like this with your example:
L.getGlobal("debug");
L.getField(-1, "traceback"); // the handler
L.getGlobal("foo"); // the function
L.pushNumber(42); // the parameters
if (L.pcall(1, 1, -3) != 0) { ... // ... you know the drill...
Assuming you have a Lua function somewhere to handle the error:
function err_handler(errstr)
-- exception in progress, stack's unwinding but control
-- hasn't returned to caller yet
-- do whatever you need in here
return "I caught an error! " .. errstr
end
You can pass that err_handler function into your pcall:
double finalResult;
L.getGlobal("err_handler");
L.getGlobal("foo");
L.pushNumber(8.0);
// err_handler, foo, 8.0
if (L.pcall(1, 1, -3) != 0)
{
// err_handler, error message
Log.LogError( L.toString(-1) ); // "I caught an error! " .. errstr
}
else
{
// err_handler, foo's result
finalResult = L.toNumber(-1);
}
// After you're done, leave the stack the way you found it
L.pop(2);

can`t figure out error in my code, mixing jquery and razor

I am reading through a table in jquery and I am trying to pass the value to a method from a class. I am trying to write the following but can`t figure what is wrong.
The error message is on the line if...:
MvcUI\Views\Shared\employee.cshtml(170,81): error CS1646: Keyword, identifier, or string expected after verbatim specifier: #
MvcUI\Views\Shared\employee.cshtml(170,83): error CS1056: Unexpected character '$'
MvcUI\Views\Shared\employee.cshtml(170,90): error CS1056: Unexpected character '$'
MvcUI\Views\Shared\employee.cshtml(170,103): error CS1012: Too many characters in character literal
Help please.
if($.trim($(this).find('td:first').text())!='')
{
#{
if (MvcUI.Employee.ContainsName(#:$.trim($(this).find('td:first').text())))
{
#:$($(this).find('td:first').html($(this).find('td:first').text() + "<br />Name");
}
}
}
There 2 way to do what you want:
Preload employer names into some js array
Use ajax to check if name is registred
I will describe the second way.
The JS code:
var tdText = jQuery.trim($(this).find('td:first').text());
if(tdText != '') {
jQuery.post
(
'/some_route/employers/checkname',
{
name = tdText
},
function(rsp) {
if(rsp == 'true') {
alert("name is registered"); //replace by your code
}
else
{
alert("name isn't registered"); //replace by your code
}
}
);
}
The C# controller code:
[HttpPost]
public ActionResult CheckName(string name)
{
return Json(MvcUI.Employee.ContainsName(name));
}

Resources