Ejemplo n.º 1
0
 /**
  * Saves the object to the disk.
  */
 public function save()
 {
     $isNewFile = !strlen($this->fileName);
     /*
      * Generate a file name basing on the URL
      */
     if ($isNewFile) {
         $dir = rtrim(static::getFilePath($this->theme, ''), '/');
         $fileName = trim(str_replace('/', '-', $this->getViewBag()->property('url')), '-');
         if (strlen($fileName) > 200) {
             $fileName = substr($fileName, 0, 200);
         }
         if (!strlen($fileName)) {
             $fileName = 'index';
         }
         $curName = trim($fileName) . '.htm';
         $counter = 2;
         while (File::exists($dir . '/' . $curName)) {
             $curName = $fileName . '-' . $counter . '.htm';
             $counter++;
         }
         $this->fileName = $curName;
     }
     parent::save();
     if ($isNewFile) {
         $pageList = new PageList($this->theme);
         $pageList->appendPage($this);
     }
 }