0
CodeIgniterを使用していくつかの記事を表示するWebアプリケーションを作成しようとしています。 DBからすべての記事を抽出しました。プレビューとして使用されています。 これで、1つの記事を表示するページを作成します。記事の プレビューが/記事/に示されている、私は/記事では、単一の記事を表示したいと思います//IDCodeIgniter - Single result
を読んでこれは私のコードです:
コントローラ
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Articles extends CI_Controller
{
public function index()
{
$this->load->model('articles_model');
$articles_data['data'] = $this->articles_model->select_articles();
$this->load->view('header');
$this->load->view('nav');
$this->load->view('articles-content', $articles_data);
$this->load->view('footer');
}
public function read()
{
//?????
}
モデル
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Articles_model extends CI_Model
{
public function select_articles()
{
$this->db->select('*');
$this->db->from('articles');
$this->db->join('authors', 'articles.id_author = authors.id_author', 'left');
$this->db->join('images', 'articles.id_image = images.id_image', 'left');
$query = $this->db->get();
return $query->result_array();
}
}
ビュー
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<div id="content">
<div id="articles">
<?php foreach($data as $row){
$limited_article = word_limiter($row['article_text'], 200);
?>
<section class="article">
<h2><?php echo $row['article_title'];?></h2>
<img class="article-image" src="<?php echo base_url('/assets/images/' . $row['image']) ;?>">
<p class="info">Author: <?php echo $row['author']; ?> Date: <?php echo $row['article_data'] ?></p>
<p><?php echo $limited_article; ?></p>
</section>
<?php }?>
</div>
</div>
私はどのように行うことができますか?前もって感謝します!