当我在视图中选择链接时

当我在视图中选择链接时

本文介绍了当我在视图中选择链接时,codeigniter分页链接不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击视图中的链接时,它显示找不到页面。有人可以帮助我吗?还告诉我为什么这些链接不起作用?数据显示正常。但是转到表的其他页面的链接不起作用。当我单击 1,2,3页面时找不到。它仍然在同一个地方..我想这将是发布还是出现问题?。

when i click on the link in view it shows no page found.can any one help me ?. also tell me why those links are not working?. The display of data is okay. But the link for go to other page of the table it is not working. When i click the "1,2,3" page not found. It is still in the same place.. i m guessing it will be post or get problem?.

这是我的控制器。

<?PHP
/**
*
*/
class Search extends MY_Controller
{

    public  function index ()

    {
        if  ($this->form_validation->run('search') == FALSE)

       {


            $this->load->model('City');
           $deals=$this->City->default_city();
           foreach ($deals as $key)
           {

                   $city_id=$key->city_id;
                   $city_name=$key->city_name;
                   $city_status=$key->city_status;

           }



        }

        else

       {


            $city_name=$this->input->post('city_name');
            $this->load->model('City');
            $city_id=$this->City->other_city($city_name);


            foreach ($city_id as $row)

            {
                    $city_id= $row->city_id;
                    $city_name=$row->city_name;
                    $city_status=$row->city_status;


            }
        }

            $deal_name=$this->input->post('deal_name');
            $data['city_id']=$city_id;
            $data['city_name']=$city_name;
            $data['city_status']=$city_status;
            $this->load->model('Deals');
            $total_deals=$this->Deals->total_deals();
            $config=[
            'base_url' => base_url().'Search',
            'per_page' => 3,
            'total_rows' => $this->Deals->number_rows($deal_name,$city_id,$city_status),
            'uri_segment'=> 2,
            ];
            $this->pagination->initialize($config);

            $user_search=$this->Deals->user_search($deal_name,$city_id,$city_status,$config['per_page'],$this->uri->segment(2));
            $data['links']=$this->pagination->create_links();
            $data['deals']=$user_search;

            $data['total_deals']=$total_deals;
            $total_categories=$this->Deals->total_categories();
            $data['total_categories']=$total_categories;
            for($i=1;$i<=$total_categories;$i++)

            {
                $deals_by_categories[]=$this->Deals->deals_by_categories($i);
            }
            $category_name=$this->Deals->categories();
            //$category_name = json_decode(json_encode($category_name), true);
            $data['category_name']=$category_name;
            $data['deals_by_categories']=$deals_by_categories;
            $this->load->view('page-search',$data);








    }
}
?>

这是我的模型函数

public function user_search($deal_name,$city_id,$city_status,$limit,$offset)

    {

           $query= $this->db->select('merchants.merchant_logo,deals.deal_title,deals.deal_description,deals.start_date,deals.end_date,deal_id')
           ->from('deals')
           ->join('merchants_branches', 'deals.branch_id=merchants_branches.branch_id', 'inner')
           ->join('merchants', 'merchants_branches.merchant_id=merchants.merchant_id', 'inner')
           ->join('cities','cities.city_id=merchants_branches.city_id','inner')
           ->where('merchants_branches.city_id',$city_id)
           ->where('cities.city_status',$city_status)
           ->where('deal_status', 1)
           ->like('deals.deal_name',$deal_name)
           ->limit($limit,$offset)
           ->get();
           return $query->result();

    }

     public function number_rows($deal_name,$city_id,$city_status)

    {

           $query= $this->db->select('merchants.merchant_logo,deals.deal_title,deals.deal_description,deals.start_date,deals.end_date,deal_id')
           ->from('deals')
           ->join('merchants_branches', 'deals.branch_id=merchants_branches.branch_id', 'inner')
           ->join('merchants', 'merchants_branches.merchant_id=merchants.merchant_id', 'inner')
           ->join('cities','cities.city_id=merchants_branches.city_id','inner')
           ->where('merchants_branches.city_id',$city_id)
           ->where('cities.city_status',$city_status)
           ->where('deal_status', 1)
           ->like('deals.deal_name',$deal_name)
           ->get();
           return $query->num_rows();

    }

这是我的观点

<?php
                    if(count($deals)):
                    foreach ($deals as $deals) :
                    date_default_timezone_set("Asia/Dubai");
                    $date=date('Y-m-d H:i:s');
                    $enddate=$deals->end_date;

                    $date = new DateTime($date);

                    $enddate = new DateTime($enddate);

// The diff-methods returns a new DateInterval-object...
                    $diff = $date->diff($enddate);
                    if($date<$enddate):
// Call the format method on the DateInterval-object


                 ?>

                        <a class="col-md-4 model-1" href="<?php echo base_url(); ?>DealDescription/<?php echo $deals->deal_id  ?>/<?php echo $city_status?>">
                            <div class="product-thumb model-2">
                                <header class="product-header">
                                    <img src="<?php echo base_url(); ?>img/logos/<?php echo $deals->merchant_logo ?>" alt="Image Alternative text" title="Food is Pride" />
                                </header>
                                <div class="product-inner">
                                    <h5 class="product-title"><?php echo $deals->deal_title ?></h5>
                                    <p class="product-desciption"><?php echo $deals->deal_description ?></p>
                                    <div class="product-meta"><span class="product-time"><i class="fa fa-clock-o"></i> <?php echo $diff->format('%a Day and %h hours');?></span>
                                        <ul class="product-price-list">
                                            <li><span class="product-price">$118</span>
                                            </li>
                                            <li><span class="product-old-price">$227</span>
                                            </li>
                                            <li><span class="product-save">Save 52%</span>
                                            </li>
                                        </ul>
                                    </div>
                                    <p class="product-location"><i class="fa fa-map-marker"></i> <?php echo $city_name;?></p>
                                </div>
                            </div>
                        </a>


                    <?php else: header('location:'.base_url().'SearchError'); endif; endforeach;?>
                         <?php else: header('location:'.base_url().'SearchError');

                    endif;
                    ?>
                    <?php echo $links; ?>


推荐答案

由于CodeIgniter的工作方式以及您的控制器的index方法中确实没有URI段,则需要将搜索移至其他方法。如果您执行以下操作,这将非常简单:

Due to the way CodeIgniter works, and the fact that you really can't have URI segments in your controller's index method, you need to move the search to a different method. This is pretty easy if you do something like:

public function index()
{
    $this->results();
}

public function results( $page = 1 )
{
     // your code
}

请注意,实际上您现在在URI段3中有一个页面变量。这很重要,因为CodeIgniter将根据配置查找该页面。 :

Notice now that you now actually have a page variable in URI segment 3. This is important, because CodeIgniter will be looking for that page based on the config:

$config['uri_segment'] = 3; // You can't use 2!

此外,在CodeIgniter中,使用site_url而不是base_url进行分页base_url很重要:

Also, in CodeIgniter it's important to use site_url, and not base_url for this pagination base_url:

$config['base_url'] = site_url('search/results'); // Do not uppercase "search"

此外,如果您想要页面的自然用户体验,应该使用页码:

Furthermore, if you want a natural user experience for pages, you should be using page numbers:

$config['use_page_numbers'] = TRUE;

采用这种方法,您仍然需要确定查询的偏移量,因为显然不是页面偏移量数字:

Taking this approach, you still need to determine what your query offset is, because it's obviously not the page numbers:

$offset = ( $page * $config['per_page'] ) - $config['per_page'];

另外,请务必阅读有关分页的用户指南页面,因为它非常有用:

Also, make sure to read the user guide's page on pagination, as it's very helpful: https://www.codeigniter.com/userguide3/libraries/pagination.html

这应该让您立即分页。

这篇关于当我在视图中选择链接时,codeigniter分页链接不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 20:16