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

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;
      

      2010年5月4日 星期二

      PHP: How to convert ISO character (HTMLEntities) to UTF-8?

      最近在寫針對 Amazon.com Bookstore 的 HTML Crawler 程式,

      發現原來 Amazon.com 的網頁編碼居然不完全都是 UTF-8 編碼,

      讓我抓下資料(ISO編碼)後,存不進預設編碼為 UTF-8 的資料庫,

      於是乎,我向咕狗大神詢問了一番,獲得了以下的解答:

      I’m facing problem in how to convert string from ISO to UTF8 previously. Due to the server configuration problem, all the UTF-8 char has been convereted into ISO (HTMLEntities) before it insert into db and those ISO character (HTMLEntities) break while showing in XML document. Now i found the solution to convert ISO character into UTF-8.

      The original utf-8 chinese words: "你好"
      Converted to ISO (HTMLEntities) : "& #20320;& #22909;"

      For you to convert the ISO string "& #20320;& #22909;" to become utf-8 chinese words: "你好", you need to use Multibyte String function (or mbstring extension). Example below uses mb_convert_encoding function to convert ISO (HTMLEntities) characters to UTF-8.

      ?php $str =  "& #20320;& #22909;";
      echo mb_convert_encoding($str, 'UTF-8', 'HTML-ENTITIES'); ?
      

      2009年8月1日 星期六

      FreeBSD 7.1 安裝 phpSysinfo & phpMyAdmin


      phpSysInfo:

      安裝:
      # cd /usr/ports/www/phpsysinfo/
      # make install clean
      編輯設定:
      # cd /usr/local/www/phpsysInfo/
      # cp config.php.new config.php
      # ee config.php
      修改你要的設定,例如語言、預設模板等等。
      接著修改 /usr/local/etc/apache22/httpd.conf
      Alias /phpsysinfo "/usr/local/www/phpsysInfo/"
      <Directory "/usr/local/www/">
      Options none
      AllowOverride Limit
      Order allow,deny
      Allow from all
      </Directory>
      接著重開 apache 即可。

      phpMyAdmin:

      安裝:
      # cd /usr/ports/databases/phpMyAdmin/
      # make install clean
      編輯設定檔:
      # cd /usr/local/www/phpMyAdmin/
      # cp config.sample.inc.php config.inc.php
      # ee config.inc.php

      在FreeBSD 7.1下,以下設定似乎可忽略 (因為我沒設定)

      $cfg['Servers'][$i]['auth_type'] = 'cookie' ;
      改為 $cfg['Servers'][$i]['auth_type'] = 'http' ;

      接著修改 /usr/local/etc/apache22/httpd.conf
      Alias /phpmyadmin "/usr/local/www/phpMyAdmin/"
      <Directory "/usr/local/www/">
      Options none
      AllowOverride Limit
      Order allow,deny
      Allow from all
      </Directory>
      如果你前面已經有加上 <Directory "/usr/local/www/">,則不需要在加上那段。
      最後重開 apache 即可。



      資訊轉載自 阿駕零零壹 感謝 <(__)>

      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.