Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

php code problem

Posted on 2011-03-05
4
Medium Priority
?
309 Views
Last Modified: 2012-05-11
I know nothing about php and have inheritted some code that is not working.  See attachment.

There are three functions in the code.  Basically what it is trying to do is set a value to $pn in the function onPostParse.  This value $pn is then used in the other two functions.

Can anyone see anything that is wrong.  The value of $pn is always an empty string. I want to use it in when i create the files in the other two functions.

<?php

 
class MyHandlers {

        private $pn = "Unknown";


        function addEventHandlers (RequestContext $ctx) {
                $handler = $this;


                $ctx->addEventHandler (FileGeneratedEvent::PDF, $handler, "onGeneratedPDF");

                $ctx->addEventHandler (FileGeneratedEvent::XML, $handler, "onGeneratedXML");
                $ctx->addEventHandler (ParseFieldEvent::POST_PARSE, $handler, "onPostParse");
       }
 

        function onPostParse( ParseFieldEvent $event)
        {
          $field = $event->field;
          if($field->key == "personnummer"){
            if ($field->value == ""){
              $this->pn = "Unknown" ;
            }
            else {
              $this->pn = $field->value;
            }
          }
          else { $this->pn = "NotFound" ; }
         
         }


        function onGeneratedPDF (FileGeneratedEvent $event)
        {

                $docDir = "/smart/export/journal";
                $docId = $event->document->id;
                $retval = 0; 
                $lines = array();
                $fileName = $docDir . "/" . basename($event->file). $this->pn . ".jpg";
                exec( "/usr/bin/convert $event->file $fileName", $lines, $retval );
                   if ($retval != 0)
                       throw new Exception ("Could not create jpg. $event->file to $fileName");

        }

        function onGeneratedXML (FileGeneratedEvent $event)
        {
                $docDir = "/smart/export/journal";
                $docId = $event->document->id;
                $fileName = $docDir . "/" . basename($event->file). $this->pn .  ".xml" ;
                if(!copy($event->file, $fileName))
                        throw new Exception ("Could not copy XML file $event->file to $fileName");
        }


}
?>

Open in new window

0
Comment
Question by:soozh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35044362
Can you post the code which call the class function ?
I assume you did initialize the object of the class
$obj = new MyHandlers();
// and call the function with proper parameter
$obj->onPostParse($SOMEEVENT);

where $SOMEEVENT variable needs to have a $field inside.
0
 

Author Comment

by:soozh
ID: 35044378


Sorry but I do not have the rest of the code.  But you can assume that everything "external" works correctly.  

The purpose of the MyHandler code is to extend an existing system.  I know that the call works, files are saved etc.  Its just the $pn field is empty.

Perhaps I should somehow log the call to onPostParse so I know that it is setting up a value.
0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 2000 total points
ID: 35044400
Ok then put this into the function

        function onPostParse( ParseFieldEvent $event)
        {

          var_dump($event);

          $field = $event->field;
          if($field->key == "personnummer"){
            if ($field->value == ""){
              $this->pn = "Unknown" ;
            }
            else {
              $this->pn = $field->value;
            }
          }
          else { $this->pn = "NotFound" ; }
         
         }
0
 

Author Comment

by:soozh
ID: 35044425

ok and what shall i look for? Where is the dump.  Sorry i know nothing about php or linux.

Is the $pn variable declared correctly?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question