此GET存在问题。 我想传递三个值(ygo,dane,1)以及指向索引的链接,以便将这些值输入到相应的WHERE中。 但是很遗憾,页面上没有任何价值,我只是不知道为什么。
IMG: https://screenshots.firefox.com/g6qcToRn.../127.0.0.1
控制器:
public function index($slug) {
$url = 'edition/index';
$array = explode ('/',$url);
$data['array'] = $array[0];
$data['title'] = 'Edition Liste';
$data['edition_listes'] = $this->Edition_model->edition_listess($slug);
$this->load->view('templates/header', $data);
$this->load->view($url, $data);
$this->load->view('templates/footer');
}
public function edition($tcg,$id,$short) {
$url = 'edition/edition';
$array = explode ('/',$url);
$data['array'] = $array[0];
$data['get_edition'] = $this->Edition_model->get_edition($tcg,$id,$short);
$this->load->view('templates/header', $data);
$this->load->view($url, $data);
$this->load->view('templates/footer');
}
型号:
public function edition_listess($slug) {
$this->db->select('*');
$this->db->from('db_edition');
$this->db->where('db_edition.tb_edition_tcg', $slug);
$this->db->order_by('db_edition.tb_edition_kurzel', 'ASC');
$this->db->order_by('db_edition.tb_edition_date', 'ASC');
$query = $this->db->get();
return $query->result_array();
}
public function get_edition($tcg,$id,$short) {
$this->db->select('*');
$this->db->from('db_edition');
$this->db->where('db_edition.tb_edition_tcg', $tcg);
$this->db->where('db_edition.tb_edition_id', $id);
$this->db->or_where('db_edition.tb_edition_kurzel', $short);
$this->db->order_by('db_edition.tb_edition_kurzel', 'ASC');
$this->db->order_by('db_edition.tb_edition_date', 'ASC');
$query = $this->db->get();
return $query->result_array();
}
index.php
<?php echo validation_errors(); ?>
<title><?php echo $title; ?></title>
<div class="row">
<div class="col-xs-6 col-lg-1">
</div>
<div class="col-xs-6 col-lg-10">
<?php foreach ($edition_listes as $edition_liste): ?>
<div class="list-group">
<a href="<?php echo base_url(); ?>edition/edition/<?php echo $edition_liste['tb_edition_tcg'];?>/<?php if($edition_liste['tb_edition_kurzel'] > '') { echo $edition_liste['tb_edition_kurzel']; } else { echo $edition_liste['tb_edition_id']; } ?>" class="list-group-item list-group-item-action list-group-item-secondary">
<div class="media">
<img class="media-object img-rounded img-responsive" src="<?php echo base_url(); ?>/assets/images/display.png" alt="placehold.it/350x250">
<div class="media-body">
<h4 class="list-group-item-heading"><?php echo $edition_liste['tb_edition_name'];?></h4>
<p class="list-group-item-text">
<b>SET ID: </b><?php if($edition_liste['tb_edition_kurzel']): echo $edition_liste['tb_edition_kurzel']; endif; ?></br>
<b>Kartenmenge: </b><?php echo $edition_liste['tb_edition_size'];?></br>
<b>Release: </b>00.00.0000
</p>
</div>
<div class="col-md-3 text-right">
<h5 class="colors">Pre-Release: <button class="btn btn-primary"><i class="fa fa-check-square"></i></button></h5>
<h5 class="colors">Pre-Release: <button class="btn btn-primary"><i class="fa fa-square"></i></button></h5>
</div>
</div>
</a>
</div>
<?php endforeach; ?>
</div>
<div class="col-xs-6 col-lg-1">
</div>
</div>
edition.php (测试页)
<?php echo validation_errors(); ?>
<?php echo $slug; ?>
答案 0 :(得分:0)
您似乎没有将第三个参数传递给edition($tcg,$id,$short)
。这可能意味着您的模型在对null
的调用中使用$short
作为$this->db->or_where('db_edition.tb_edition_kurzel', $short);
的值,因此它可能不返回任何记录。
您的代码可能更容易阅读。这是有关如何创建指向版本控制器的链接的代码段建议
...
<div class="list-group">
<?php
$tcg = $edition_liste['tb_edition_tcg'];
if($edition_liste['tb_edition_kurzel'] !== '') // use a more reliable test for an empty string than > ''
{
$id = $edition_liste['tb_edition_kurzel'];
}
else
{
$id = $edition_liste['tb_edition_id'];
}
$short = 1;
?>
<a href="<?= base_url("edition/edition/$tcg/$id/$short"); ?>" class="list-group-item list-group-item-action list-group-item-secondary">
...
如果您不熟悉语法<?=
与<?php echo
完全相同,但键入量少得多。
现在,一个额外的建议。我不确定您为什么要使用此代码
$url = 'edition/index';
有一种方法可以获取当前的控制器和方法而无需对其进行硬编码。
$url = $this->router->class . '/' . $this->router->method;
这样,如果您重命名控制器或方法,则不必更改硬编码的字符串。是的!
CodeIgniter没有记录路由器类,但是源代码在/system/core/Router.php
中,并且每个控制器都有一个路由器类的实例,其属性为$this->router
。