顯示具有 symfony 標籤的文章。 顯示所有文章
顯示具有 symfony 標籤的文章。 顯示所有文章

2010年5月25日 星期二

Some notes for symfony

View Template Shortcuts

  • $sf_context: The whole context object (instance of sfContext)
  • $sf_request: The request object (instance of sfRequest) 
  • $sf_params: Parameters of the request 
  • $sf_user: The current user session object (instance of sfUser)

      Get XML information in symfony 1.4

      When parse a remote xml file, I use sfWebBrowserPlugin and get the right result, like this way:

      in actions code
      $tar = new sfWebBrowser();
      $tar->post(url_for('MsgTransfer/Recommender', true), http_build_query($this->form->getValues()));
      $this->xml = $tar->getResponseXML(); 
      
      in template code
      php echo $xml->string;
      then i get the error message:
      Fatal error: Call to undefined method SimpleXMLElement::__toString() in /usr/share/php/symfony/escaper/sfOutputEscaperObjectDecorator.class.php on line 98

      The solution to solve is use:
      php echo $sf_data->getRaw('xml')->string;
      

      2009年8月28日 星期五

      sfGuardPlugin Data-Dump & Data-Load UserPassword error solution

      Please rewrite signin function from sfGuardPlugin/lib/model/plugin/PluginsfGuardUser.php as following:

      (For Propel)
      public function setPassword($password)
        {
          if (!$password && 0 == strlen($password))
          {
            return;
          }
      /*
       * iba: if salt is set then probly the passwort is already encrpted
       * thus call setPassword without user_funx algorythm
       */
          /*--- Add Here ---*/
          $fromdump = false;
          if($this->isNew() && $this->getSalt()){
            $fromdump=true;
          }
          /*----------------*/
      
          if (!$salt = $this->getSalt())
          {
            $salt = md5(rand(100000, 999999).$this->getUsername());
            $this->setSalt($salt);
          }
          $algorithm = sfConfig::get('app_sf_guard_plugin_algorithm_callable', 'sha1');
          $algorithmAsStr = is_array($algorithm) ? $algorithm[0].'::'.$algorithm[1] : $algorithm;
          if (!is_callable($algorithm))
          {
            throw new sfException(sprintf('The algorithm callable "%s" is not callable.', $algorithmAsStr));
          }
          $this->setAlgorithm($algorithmAsStr);
      
      /*
       * iba: if passwort is already encrypted dont encrypt it again.
       */
          /*--- Add Here ---*/
          if($fromdump){
            parent::setPassword($password);
          }
          /*----------------*/
      
          else{
            parent::setPassword(call_user_func_array($algorithm, array($salt.$password)));
          }   
          
        }
      

      2009年8月5日 星期三

      New way to loadHelper for symfony 1.2

      In Action class file:

      Before -
      sfLoader::loadHelper("helper");

      New way -
      sfContext::getInstance()->getConfiguration()
      ->loadHelpers("helper");
      

      2009年7月22日 星期三

      symfony "schema.yml" file

      `schema.yml` 文件包含了所有的資料庫表格的規劃描述。每個都通過如下訊息描述:

      * `type`: 資料類型 (`boolean`, `tinyint`, `smallint`, `integer`, `bigint`, `double`,
      `float`, `real`, `decimal`, `char`, `varchar(size)`, `longvarchar`,
      `date`, `time`, `timestamp`, `blob`, `clob`)

      * `required`: 設為 `true` 用來表示此欄位內容不得為空白

      * `index`: 設為 `true` 為該表格創建索引鍵,或者設置 `unique` 在該表格上創建唯一索引鍵。

      對於設置資料內容為 `~` (`id`, `created_at`, 和 `updated_at`) 的資料,symfony 會探測最合適的
      配置方式(`id`是作為主鍵,`created_at` 和 `updated_at`是時間戳記)

      **NOTE**
      `onDelete`: 屬性定義了外鍵的`ON DELETE`行為。Propel 只是 `CASCADE`, `SETNULL`,
      `RESTRICT` 等幾種。
      例如,删除一條 `job` 紀錄後,`jobeet_job_affiliate` 中所有相關
      紀錄也會自動通過數據庫删除。如果底層的數據庫引擎不支持該功能,Propel可以做到。

      2009年7月21日 星期二

      Backend Admin FileUpload for symfony 1.2

      This approach is to provide a path option to sfValidatorFile...
      --------------------------------------------------------------
      // lib/form/StudentForm.class.php
      class StudentForm extends BaseStudentForm
      {
          public function configure()
          {
              $this->widgetSchema['photo'] = new sfWidgetFormInputFile();
              $this->validatorSchema['photo'] = new sfValidatorFile(array(
              'path' => sfConfig::get('sf_web_dir').'/uploads/students',
              ));
          }
      }
      --------------------------------------------------------------
      And write a generatePhotoFilename() method on Student (assuming "Photo" is the phpName for the field name "photo")
      --------------------------------------------------------------

      // lib/model/Student.php
      class Student extends BaseStudent
      {
          public function generatePhotoFilename(sfValidatedFile $file)
          {
              return $file->getOriginalName();
          }
      }
      

      --------------------------------------------------------------

      This way is probably the preferred approach as it makes for a thinner controller.