[eluser]balboa_1990[/eluser]
In my application, the user can create an account, log in and it should display news articles from the database. When the user logs in now however, it displays the method/function name in the url instead of admin/news and does not display the data from the database (only the the header and links from the view). Any help would be appreciated.
Code:
CONTROLLER:
class Login extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$data['main_content'] = 'login';
$this->load->view('include/template', $data);
}
//Validate login area
//This method will have the credentials validation
public function login_validation() {
$data['error'] ="Invalid Username or Password";
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|callback_username_check');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_password_check');
if($this->form_validation->run() == FALSE)
{
//Field validation failed. User redirected to login page
$this->index();
}else{
$this->load->model('register_model');
if($query = $this->register_model->validate()) {
$this->load->model('news_model');
$data = array('news' => $this->news_model->getArticle());
$data['title'] = 'Admin | Home';
$data['heading'] = 'News Articles';
$data['main_content'] = 'admin/news';
$this->load->view('include/template', $data);
}else {
$this->load->view('login',$data);
}
}
}
//Validate signup area
public function signup() {
$data['main_content'] = 'signup';
$this->load->view('include/template', $data);
}
public function create_member() {
$this->load->library('form_validation');
//field name, error, message, validation rules
$this->form_validation->set_rules('first_name', 'Name', 'trim|required');
$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
$this->form_validation->set_rules('email_address', 'Email Address', 'trim|required|valid_email');
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
$this->form_validation->set_rules('password2', 'Password Confirm', 'trim|required|matches[password]');
if($this->form_validation->run() == FALSE) {
$this->signup();
}else{
$this->load->model('register_model');
if($query = $this->register_model->create_membership()) {
$data['main_content'] = 'signup_successful';
$this->load->view('include/template', $data);
}else {
$this->load->view('signup');
}
}
}
}
VIEW for news
Code:
<?php foreach ($news as $article): ?>
<h2><?php echo $article['title'] ?></h2>
<p><?php echo $article['content'] ?></p>
<p><?php echo $article['author'] ?></p>
<p><?php echo $article['date'] ?></p>
<?php endforeach ?>
News Model:
Code:
class News_model extends CI_Model {
public function __construct() {
parent::__construct();
}
function getArticle () {
$this->db->select('*');
$this->db->from('news');
$this->db->order_by('id', 'DESC');
return $this->db->get()->result_array();
}
}
Been struggling most of today and i fixed one bug for this application and another happens, typical! No error message are being displayed or in the php log.