开发者

How to convert smarty functions to zend functions

I have written custom smarty functions to work with Zend framework and now I 开发者_运维技巧would like them to be rewritten to zend structure, plz suggest how can I do that ? thanx. Here is the sample code for the same...

function smarty_function_render_table($params, &$smarty)
{
    extract($params);

    $sSortTableBy  = $smarty->get_template_vars("sortTableBy");
    $bSortTableOrderAsc = (boolean) (strlen($smarty->get_template_vars("sortTableOrder")) > 0 ? strtolower($smarty->get_template_vars("sortTableOrder")) == 'asc' : true);
    $iSortTablePage  = $smarty->get_template_vars("page");

    Adx_Sort::getInstance()->multiSort($data, $sSortTableBy, $bSortTableOrderAsc);

    $columnSettings = $smarty->get_config_vars($id);


Analog of the Smarty plugins are Zend View Helpers. You can write Zend View Helpers to make similar job as Smarty plugins did. Zend View Helpers is a class derived from the Zend_View_Helper_Abstract abstract class. View object is already accessible there via view public class member. get_template_vars is not needed - you can just get view custom vars directly from View object.

<?php
class Zend_View_Helper_Table extends Zend_View_Helper_Abstract {

    public function table($params) {
        extract($params);
        $sSortTableBy = $this->view->sortTableBy;
        $bSortTableOrderAsc = (boolean) (strlen($this->view->sortTableOrder) > 0 ? strtolower($this->view->sortTableOrder) == 'asc' : true);
        $iSortTablePage = $this->view->page;
        return Adx_Sort::getInstance()->multiSort($data, $sSortTableBy, $bSortTableOrderAsc);
    }

}

After you had created view helper, you can use it directly in every view script via direct calls:

<?=$this->table($params)?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜