2013-12-19 35 views
1

任何人都可以帮助我如何在mvc结构中调用分页函数吗?MVC结构中的分页

我联系一下喜欢在此之后,.htaccess已经完成了它的魔力:

controller/action/id 

前:

index.php?controller=&action=&id= 

什么,我真的很想做的是设置URL像

/controller/px 

其中x是任何int值

.htaccess

Options +FollowSymLinks 
RewriteEngine on 

RewriteRule ^([a-zA-Z]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controller=$1&action=$2&id=$3 [NC,L,QSA] 

我希望一些帮助或任何形式的一些指针将是很好。

+0

你怎么想重写内部'/控制器/ px'? – anubhava

+0

MVC与你建立你的URI的方式没有任何关系 – PeeHaa

+0

它就像我有一大堆新闻的首页......我想能够添加像/ home这样的分页< - 这是我的首页...但是,如果我去/ home /视图,例如它在我的控制器内我的视图行动。我的问题实际上并不是说要让分页工作不用说/ home/view/1/p2? – Cruelcrome

回答

1

您可以将现有的规则之前添加此规则

RewriteRule ^([a-zA-Z]+)/([0-9]+)/?$ index.php?controller=$1&action=&id=&p=$2 [L,QSA] 
+0

非常感谢它工作:) – Cruelcrome

+0

不客气,很高兴它解决了。 – anubhava

0
for htaceess file: 

    <IfModule mod_rewrite.c> 
     RewriteEngine On 
     RewriteBase /your_folder_name/ 
     RewriteCond %{REQUEST_FILENAME} !-f 
     RewriteCond %{REQUEST_FILENAME} !-d 
     RewriteRule ^(.*)$ index.php?/$1 [L] 
    </IfModule> 

    <IfModule !mod_rewrite.c> 
     # If we don't have mod_rewrite installed, all 404's 
     # can be sent to index.php, and everything works as normal. 
     # Submitted by: ElliotHaughin 

     ErrorDocument 404 /index.php 
    </IfModule> 

Replace your_folder_name on the third line with your folder name. 

if its code ignitor, you need to make some changes in application/config/config.php 
change the following lines as below 

$config['index_page'] = ''; 
$config['uri_protocol'] = 'REQUEST_URI'; 

also in autoload in application/config/autoload.php, change to the following line 

$autoload['helper'] = array('url'); 

In Controller 

$this->load->library('Pagination'); 
$config['base_url']=base_url().'controller/function'; 
$config['total_rows']=$data_count; 
$config['per_page']=1; 
$config['num_links']=2; 
$this->pagination->initialize($config); 

While fetching data from database use uri segment and $config['per_page'] as limits 

In View 

to get the pagination links 

echo $this->pagination->create_links();