天生我才必有用

Drupal 文件系统

Posted in PHP    作者:Ray    2011年八月25日

Drupal7 的文件系统使用了3种自定义的URI,操作起来和访问http、ftp协议类似,比较直观。

  • public://
  • private://
  • temp://

用户还可以自己定义stream wrapper,来实现自己的URI。具体内容参见:DrupalStreamWrapperInterface。

当调用file_save_data时,有三种模式可以选择:

  • FILE_EXISTS_REPLACE:覆盖原有的文件
  • FILE_EXISTS_RENAME:对文件名从新命名,自动添加_1,_2等后缀。
  • FILE_EXISTS_ERROR:什么事情都不做,直接返回错误。

默认为FILE_EXISTS_RENAME模式。

如果保存成功则返回drupal的file对象。

标签:

Drupal Test Part 1

Posted in PHP    作者:Ray    2011年八月23日

最新的Drupal7提供了单元测试的功能,为你的代码健壮性提供了保证。

  1. 建立一个module.test的文件作为你模块的测试文件,module请替换成你的模块名称。
  2. 建立一个继承DrupalWebTestCase的类,并实现其中的getInfo的函数。
  3. 添加一个setUp的函数,这个函数类似所有单元测试中的setup函数,不过在这个函数中必须加入parent::setup(‘module’),其中module是你的模块名称。
  4. 在后台的激活testing模块。
  5. 在admin/config/development/testing/设定页面中,点击“Clean Environment”按钮,就可以在列表中看到你的测试模块了。
标签:

Magento定制主菜单

Posted in PHP    作者:Ray    2011年三月10日
标签:

Magento转换URL

Posted in PHP    作者:Ray    2011年三月4日

Get the base url

1
2
3
4
5
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); // default
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);

Get the skin url

1
$this->getSkinUrl();
标签:

Magento定制Sidebar

Posted in PHP,技术    作者:Ray    2011年三月3日

删除Paypal Partner

<remove name=”paypal.partner.right.logo” />  <!–paypal logo–>

删除Community Poll

<remove name=”right.poll”/>
<remove name=”left.poll”/>

删除Tags

<remove name=”tags_popular”/>

删除Compare Products

<remove name=”catalog.compare.sidebar” />  <!–product compare–>

删除Reorder

<remove name=”sale.reorder.sidebar”/>

删除WishList

<remove name=”wishlist_sidebar”/>

删除Dog

<remove name=”left.permanent.callout” />  <!–the dog–>

删除Back to School

<remove name=”right.permanent.callout” />  <!–back to school–>

删除购物车

<remove name=”cart_sidebar” /> <!–cart sidebar–>

删除recently viewed product

<remove name=”left.reports.product.viewed” /> <!–recently viewed prod–>
<remove name=”right.reports.product.viewed” /> <!–recently viewed prod–>

删除recently compared product

<remove name=”right.reports.product.compared” /> <!–recently compared prod–>

更多信息请参考Turning On and Off Magento’s Default Blocks

标签:

Drupal 测试邮件发送

Posted in PHP    作者:Ray    2011年三月3日

Reroute Email模块可以帮助你进行邮件发送的测试。

This module intercepts all outgoing emails from a Drupal site and reroutes them to a predefined configurable email address.

This is useful in case where you do not want email sent from a Drupal site to reach the users. For example, if you copy a live site to a test site for the purpose of development, and you do not want any email sent to real users of the original site. Or you want to check the emails sent for uniform formatting, footers, …etc.

This is also a good demonstration of what hook_mail_alter(), available in Drupal 5.x and later, can do.

标签:

Drupal 7常用theme hooks

Posted in PHP    作者:Ray    2011年三月1日

file_link
Returns HTML for a link to a file.

html_tag
Returns HTML for a generic HTML tag with attributes. This can often be too generic a theme hook to use, but is really useful for adding a tag to the of a document or for theming a tag inside a render element.

image
Returns HTML for an image. image_style Returns HTML for an image using a specific image style.

item_list
Returns HTML for a list of items which can optionally be nested.

links
Returns HTML for a list of links (cannot be nested).

more_link
Returns HTML for a more link, often used on blocks.

pager
Returns HTML for a pager query element, a list of pages for result sets too long for one page.

progress_bar
Returns HTML for an indicator showing a task’s progress.

table
Returns HTML for a table.

username
Returns HTML for a username.

user_list
Returns HTML for a list of users.

user_picture
Returns HTML for a picture configured for the user’s account.

标签: ,

Drupal t函数

Posted in PHP,技术    作者:Ray    2011年二月23日

Drupal supports translation is largely through the t() function.

The function takes an optional second argument。

1
2
$values = array('@user' => $username);
print t('Welcome, @user', $values);

If the placeholder begins with at sign @, then before it inserts the value, Drupal sanitizes the value using its internal check_plain() function.

1
2
$values = array('!url' => 'http://example.com');
print t('The website can be found at !url', $values);

If the placeholder begins with exclamation mark !,  then it will be entered with no escaping. We can do this safely only because we already know the value of URL.

1
2
$values = array('%color' => 'blue');
print t('My favorite color is %color.', $values);

If the placeholder begins with the percent sign %, it tells Drupal  to escape the code and to mark it as emphasized. (The content will be embedded in the em tag)

标签:

使用PHP读取Excel文件

Posted in PHP    作者:Ray    2009年十一月20日

可能这应该算得上一个很古老的问题,解决的也有多种多样,不过Internet上比较多的是Excel的保存的范例,所以写一篇如何读取Excel,可能对大家有所帮助。

  1. 使用COM接口调用,把Excel应用程序作为一个Server,PHP间接使用Excel来读取文件。
  2. 使用PHPExcel的程序包。它的优点不单单读取资料而且可以保存资料为Excel文件,同时还支持Excel 2007的格式。方法就是把Excel看作一个普通的Excel文件读取。
  3. 还有一种是PHP Excel Reader,它把Excel文件看作一个二进制文件读取,不过不支持新版本Excel文件。

方法2可能看起来不错,不过当你在读取资料大比较大的文件时,会有一个致命的缺点:内存溢出。因为它必须把整个Excel读入内存。有点像XML的DOM接口,不清楚是否有类型XML的SAX的方法。

方法3有类似方法2内存溢出的问题,同时对新版的支持较差。

方法1应该是属于非常传统的方式,只有支持COM程序接口就可。同时只有你能用当前安装的Excel打开此文件,你就可以通过COM接口读取文件。缺点就是你必须在你的电脑上安装Excel。不过对于大文件现在只能使用这个方法。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$doc = "test.xls" ;
$excel_app = new COM("Excel.Application", NULL, CP_UTF8) or die ("Please install the Excel. \n");
 
#$excel_app->Visible = 1;

$workbook = $excel_app->Workbooks->Open($doc) or die("Can't open ".$doc);
$worksheet = $workbook->WorkSheets(1);
$worksheet->activate;
 
$min_row    = $worksheet->UsedRange->Row;
$min_col    = $worksheet->UsedRange->Column;
$max_row    = $worksheet->UsedRange->Rows->Count;
$max_col    = $worksheet->UsedRange->Columns->Count;
 
for ($row = $min_row ; $row < $max_row; $row ++){
    for ($column = $min_col ; $column <= $max_col; $column ++){
       $value = $worksheet->Cells($row, $column)->value;
       echo $value."\n";
    }
}
$excel_app->Workbooks->Close();
$excel_app->Quit();
标签: , , ,

Zend Framework 1.9发布

Posted in PHP,技术    作者:Ray    2009年八月10日

感觉现在Zend Framework 更新了很快,可能和日益受到关注有关。不知不觉中已经发布到了1.9版本。

更新的内容可以查看:http://devzone.zend.com/article/4906-Zend-Framework-1.9.0-Released

我对Zend_Test_PHPUnit_Db和Zend_Queue比较感兴趣,特别是Zend_Queue的支持,特别是加入了对MemcacheQ的原生支持。

有空学习一下这些新内容,感觉Zend Framework在逐渐缩短和RoR之间的差距。在新版本发布之际,更新一下Zend Framework的帮助chm.

标签: ,