Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8768163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:00:19+00:00 2026-06-13T17:00:19+00:00

I try add example from http://ellislab.com/codeigniter/user_guide/tutorial/news_section.html to my site, this is code: news_model <?php

  • 0

I try add example from http://ellislab.com/codeigniter/user_guide/tutorial/news_section.html

to my site, this is code:

news_model

<?php
class News_model extends CI_Model {

    public function __construct()
    {
        $this->load->database();
    }


public function get_news($art = FALSE)
{
    if ($art === FALSE)
    {
        $query = $this->db->get('news');
        return $query->result_array();
    }

    $query = $this->db->get_where('news', array('art' => $art));
    return $query->row_array();
}

public function set_news()
{
    $this->load->helper('url');

    $slug = url_title($this->input->post('title'), 'dash', TRUE);

    $data = array(
        'title' => $this->input->post('title'),
        'art' => $art,
        'text' => $this->input->post('text'),
        'image'=> $image
    );

    return $this->db->insert('news', $data);
  }
}
?>

news_controller

<?php
class News extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('news_model');
    }

    public function index()
    {
        $session_data = $this->session->userdata('logged_in');
        $data['username'] = $session_data['username'];
        $data['errors_login'] = array();
        $data['news'] = $this->news_model->get_news();
        $data['title'] = 'News archive';

    $this->load->view('main/open_news', $data);
    }

    public function view($art) {
    $data['news_item'] = $this->news_model->get_news($art);

    if (empty($data['news_item']))
    {
        show_404();
    }

    $data['title'] = $data['news_item']['title'];
    $session_data = $this->session->userdata('logged_in');
    $data['username'] = $session_data['username'];
    $data['errors_login'] = array();
    $this->load->view('main/open_one_news', $data);
    }   
}

open_news

<?php
$this->load->view('mains/header');
$this->load->view('main/news');
$this->load->view('mains/footer');
?>

news view

<?php foreach ($news as $news_item): ?>

    <h2><?php echo $news_item['title'] ?></h2>
    <div id="main">
        <?php echo $news_item['text'] ?>
    </div>
    <a href="news/<?php $news_item['art'] ?>">View article</a>
<?php endforeach ?>

And when I click in <a href="news/<?php $news_item['art'] ?>">View article</a>

The page is not forwarding to concret page with news, only in link duplicate “news”:

http://localhost/index.php/news/news/news/news/news/news

I dont know what is problem. But I think it will by may in routes.config
Because I have only:
$route['default_controller'] = 'login'; -> this is my start page

But in CodeIgniter tutorial is:

$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';

But when I add some from 3 first line, even the first page with list of news doesn`t open.

SOLVED:
I make stupid mistake. Because controller name news, but function: public function view($art), and the link should be: 'news/view/'.$news_item['art'].

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:00:22+00:00Added an answer on June 13, 2026 at 5:00 pm

    You forgot the echo at:

    <a href="news/<?php $news_item['art'] ?>">View article</a> 
    

    You should use:

    <a href="news/<?php echo $news_item['art'] ?>">View article</a> 
    

    or:

    <?php echo anchor('news/' . $news_item['art'], 'View article');
    

    or:

    <?php echo anchor("news/{$news_item['art']}", 'View article');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to use this example to get images urls from http://www.nydailynews.com/cmlink/NYDN.Article.rss but no
From this example http://www.smartclient.com/smartgwt/showcase/#tree_databinding_local , I started to implement my own tree structure dynamically
I am trying to build the hello.c example from http://www.glprogramming.com/red/chapter01.html (look for Example 1-2).
I try this tutorial for building a Widget for Android Homescreen. http://www.helloandroid.com/files/xmaswidget/android_howto-hellowidget.pdf But if
Following the example in this article: http://blogs.msdn.com/b/yaohuang1/archive/2012/05/21/asp-net-web-api-generating-a-web-api-help-page-using-apiexplorer.aspx I've set up everything to provide documentation
I'm trying to create a redirect from http://example.com/links/AAA to http://links.example.net/l/AAA (where AAA is a
Getting this error when try to add an item to my repositories/context: Collection has
I've used JRab's example here http://supportforums.blackberry.com/t5/Tablet-OS-SDK-for-Adobe-AIR/App-specific-system-menu/td-p/693 ... to add a header menu to my
Good day. When i try to run the example from MSDN. But it failed
Hi i try to add sound to my game i used aphoneGap code to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.