Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.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 如何使用Kohana 2.3.x实现分页搜索_Php_Search_Navigation_Kohana - Fatal编程技术网

Php 如何使用Kohana 2.3.x实现分页搜索

Php 如何使用Kohana 2.3.x实现分页搜索,php,search,navigation,kohana,Php,Search,Navigation,Kohana,我在谷歌上搜索了所有地方,但找不到关于这个问题的明确答案 我正在尝试进行网页搜索并对结果分页(并按标题排序) 请看原型 我希望,如果用户指定搜索条件为“a”,则会显示包含“a”的所有名称。我的问题是如何在导航链接上添加字符串:?name=a 如果我没有发回搜索条件,单击下一页将显示所有记录 我读了很多关于这个主题的帖子,但我还不知道怎么做 控制器代码(草稿) 谢谢我设法让它工作了。查看Kohana分页库,它仅使用函数http_build_query扩展GET参数。然后我更改了表单方法以获取 工作

我在谷歌上搜索了所有地方,但找不到关于这个问题的明确答案

我正在尝试进行网页搜索并对结果分页(并按标题排序)

请看原型

我希望,如果用户指定搜索条件为“a”,则会显示包含“a”的所有名称。我的问题是如何在导航链接上添加字符串:?name=a

如果我没有发回搜索条件,单击下一页将显示所有记录

我读了很多关于这个主题的帖子,但我还不知道怎么做

控制器代码(草稿)


谢谢

我设法让它工作了。查看Kohana分页库,它仅使用函数http_build_query扩展GET参数。然后我更改了表单方法以获取

工作代码:

控制器:

function listall(  )
{
    $limit = 25 ;
    $orderby = 'u.id';
    $direction = 'asc';
    $name = '';
    $query_string= '';


    if ( $_GET )
    {
        $name = $this->input->get('name');
        $online = $this->input->get('online'); 

        if ( $this->input->get('orderby') )
            list($orderby, $direction) = explode(':', $this->input->get('orderby'));
    }

    kohana::log('debug', kohana::debug( $_GET ) );

    $view = new view( 'character/listall');
    $db = Database::instance();

    $sql = "select c.id id, c.lastactiontime, c.name character_name, k.name kingdom_name, 
        k.image kingdom_image, from_unixtime( u.last_login, '%d-%m-%y') last_login, u.nationality 
    from characters c, kingdoms k, users u
    where 1=1 and
    c.kingdom_id = k.id and
    c.user_id = u.id 
    " ;

    $criteria = kohana::lang('global.criteria' );

    if ( $name != '' ) 
    {
        $sql .= " and c.name like '%" . $name . "%' " ;
        $criteria .= kohana::lang('global.name') . ' ' . kohana::lang('global.contains') . ' ' . $name . ' ' ;
    }
    if ( $online )  
    {
        $sql .= " and c.lastactiontime > (unix_timestamp() - 15 * 60 ) " ;
        $criteria .= kohana::lang('global.online') . ' = true' ;
    }

    if ( !$online and $name == '' )
        $criteria .= kohana::lang('global.allrecords' ) ;

    $characters = $db->query( $sql );

    //$characters = ORM::factory( "character" )->orderby( $orderby, $direction )->find_all();

    $this->pagination = new Pagination(array(
        'base_url'=>'character/listall',
        'uri_segment'=>'listall',
        'style'=>'digg',
        'query_string' => 'page',
        'total_items'=>$characters->count(),
        'items_per_page'=>$limit));             

    //$characters = ORM::factory( "character" )->orderby( $orderby, $direction )->find_all($limit, $this->pagination->sql_offset);          

    $sql .= " order by $orderby $direction ";
    $sql .= " limit $limit offset " . $this->pagination->sql_offset ;

    kohana::log('debug', $sql );

    $characters = $db->query( $sql );

    $playersinfo = Character_Model::getplayersinfo();

    $view->playersinfo = $playersinfo;      
    $view->pagination = $this->pagination;
    $view->characters = $characters;
    $view->criteria = $criteria ;
    $this->template->content = $view;   

}
查看

[cut]

<?php
echo form::open('/character/listall', array('method' => 'get' ) );
echo form::label( kohana::lang('global.name')) . '&nbsp;' . form::input( array( 'id' => 'name', 'name' => 'name', 'style' => 'width:200px') );
echo '&nbsp;&nbsp;';
echo form::label( kohana::lang('global.online')) . '&nbsp;' . form::checkbox('online', true );
echo "<div style='float:right'>";
echo form::submit( array( 'id' => 'submit', 'class' => 'submit', 'value' => kohana::lang('global.search') ) );
echo form::submit( array( 'id' => 'reset', 'class' => 'submit', 'value' => kohana::lang    ('global.reset') ) );
echo "</div>";
echo form::close();
echo '<br/>';
echo '<b>' . $criteria .'</b>';
[cut]

你的代码应该可以工作。AFAIR,分页将自动添加当前查询字符串。
[cut]

<?php
echo form::open('/character/listall', array('method' => 'get' ) );
echo form::label( kohana::lang('global.name')) . '&nbsp;' . form::input( array( 'id' => 'name', 'name' => 'name', 'style' => 'width:200px') );
echo '&nbsp;&nbsp;';
echo form::label( kohana::lang('global.online')) . '&nbsp;' . form::checkbox('online', true );
echo "<div style='float:right'>";
echo form::submit( array( 'id' => 'submit', 'class' => 'submit', 'value' => kohana::lang('global.search') ) );
echo form::submit( array( 'id' => 'reset', 'class' => 'submit', 'value' => kohana::lang    ('global.reset') ) );
echo "</div>";
echo form::close();
echo '<br/>';
echo '<b>' . $criteria .'</b>';