Note that there are some explanatory texts on larger screens.

plurals
  1. PONews system CodeIgniter
    primarykey
    data
    text
    <p>I try add example from <code>http://ellislab.com/codeigniter/user_guide/tutorial/news_section.html</code></p> <p>to my site, this is code:</p> <p>news_model</p> <pre><code>&lt;?php class News_model extends CI_Model { public function __construct() { $this-&gt;load-&gt;database(); } public function get_news($art = FALSE) { if ($art === FALSE) { $query = $this-&gt;db-&gt;get('news'); return $query-&gt;result_array(); } $query = $this-&gt;db-&gt;get_where('news', array('art' =&gt; $art)); return $query-&gt;row_array(); } public function set_news() { $this-&gt;load-&gt;helper('url'); $slug = url_title($this-&gt;input-&gt;post('title'), 'dash', TRUE); $data = array( 'title' =&gt; $this-&gt;input-&gt;post('title'), 'art' =&gt; $art, 'text' =&gt; $this-&gt;input-&gt;post('text'), 'image'=&gt; $image ); return $this-&gt;db-&gt;insert('news', $data); } } ?&gt; </code></pre> <p>news_controller</p> <pre><code>&lt;?php class News extends CI_Controller { public function __construct() { parent::__construct(); $this-&gt;load-&gt;model('news_model'); } public function index() { $session_data = $this-&gt;session-&gt;userdata('logged_in'); $data['username'] = $session_data['username']; $data['errors_login'] = array(); $data['news'] = $this-&gt;news_model-&gt;get_news(); $data['title'] = 'News archive'; $this-&gt;load-&gt;view('main/open_news', $data); } public function view($art) { $data['news_item'] = $this-&gt;news_model-&gt;get_news($art); if (empty($data['news_item'])) { show_404(); } $data['title'] = $data['news_item']['title']; $session_data = $this-&gt;session-&gt;userdata('logged_in'); $data['username'] = $session_data['username']; $data['errors_login'] = array(); $this-&gt;load-&gt;view('main/open_one_news', $data); } } </code></pre> <p>open_news</p> <pre><code>&lt;?php $this-&gt;load-&gt;view('mains/header'); $this-&gt;load-&gt;view('main/news'); $this-&gt;load-&gt;view('mains/footer'); ?&gt; </code></pre> <p>news view</p> <pre><code>&lt;?php foreach ($news as $news_item): ?&gt; &lt;h2&gt;&lt;?php echo $news_item['title'] ?&gt;&lt;/h2&gt; &lt;div id="main"&gt; &lt;?php echo $news_item['text'] ?&gt; &lt;/div&gt; &lt;a href="news/&lt;?php $news_item['art'] ?&gt;"&gt;View article&lt;/a&gt; &lt;?php endforeach ?&gt; </code></pre> <p>And when I click in <code>&lt;a href="news/&lt;?php $news_item['art'] ?&gt;"&gt;View article&lt;/a&gt;</code> </p> <p>The page is not forwarding to concret page with news, only in link duplicate "news": </p> <pre><code>http://localhost/index.php/news/news/news/news/news/news </code></pre> <p>I dont know what is problem. But I think it will by may in routes.config Because I have only: <code>$route['default_controller'] = 'login';</code> -> this is my start page</p> <p>But in CodeIgniter tutorial is: </p> <pre><code>$route['news/(:any)'] = 'news/view/$1'; $route['news'] = 'news'; $route['(:any)'] = 'pages/view/$1'; $route['default_controller'] = 'pages/view'; </code></pre> <p>But when I add some from 3 first line, even the first page with list of news doesn`t open.</p> <p>SOLVED: I make stupid mistake. Because controller name news, but function: public function <code>view($art)</code>, and the link should be: <code>'news/view/'.$news_item['art']</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload