使用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,都要配置好!!
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,都要配置好!!
相关文章推荐
- 使用widget控件的一般规律!!!
- 控件状态11种,必须倒背如流——记录控件当前的状态,防止误判(一般使用完以后就把状态改回去)
- Android自定义SurfaceView类和一般控件的xml布局使用
- 关于QTableWidget使用setCellWidget嵌入控件错位的问题
- QTableWidget控件使用总结
- qt tableWidget 表格控件使用
- 桌面小控件appwidget的简单使用
- AppWidgetProvider桌面控件的使用简介
- AspNetPager分页控件的一般使用方法
- 在xml布局文件中,我们既可以设置px,也可以设置dp(或者dip)。一般情况下,我们都会选择使用dp,这样可以保证不同屏幕分辨率的机器上布局一致。但是在代码中,如何处理呢?很多控件的方法中都只提供了
- Android RecyclerView 使用完全解析 体验不一般的控件
- QVTKWidget 和其它控件配合使用记录
- Android控件之切换卡TabWidget的简单使用
- iOS控件一般使用套路
- 安卓学习笔记之使用widget桌面小控件
- 【ASP.NET】GRIDVIEW控件的一般使用技巧
- QTableWidget的控件的使用
- 【视频】自然框架之分页控件的使用方法(一) PostBack方式的一般分页方式
- IOS开发学习笔记018- 一般控件的使用
- 【视频】自然框架之分页控件的使用方法(一) PostBack方式的一般分页方式