我在CodeIgniter中创建了一个网站,我试图制作一个包含所有类别的菜单栏,当您点击某个类别时,它必须显示该类别中的所有产品但它没有真正起作用。
当我打开category.php视图而不是侧面菜单栏时,真的有很大的白色空白链接,什么都没有。此外,当我点击其中一个链接时,我收到一个错误。这是错误:
An Error Was Encountered
The URI you submitted has disallowed characters.
当我加载category.php视图时,这也是错误消息:
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: views/allecadeaus.php
Line Number: 26
Backtrace:
File: /home/ubuntu/workspace/application/views/allecadeaus.php
Line: 26
Function: _error_handler
File: /home/ubuntu/workspace/application/controllers/AlleCadeausController.php
Line: 12
Function: view
File: /home/ubuntu/workspace/index.php
Line: 315
Function: require_once
allecadeaus.php文件:
<?php include_once ('templates/header.php'); ?>
<!-- Alle cadeaus gele title bovenaan pagina -->
<div class="container-fluid">
<div class="row">
<div class="col-lg-12 bg-warning" style="font-size:25px">
<center>Alle cadeaus</center>
</div>
</div>
</div>
<hr />
<br>
<!-- Cadeau categorie side menu -->
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
<div id="categorymenu">
<center> <h3>Categorieën</h3> </center>
<ul class="list-group">
<?php foreach ($category() as $row) : ?>
<li class="list-group-item">
<a href="<?php echo base_url('Product/category/'.$row->id);?>"> <?php echo $row->name; ?></a>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<!-- Laat cadeau zien op alle cadeaus pagina -->
<div class="col-md-8">
<?php foreach($products as $product) : ?>
<div class="col-md-2">
<div id="product">
<a href="<?php echo base_url() ?>/Product/details/<?php echo $product['product_id']; ?>">
<img src="<?php echo base_url(); ?>upload/<?php echo $product['product_foto_thumb']; ?>">
</a>
<div class="product_naam"><?php echo $product['product_naam']; ?></div>
<div class="ophaal_plaats">
<?php echo $product['ophaal_plaats']; ?>
</div>
<div class="aangeboden_door">
<p>Aangeboden door: Peter</p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<div class="clearfix"></div>
<?php include_once ('templates/footer.php'); ?>
这是我的category.php视图页面:
<?php include_once ('templates/header.php'); ?>
<!-- Alle cadeaus gele title bovenaan pagina -->
<div class="container-fluid">
<div class="row">
<div class="col-lg-12 bg-warning" style="font-size:25px">
<center>Alle cadeaus</center>
</div>
</div>
</div>
<hr />
<br>
<!-- Cadeau categorie side menu -->
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
<div id="categorymenu">
<center> <h3>Categorieën</h3> </center>
<ul class="list-group">
<?php foreach (get_categories_h() as $category) : ?>
<li class="list-group-item">
<a href="<?php echo base_url('Product/category/'.$category->id);?>"> <?php echo $category['name']; ?></a>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<!-- Laat cadeau zien op alle cadeaus pagina -->
<div class="col-md-8">
<?php foreach($products as $product) : ?>
<div class="col-md-2">
<div id="product">
<a href="<?php echo base_url() ?>/Product/details/<?php echo $product['product_id']; ?>">
<img src="<?php echo base_url(); ?>upload/<?php echo $product['product_foto_thumb']; ?>">
</a>
<div class="product_naam"><?php echo $product['product_naam']; ?></div>
<div class="ophaal_plaats">
<?php echo $product['ophaal_plaats']; ?>
</div>
<div class="aangeboden_door">
<p>Aangeboden door: Peter</p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<div class="clearfix"></div>
<?php include_once ('templates/footer.php'); ?>
这是我在Product.php控制器文件中的功能:
public function category($id)
{
$data['title'] = 'Category';
$data['page'] = 'Product/category';
$data['category'] = $this->Category_model->findByCategory($id);
$data['products'] = $this->Product_model->findByCategory($id);
$this->load->view('category', $data);
}
这些是我的产品型号中的功能(Product_model.php):
public function get_categories(){
$this->db->select('*');
$this->db->from('categories');
$query = $this->db->get();
$result = $query->result_array();
return $result;
}
public function findAll(){
return $this->db->get('product')->result();
}
public function findByCategory($category_id){
$this->db->where('category_id', $category_id);
return $this->db->get('product')->result();
}
这是我的Category_model.php文件:
<?php
class Category_model extends CI_Model {
public function findAll(){
return $this->db->get('category')->result();
}
public function find($id){
$this->db->where('id', $id);
return $this->db->get('category')->row();
}
}
?>
一些数据库信息:
Table 1: products
-product_id
-product_naam
-product_beschrijving
-user_id
-category_id
table 2: categories: 2 columns:
1.id
2.name
这是我的类别表的外观:
id name
1 Cosmetica
2 Antiek en kunst
3 Voor kinderen
4 Apparatuur
5 Boeken
6 Muziek en instrumenten
7 Spellen
8 Sieraden
9 Overige cadeaus
10 Sport
答案 0 :(得分:0)
您的类别名称/ ID包含 config.php 文件中当前permitted_uri_chars
配置不允许的字符。
转到config.php文件(application\config\config.php
)并为$config['permitted_uri_chars']
选项提供值:a-z 0-9~%.:_\-\=
这将允许几乎所有常见字符。
答案 1 :(得分:0)
您需要在视图文件中更换此代码
<?php foreach ($category as $row) : ?>
<li class="list-group-item">
<a href="<?php echo base_url('Product/category/'.$row->id);?>"> <?php echo $row->name; ?></a>
</li>
<?php endforeach; ?>