I have a problem with codeigniter 3
in my file routes.php I have
$route['article/(:num)/(:any)'] = 'article/index/$1/$2';
in my file article.php I have
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Article extends Frontend_Controller {
public function __construct()
{
parent::__construct();
$this->data['recent_news'] = $this->article_m->get_recent();
}
public function index($id, $slug)
{
// Fetch the article
$this->article_m->set_published();
$this->data['article'] = $this->article_m->get($id);
// Return 404 if not found uri_string() return blog/comments/123
count($this->data['article']) || show_404(uri_string());
// Redirect if slug was incorrect
$request_slug = $this->uri->segment(3);
$set_slug = $this->data['article']->slug;
if ($request_slug != $set_slug) {
// with 301 redirect
redirect('article/' . $this->data['article']->id . '/' . $this->data['article']->slug, 'location', 301);
}
// Load view
add_meta_title($this->data['article']->title);
$this->data['subview'] = 'article';
$this->load->view('_main_layout', $this->data);
}
}
when I enter to the url http://ci-cms.com/article/6/confesion it's ok, but if I enter to the url http://ci-cms.com/article I have a problem as this:
An uncaught Exception was encountered
Type: ArgumentCountError
Message: Too few arguments to function Article::index(), 0 passed in C:\xampp\htdocs\ci-cms\system\core\CodeIgniter.php on line 532 and exactly 2 expected
Filename: C:\xampp\htdocs\ci-cms\application\controllers\article.php
Line Number: 12
Backtrace:
File: C:\xampp\htdocs\ci-cms\index.php Line: 320 Function: require_once
How can I resolve this problem?, please help me I'm new in this framework...
thanks.