Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 扩展网格UI元素以链接到页面_Php_Frameworks_Atk4_Agiletoolkit - Fatal编程技术网

Php 扩展网格UI元素以链接到页面

Php 扩展网格UI元素以链接到页面,php,frameworks,atk4,agiletoolkit,Php,Frameworks,Atk4,Agiletoolkit,我正在使用Agile Toolkit进行一些开发,并希望扩展现有的网格控件,使每一行都包含数据(就像现在一样),但也链接到一个带有包含ID的查询字符串的页面。我希望能够执行以下操作: $this->add('Grid', 'short-name', 'template-tag', array('page?id=', 'id'))->setModel('mydatasource'); 我目前可以使用以下功能: $this->add('Grid', 'short-name', '

我正在使用Agile Toolkit进行一些开发,并希望扩展现有的网格控件,使每一行都包含数据(就像现在一样),但也链接到一个带有包含ID的查询字符串的页面。我希望能够执行以下操作:

$this->add('Grid', 'short-name', 'template-tag', array('page?id=', 'id'))->setModel('mydatasource');
我目前可以使用以下功能:

$this->add('Grid', 'short-name', 'template-tag')->setModel('mydatasource');
$this->add('MyGrid',array('dest_page'=>'page'), 'template-tag');


class MyGrid extends Grid {
    function format_text($field){
        parent::format_text($field);

        // Wrap the value inside a link
        $this->current_row_html[$field]='<a href="'.
            $this->api->url($this->dest_page, array('id'=>$this->current_id).'">'.
            ($this->current_row_html[$field]?:
             htmlspecialchars($this->current_row[$field],ENT_NOQUOTES,'UTF-8')).
            '</a>'
    }
}
但我希望能够将我链接到的页面指定为包含我要传递的字段的格式,以便单击第二行的任意位置:

1     Jack Johnson     Clerk
2     John Doe         Executive
带我到:myapp.com/page?id=2

我将如何扩展网格元素来实现这一点?或者我需要从AbstractView或Lister一直向下扩展吗

谢谢

完整的工作解决方案:

precacheTemplate删除了我在html模板中定义的变量的第t行引用。因此,我遵循了现有的做法,添加了另一个重置变量to(即,它设置to的位置),这样它就会留在内存中,作为返回泛型formatRow中的模板字段的引用,泛型formatRow正在从基本网格重载

罗曼之前提到过一些,但我最终得到了丢失的链接,我不得不重新设置

最好的理解方法是逐行比较我的网格和基本网格(是的,我知道我从高级扩展而来)

希望这能帮助其他有同样问题的人

在页面上

$this->add('ExtendedUI_GridLinkedRow', array('dest_page'=>'home', 'name'=>'assessments'), 'assessments')
    ->setModel('GrantAssessment')
    ->addCondition('uid', 1);
GridLinkedRow.php

    <?php

class ExtendedUI_GridLinkedRow extends Grid_Advanced {

    function init(){
        parent::init();
    }

    function defaultTemplate(){
        return array('ExtendedUI/grid_linked_row');
    }

    function precacheTemplate(){
        // pre-cache our template for row
        // $full=false used for certain row init
        $row = $this->row_t;
        $col = $row->cloneRegion('col');

        // tbody -> column
        $row->setHTML('row_id','<?$id?>');
        $row->trySetHTML('odd_even','<?$odd_even?>');
        $col->setHTML('dest_link','<?$page_link?>');
        $row->del('cols');

        // thead -> column
        $header = $this->template->cloneRegion('header');
        $header_col = $header->cloneRegion('col');
        $header_sort = $header_col->cloneRegion('sort');

        // Totals -> column
        if($t_row = $this->totals_t){
            $t_col = $t_row->cloneRegion('col');
            $t_row->del('cols');
        }

        $header->del('cols');

        foreach($this->columns as $name=>$column){
            $col->del('content');
            $col->setHTML('content','<?$'.$name.'?>');

            if(isset($t_row)){
                $t_col->del('content');
                $t_col->setHTML('content','<?$'.$name.'?>');
                $t_col->trySetHTML('tdparam','<?tdparam_'.$name.'?>style="white-space: nowrap"<?/?>');
                $t_row->appendHTML('cols',$t_col->render());
            }

            // some types needs control over the td

            $col->setHTML('tdparam','<?tdparam_'.$name.'?>style="white-space: nowrap"<?/?>');

            $row->appendHTML('cols',$col->render());

            $header_col->set('descr',$column['descr']);
            $header_col->trySet('type',$column['type']);

            // TODO: rewrite this (and move into Advanced)
            if(isset($column['sortable'])){
                $s=$column['sortable'];
                // calculate sortlink
                $l = $this->api->getDestinationURL(null,array($this->name.'_sort'=>$s[1]));

                $header_sort->trySet('order',$column['sortable'][0]);
                $header_sort->trySet('sorticon',$this->sort_icons[$column['sortable'][0]]);
                $header_sort->set('sortlink',$l);
                $header_col->setHTML('sort',$header_sort->render());
            }else{
                $header_col->del('sort');
                $header_col->tryDel('sort_del');
            }

            if($column['thparam']){
                $header_col->trySetHTML('thparam',$column['thparam']);
            }else{
                $header_col->tryDel('thparam');
            }

            $header->appendHTML('cols',$header_col->render());

        }
        $this->row_t = $this->api->add('SMlite');
        $this->row_t->loadTemplateFromString($row->render());

        if(isset($t_row)){
            $this->totals_t = $this->api->add('SMlite');
            $this->totals_t->loadTemplateFromString($t_row->render());
        }

        $this->template->setHTML('header',$header->render());
    }

    function formatRow(){

        if(!$this->columns)throw $this->exception('No columns defined for grid');

        foreach($this->columns as $tmp=>$column){
            $this->current_row[$tmp.'_original']=@$this->current_row[$tmp];

            $formatters = explode(',',$column['type']);
            foreach($formatters as $formatter){
                if(!$formatter)continue;
                if(method_exists($this,$m="format_".$formatter)){
                    $this->$m($tmp,$column);
                }else throw new BaseException("Grid does not know how to format type: ".$formatter);
            }
            // setting cell parameters (tdparam)
            $this->applyTDParams($tmp);
            if($this->current_row[$tmp]=='')$this->current_row[$tmp]=' ';
        }
        $this->row_t->setHTML('page_link', $this->api->url($this->dest_page, array('id'=>$this->current_id)));
        return $this->current_row;
    }

}

如果要将网格的所有文本值包装在链接中,可以使用以下选项:

$this->add('Grid', 'short-name', 'template-tag')->setModel('mydatasource');
$this->add('MyGrid',array('dest_page'=>'page'), 'template-tag');


class MyGrid extends Grid {
    function format_text($field){
        parent::format_text($field);

        // Wrap the value inside a link
        $this->current_row_html[$field]='<a href="'.
            $this->api->url($this->dest_page, array('id'=>$this->current_id).'">'.
            ($this->current_row_html[$field]?:
             htmlspecialchars($this->current_row[$field],ENT_NOQUOTES,'UTF-8')).
            '</a>'
    }
}
$this->add('MyGrid',array('dest_page'=>'page'),'template tag');
类MyGrid扩展了Grid{
函数格式\u文本($field){
父::格式化文本($field);
//将值包装在链接中
$this->current_row_html[$field]=''
}
}

Hi@romaninsh如果您在formatRow或format@romaninsh$this->setHTML('dest_link',$this->api->url($this->dest_页面,数组('id'=>$this->current_id)),则precachetemplate和initry中的id字段都是空的;在formatRow内部,但没有骰子-它有url(和id字段),但我不知道我需要使用的模板对象是什么。i、 e.$this->template->setHTML。。。。。或者$this->setHTML…我已经更新了我的答案。它可能包含一些语法错误,如有必要请修改。想法应该很清楚。谢谢@romaninsh-我没有使用你发布的确切解决方案,但我最终从你的提示中收集了一个工作解决方案,感觉很干净,也就是说,我想保持你框架的目标-我没有直接修改任何html。我还发布了我的完整工作解决方案-如果您认为可以,请让我知道:)