Hi,

i doing personal page module.

this is the my edit profile page code.

i have error in 126.call to undefind error.
this is error line.
$personal->$personal=getDataInArray();

what is the proble?
any body plz help me.

public function executeEdit(sfWebRequest $request)
  {
    $this->frm_edit = new PersonalForm();
     $personal=array();
     $error=array();
     //if they submitted the form
      if($request->isMethod("post")) {
      //if they want to change their detail
      // if($request->getParameter("type") =="detail") {
       //get the submitted values
        $personal=$request->getParameter("personal");
        //check birth date validation
        /* if(!$personal["birth_date_day"] || !$personal["birth_date_month"] || !$personal["birth_date_year"]) {
         $error["birth_date"]=sfConfig::get("app_notice_label_empty");
         }
          elseif (!checkdate($personal["birth_date_month"], $personal["birth_date_day"], $personal["birth_date_year"])) {
                    $error["birth_date"] = sfConfig::get("app_notice_label_not_valid");
                }



               /* // check country validation
                if (!$personal["country_id"]) {
                    $error["country_id"] = sfConfig::get("app_notice_label_empty");
                }
                elseif (!Doctrine::getTable("Country")->find($personal["country_id"])) {
                    $error["country_id"] = sfConfig::get("app_notice_label_not_valid");
                }

                // check zone validation
                if ($personal["zone_id"]) {
                    $zone = Doctrine::getTable("Zone")->find($personal["zone_id"]);
                    if (!$zone || $zone->getCountryId() != $personal["country_id"]) {
                        $error["zone_id"] = sfConfig::get("app_notice_label_not_valid");
                    }
                }*/
                if (!$personal["occupation"]) {
                    $error["occupation"] = sfConfig::get("app_notice_label_empty");
                // check about me validation
                if (!$personal["about_me"]) {
                    $error["about_me"] = sfConfig::get("app_notice_label_empty");
                }
                // check total error
                /*if (count($error) == 0) {
                    $detail = $this->getUser()->getAttribute("detail");

                    // change the value for birth_date so it will be compatible with mysql
                    $personal["birth_date"] = date("Y-m-d", strtotime($personal["birth_date_year"] . "-" . $personal["birth_date_month"] . "-" . $personal["birth_date_day"]));
                    $detail->saveDataInArray($personal);
                    $this->getUser()->setAttribute("detail", $detail);
                    $this->getUser()->setFlash("notice_edit_profile", sfConfig::get("app_notice_edit_profile_success"));
                }*/
                }
                else {
                  $personal->personal=getDataInArray();
                // $personal = $this->getDataInArray();
                 }
                 // pass the variables for the template
        $this->personal = $personal;
        $this->error = $error;

        $this->countries = Doctrine::getTable("Country")->findAll();
        //$this->sex = Doctrine::getTable("Personal")->getSexInArray();
        //$this->relationshipStatus = Doctrine::getTable("Personal")->getRelationshipStatusInArray();

    }
    }



class Personal extends BasePersonal
{
public function getDataInArray()
    {
        $data = array();

        $data['user_id'] = $this->user_id;
       // $data['Firstname'] = $this->full_name;
        $data['sex'] = $this->sex;
        $data['birth_date'] = $this->birth_date;
        $data['relationship_status'] = $this->relationship_status;
        $data['country_id'] = $this->country_id;
        $data['zone_id'] = $this->zone_id;
        $data['occupation'] = $this->occupation;
        $data['about_me'] = $this->about_me;
        $data['what_i_do'] = $this->what_i_do;
        $data['what_i_go'] = $this->what_i_go;

        return $data;
    }
    public function saveDataInArray($data)
    {
        //$this->full_name = $data['full_name'];
        $this->sex = $data['sex'];
        $this->birth_date = $data['birth_date'];
        $this->relationship_status = $data['relationship_status'];
        $this->country_id = $data['country_id'];
        $this->zone_id = $data['zone_id'] == '' ? null : $data['zone_id'];
        $this->occupation = $data['occupation'];
        $this->about_me = $data['about_me'];
        $this->what_i_do = $data['what_i_do'];
        $this->what_i_go = $data['what_i_go'];

        $this->save();
    }
}

Recommended Answers

All 4 Replies

This method

 getDataInArray()

is it a method from the same class? If so, it should be coded like this

 $personal->personal= self::getDataInArray();

Try using the parent and self thing so that it does not give you any confusion during future edits..

Hi,
that problem solved.but no record insert in db.plz help me.

I just have one question for you, before I get involved in this question. In your codes, you have extended class BasePersonal..

and in your child class Personal you have

class Personal extends BasePersonal
{

## where is the constructor of your parent class??
## it should  be here?

if you want to get the output of a method from the same class, like in your codes should be at least modified to something similar to the codes below..

 public function getDataInArray()
{
$data = array();
$data['user_id'] = $this->user_id;
// $data['Firstname'] = $this->full_name;
$data['sex'] = $this->sex;
$data['birth_date'] = $this->birth_date;
$data['relationship_status'] = $this->relationship_status;
$data['country_id'] = $this->country_id;
$data['zone_id'] = $this->zone_id;
$data['occupation'] = $this->occupation;
$data['about_me'] = $this->about_me;
$data['what_i_do'] = $this->what_i_do;
$data['what_i_go'] = $this->what_i_go;

$thisOutputData[] = $data;

return $thisOutputData;
}

Just a side note,... you can define your visibility of the method getDataInArray as private.

To access the array from the above output by antoher method, it should be written like this we don't need the data as variable in the method saveDataInArray

  public function saveDataInArray()
{
## lets harvest or dump the data from the method above.
$newData = self::getDataInArray();

foreach ($newData as $data){
//$this->full_name = $data['full_name'];
$this->sex = $data['sex'];
$this->birth_date = $data['birth_date'];
$this->relationship_status = $data['relationship_status'];
$this->country_id = $data['country_id'];
$this->zone_id = $data['zone_id'] == '' ? null : $data['zone_id'];
$this->occupation = $data['occupation'];
$this->about_me = $data['about_me'];
$this->what_i_do = $data['what_i_do'];
$this->what_i_go = $data['what_i_go'];

## I am not sure about the this->save() method below.
///$this->save();
}
}

I commented the this->save() in your function saveDatInArray, because I don't know where this method belongs. I could be from the parent? If so then the it should be executed like this.

 $execThis = parent::save()

That should trigger whatever arguments it has or to do.

Also, I would like to remind you that a coding technique like this in OOP is awfully bad.

$someVariable = $this->variable;

More acceptable is like this

$this->variable =  $someValue;

Although there is nothing wrong with that and the script is still functional, there are so called silent standards among coders that this type of scripting style should be avoided at all cost first, before you can actually code it like that. Of course, if there is nothing we can do to avoid it, you must type a comment above it.. I was almost got disowned by my family, when i wrote my code like that years back .

 ## this cannot be avoided and it is awfully wrong
 $this->variable = $this->variable;

another cool techniques or methods in coding in OOP are the setters and the getters... like

  private function setThis(){

    ## return output for the getter
    return $this->output;

    }

  public function getThis(){

  return (self::setThis());

  }

so, If you anticipating that the items in the data array is going to be used by other methods within the class or by the child class it should not be included in the constructor, so that you can redefined it somewhere else.. for example if it will be in the child class, let it be defined within the child class properties and then in the child class constructor, after the parent constructor has been declared.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.