我正在使用codeigniter构建一个简单的cms,我希望分页显示从所选类别中每页的几个帖子。 我收到了这些错误:
Severity: Warning
Message: Missing argument 1 for Vijesti::kategorija()
Filename: controllers/vijesti.php
Line Number: 12
Severity: Notice
Message: Undefined variable: cat_name
Filename: controllers/vijesti.php
Line Number: 13
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at C:\wamp\www\ci_cms_yt\system\core\Exceptions.php:185)
Filename: libraries/Session.php
Line Number: 688
model" vijest":
<?php
class Vijest extends CI_Model{
function get_news_by_name($cat_name,$num=20,$start=0){
$sql="SELECT * FROM posts WHERE post_cat_name=? ORDER BY post_date DESC LIMIT $start,$num";
$array=array($cat_name);
$this->session->set_userdata('term',$cat_name);
$query=$this->db->query($sql,$array);
return $query->result_array();
}
function get_post($slug){
$query=$this->db->query("SELECT * FROM posts WHERE slug='$slug'");
return $query->result_array();
}
function get_posts_count(){
$query=$this->db->query("SELECT post_id FROM posts");
return $query->num_rows();
}
}
?>
controller&#34; vijesti&#34;:
<?php
class Vijesti extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model('vijest');
$this->load->model('home_model');
$this->load->library('pagination');
}
function kategorija($cat_name){
$data['vijesti']=$this->vijest->get_news_by_name($cat_name,1,0);
$data1['navigation']=$this->home_model->get_cats_nav();
$data3['sidebar_news']=$this->home_model->sidebar_news();
$config['base_url']=base_url().'vijesti/kategorija/';
$config['total_rows']=$this->vijest->get_posts_count();
$config['per_page']=1;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['prev_link'] = '<';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#"><span class="sr-only">(current)</span>';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$this->pagination->initialize($config);
$data['pages']=$this->pagination->create_links();
$this->load->view('header',$data1);
$this->load->view('vijesti_po_kategoriji',$data);
$this->load->view('footer',$data3);
}
function vijest($slug){
$data1['navigation']=$this->home_model->get_cats_nav();
$data2['vijest']=$this->vijest->get_post($slug);
$data3['sidebar_news']=$this->home_model->sidebar_news();
$this->load->view('header',$data1);
$this->load->view('vijest_pojedinacno',$data2);
$this->load->view('footer',$data3);
}
}
?>
查看&#34;标题&#34;:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>News</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="<?php echo base_url('assets/css/bootstrap.min.css');?>" rel="stylesheet">
<script src="<?php echo base_url('assets/js/bootstrap.min.js');?>"></script>
<script src="<?php echo base_url('assets/js/jquery.js');?>"></script>
<link rel="stylesheet" href="<?php echo base_url('assets/css/mojstil.css');?>">
</head>
<body>
<div class="sadrzaj">
<div class="head">
<a href="<?=base_url()?>home/index"><img id="logo" src="<?=base_url()?>assets/img/admalogo.png" alt="logo" /></a>
</div>
<div class="navbarr">
<ul id="menuu">
<li><a href="<?=base_url()?>home/index">Home</a></li>
<?php
foreach($navigation as $nav){
?>
<li><a href="<?=base_url()?>vijesti/kategorija/<?=$nav['cat_title']?>"><?=$nav['cat_title']?></a></li>
<?php
}
?>
</ul>
</div>
查看vijesti_po_kategoriji:
<div class="post_area">
<?php
foreach($vijesti as $row){
?>
<h2><a class="ltitle" href="<?=base_url()?>vijesti/vijest/<?=$row['slug']?>"><?=$row['post_title']?></a></h2>
<span><i>Author:</i> <b><?=$row['post_author']?></b> <b><?=$row['post_date']?></b></span>
<img src="<?=base_url()?>news_images/<?=$row['post_image']?>" width="100" height="100" alt="title_image" />
<div><?=substr($row['post_content'],0,300)?><a class="rmlink" href="<?=base_url()?>vijesti/vijest/<?=$row['slug']?>">Read more</a></div><br>
<?php
}
echo $pages;
?>
</div>
查看&#34;页脚&#34;:
<div class="sidebarr">
<h4>Recent news</h4>
<?php
foreach($sidebar_news as $sn){
?>
<div class="recent_posts" data-link="<?=base_url()?>vijesti/vijest/<?=$sn['slug']?>">
<img src="<?=base_url()?>news_images/<?=$sn['post_image']?>" width="60" height="60" /><p><?=$sn['post_title']?></p>
<div style='clear:both'></div>
</div>
<?php
}
?>
<h4>Subscribe</h4>
<div class="pretplatite_se">
<input type="text" placeholder="Email"><br><br>
<input type="submit" value="Subscribe" id="pretplata">
</div>
<h4>Follow us</h4>
<div class="pratite_nas">
<img src="<?=base_url()?>assets/img/facebook.png" width="100" height="100"/>
<img src="<?=base_url()?>assets/img/twitter.png" width="100" height="100"/>
</div>
</div>
<div class="footer_area">
Copyright © <?php echo date("Y",time());?>
</div>
</div>
</body>
</html>
如果我把
$config['base_url']=base_url().'vijesti/kategorija/'.$cat_name;
它不会让我点击分页。帮助任何人?
答案 0 :(得分:1)
我假设你第一次点击页面时你的网址是这样的
site_url/Vijesti/kategorija/a_category_name
如果这是您的网址,那么您的Kategorija功能将如下所示
function kategorija($cat_name){
$data['vijesti']=$this->vijest->get_news_by_name($cat_name,1,0);
$data1['navigation']=$this->home_model->get_cats_nav();
$data3['sidebar_news']=$this->home_model->sidebar_news();
$config['base_url']=base_url().'vijesti/kategorija/'.$cat_name;
$config['uri_segment'] = 4;//you need to add this.At your case its 4 I think.
//rest of the code
$config['total_rows']=$this->vijest->get_posts_count();
}