Вопрос

public function save(PropelPDO $con = null)
{
  if ($this->isNew() && !$this->getExpiresAt())
  {
    $now = $this->getCreatedAt() ? $this->getCreatedAt('U') : time();
    $this->setExpiresAt($now + 86400 * sfConfig::get('app_active_days'));
  }

  return parent::save($con);
}

I don't understand return parent::save($con) please help me, thanks

Это было полезно?

Решение

It's calling the parent method save so whatever class this one extends from it's calling that method.

class Animal {
    public function getName($name) {
        return "My fav animal: " . $name;   
    }
}

class Dog extends Animal {
    public function getName($name) {
        return parent::getName($name);
    }
}

$dog = new Dog();
echo $dog->getName('poodle');

Другие советы

This class extends a Propel Model class which also has a save() method. This save method overrides the parent's save() method. When this overridden save() is invoked, it first does some work related to this concrete class, then invokes the parent's save() which will persist the object's properties in database.

If you look at the class declaration, it will say something like

class ThisClass extends anotherClass. 

The line you don't understand is returning the output of the save() method in anotherClass

parent

is the keyword that means "the class that this class is extending"

the :: (Scope Resolution Operator) allows you to call that method -- provided it is declared as static without instantiating the class --

Unless there is something else going on, you should be able to replace that line with

return $this->save($con);

The :: is the scope resolution operator. It allows you to access properties or methods from a class.

The parent keyword refers to the parent class of the current class.

With that in mind, your return statement is calling the save() method of your class' parent.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top