您的位置:首页 > 编程语言 > PHP开发

使用widget控件的一般规律!!!

2010-12-29 00:42 337 查看
widget控件:

 

1

在使用widget控件的block,一般是不指定template的。

要么通过$this->$this->setTemplate('widget/form/container.phtml'),自己指定,

要么通过父类的构造函数里面的执行语句: $this->setTemplate('widget/form/container.phtml');来指定

2

加载子block:

$this->setChild('form', $this->getLayout()->createBlock($this->_blockGroup . '/' . $this->_controller . '_' . $this->_mode . '_form'));

一般是通过上面的方法加载,在子类中定义变量,在父类中通过上面的方法生成!

3

显示内部控件。

3.1直接通过调用子block显示内部控件的,getChildHtml。

3.2先调用一个函数,譬如:getFormHtml,通过函数读取action,然后得到内部控件显示的信息,然后再使用getChildHml()显示出来!

譬如: 

 

 public function getFormHtml()

    {   //$this->_children[$name];

        $this->getChild('form')->setData('action', $this->getSaveUrl());

        return $this->getChildHtml('form');

    }

 

 

 

  public function     gettSaveUrl()

    {

        return $this->getFormActionUrl();

    }

 

 

 

  public function getFormActionUrl()

    {

        if ($this->hasFormActionUrl()) {

            return $this->getData('form_action_url');

        }

        return $this->getUrl('*/' . $this->_controller . '/save');

    }

 

将得到的action赋值于form,然后再执行getChildHtml()方法,加载子block。

 

4指定phtml,子block如果有孙block的话,继续通过setChild方法加载。

 

5以上为空间包含加载的方式。

在加载前,也就是block里面的php文件,执行__construction(),_prepareLayout()方法,提供1.css标示信息(如id,destElementId等),2路径信息,3加载的子block,4按钮信息等。为子block的执行提供使用的信息。

 

6当然,在执行前,model,helper,controllers,etc,sql,都要配置好!!

 

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息