简体   繁体   中英

PHP CI: Undefined property -> Calling a private function

I have written a private function that allows me to call the name of the object that is being called for when I edit it but for some strange reason it is being picked up as an Undefined property why?

Troublesome Line:

$data['pageTitle'] = 'Edit '.$this->fieldTitle.' ';

Function:

private function fieldTitle($id)
{
    $this->uri->segment(4);

    $information = $this->form_model->showFieldInformation();

    foreach ($information as $feild) {

        $feildName = $feild->name;

    }
    return $fieldName;
}

I see two mistakes:

fieldTitle should be a function $this-><fieldTitle() and not a variable $this->fieldTitle

There is a typo in:

foreach ($information as $feild) {

    $feildName = $feild->name;

}
return $fieldName;

you are mistyping $fieldName and $feildName

$data['pageTitle'] = 'Edit '.$this->fieldTitle.' ';

Should be

$data['pageTitle'] = 'Edit '.$this->fieldTitle().' ';

Forgot the ()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM