对于tabs,widget/tabs.phtml,

 

<?php

/**

 * Magento

 *

 * NOTICE OF LICENSE

 *

 * This source file is subject to the Academic Free License (AFL 3.0)

 * that is bundled with this package in the file LICENSE_AFL.txt.

 * It is also available through the world-wide-web at this URL:

 * http://opensource.org/licenses/afl-3.0.php

 * If you did not receive a copy of the license and are unable to

 * obtain it through the world-wide-web, please send an email

 * to license@magentocommerce.com so we can send you a copy immediately.

 *

 * DISCLAIMER

 *

 * Do not edit or add to this file if you wish to upgrade Magento to newer

 * versions in the future. If you wish to customize Magento for your

 * needs please refer to http://www.magentocommerce.com for more information.

 *

 * @category    design

 * @package     default_default

 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)

 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)

 */

?>

<?php if($this->getTitle()): ?>

    <h3><?php echo $this->getTitle() ?></h3>

<?php endif ?>

<?php if(!empty($tabs)): ?>

//1

<ul id="<?php echo $this->getId() ?>" class="tabs">

<?php foreach ($tabs as $_tab): ?>

<?php if (!$this->canShowTab($_tab)): continue;  endif; ?>

    <li <?php if($this->getTabIsHidden($_tab)): ?> style="display:none"<?php endif; ?>>

        <a href="<?php echo $this->getTabUrl($_tab) ?>" id="<?php echo $this->getTabId($_tab) ?>" name="<?php echo $this->getTabId($_tab, false) ?>" title="<?php echo $this->getTabTitle($_tab) ?>" class="tab-item-link <?php echo $this->getTabClass($_tab) ?><?php if (preg_match('//s?ajax/s?/', $_tab->getClass())) {?> notloaded<?php }?>">

            <span><span class="changed" title="<?php echo $this->__('The information in this tab has been changed.') ?>"></span><span class="error" title="<?php echo $this->__('This tab contains invalid data. Please solve the problem before saving.') ?>"></span><?php echo $this->getTabLabel($_tab); ?></span>

        </a>

        <div id="<?php echo $this->getTabId($_tab) ?>_content" style="display:none;"><?php echo $this->getTabContent($_tab) ?></div>

    </li>

<?php endforeach; ?>

</ul>

 

/////####

<script type="text/javascript">

    <?php echo $this->getJsObjectName() ?> = new varienTabs('

//2

<?php echo $this->getId() ?>', 

//3

'<?php echo $this->getDestElementId() ?>', 

//4

'<?php echo $this->getActiveTabId() ?>', 

//5

<?php echo $this->getAllShadowTabs()?>);

</script>

<?php endif; ?>

 

这个文件就是tabs显示的文件,分析如下

 

 

1$this->getId()方法。

 

1.1

这个是用来做tabs点击区域的css标示,js就是通过这个id号来进行取得标示,

这个值的设置是在

Profile_Block_Adminhtml_Profile_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs

中,定义

 $this->setId('profiles_tabs');

1.2

然后在//1这个位置将ul的id名字设置为$this->getId();,

1.3

然后再js代码段(/////####位置处),的//2将该ID做为参数传入varienTabs()函数中,

 

2

getDestElementId() 

2.1

$this->getDestElementId()

这个是form的ID

在class RichardMason_Profile_Block_Adminhtml_Profile_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs

{$this->setDestElementId('edit_form');

设置destElenentId的值,

2.2

在:RichardMason_Profile_Block_Adminhtml_Profile_Edit_Form extends Mage_Adminhtml_Block_Widget_Form处

$form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post', 'enctype' => 'multipart/form-data'));

        $form->setUseContainer(true);

        $this->setForm($form);

在构造form的时候将css标示ID写入其中array中的id的值就是edit_form,

2.3

 

<script type="text/javascript">

    <?php echo $this->getJsObjectName() ?> = new varienTabs('

//2

<?php echo $this->getId() ?>', 

//3

'<?php echo $this->getDestElementId() ?>', 

 

将其值写入js函数里面。

3

<?php echo $this->getAllShadowTabs()?>);

通过在xml文件中的配置情况,可以加载内嵌的block。

小结:

总体来说,

 

1.在tabs.PHP文件里面写入,id ,destElementId,的值,通过set()方法。

2.在phtml段,

tabs,是在tabs.phtml文件中,通过get()方法得到值

DestElementId是在Profile_Block_Adminhtml_Profile_Edit_Form,通过方法:

$form = new Varien_Data_Form(array('id' => 'edit_form'直接写入。

 

form的css标示ID

3.在js段通过get()方法将id,destElementId的值写入js函数  varienTabs()

 

 

 

额外说明:

profile/edit/form.php

profile/edit/tab/main.php

profile/edit/tab/meta.php

使用的前台页面都是widgt/form.php!

 

 

public function getFormHtml()

    {

        if (is_object($this->getForm())) {

            return $this->getForm()->getHtml();

        }

        return '';

    }

 

 

 

 

    /**

     * Get form object

     *

     * @return Varien_Data_Form

     */

 public function getForm()

    {

        return $this->_form;

    }

 

在2.2中队form的定义:

$form

故执行:$this->getForm()->getHtml();

 

public function getHtml()

    {

        return $this->toHtml();

    }

 

profile/edit/form.php,虽然和main.php,meta.php使用的同一个模板,但是他没有

 

$fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('profile')->__('Content')));

 

        //profile_id

        if ($model->getProfileId()) {

            $fieldset->addField('profile_id', 'hidden', array(

                'name' => 'profile_id',

            ))

使用这个方法给自己加载attribute,故,他是空的,没有属性集合。

 

profile/edit/tab/main.php

profile/edit/tab/meta.php

 

到此为止,grid的编辑部分基本摸清!!!