holy shit

寺夺喜从天降

调试Magento

I. 在app目录外调试
在Magento安装目录下,建立php文件(假设为list.php),内容如下:
    <?php 
       // initialize magento environment for 'default' store 
       require_once 'app/Mage.php'; 
       Mage::app('default'); 
       // Write your codes 
    ?>
然后http://server/magento/list.php
下面的例子可以输出所有category模型对应表的path字段
    <?php 
       // initialize magento environment for 'default' store 
       require_once 'app/Mage.php'; 
       Mage::app('default'); 
     
       //get categories collection 
       $categories = Mage::getModel('catalog/category')->getCollection(); 
       //$categories->getSelect()->where('entity_id= 1'); 
       $categories = $categories->load(); 
       foreach($categories AS $category) { 
          echo $category->getPath(); 
          echo "<br/>"; 
       } 
    ?>
II. 使用colleciton->getSelectSql()输出运行的SQL语句
    <?php 
      $collection = Mage::getModel('catalog/category')->getCollection(); 
      ..... 
      $collection->load(); 
      echo $colleciton->getSelectSql(); 
    ?>
III. 输出对象的类型
Magento常常产生非常大的对象,调试时如果使用var_dump($obj)会导致系统崩溃,这是常常使用
get_class($obj)
输出对象的类型,然后再慢慢分析这个类的作用!
$_category->getChildren()

posted @ 2011-05-28 16:09  潜水鱼  阅读(717)  评论(0编辑  收藏  举报

holy shit on foot