Hi,
How can i create a main page with codeigniter?
That page should contain a few links like login, register, etc.
I followed a tut to create a login screen. But it made codeigniter only for that purpose. This is the site i'm talking about:
http://tutsmore.com/programming/php/10-minutes-with-codeigniter-creating-login-form/
So basically what im trying to is, use codeigniter for more things than just a login form.
My try routes.php i set these settings:
$route['default_controller'] = "mainpage";
$route['login'] = "login";
My mainpage.php file:
class Mainpage extends Controller
{
function Welcome()
{
parent::Controller();
}
function index()
{
$this->load->view('mainpage.html');
}
}
Mainpage.html:
<HTML>
<HEAD>
<TITLE></TITLE>
<style>
a.1{text-decoration:none}
a.2{text-decoration:underline}
</style>
</HEAD>
<BODY>
<a class="2" href="login.php">login</a>
</BODY>
</HTML>
Login.php looks exactly like the one in that website which i provided the link for in this post:
Class Login extends Controller
{
function Login()
{
parent::Controller();
}
function Index()
{
$this->load->view('login_form');
}
function verify()
{
if($this->input->post('username'))
{ //checks whether the form has been submited
$this->load->library('form_validation');//Loads the form_validation library class
$rules = array(
array('field'=>'username','label'=>'username','rules'=>'required'),
array('field'=>'password','label'=>'password','rules'=>'required')
);//validation rules
$this->form_validation->set_rules($rules);//Setting the validation rules inside the validation function
if($this->form_validation->run() == FALSE)
{ //Checks whether the form is properly sent
$this->load->view('login_form'); //If validation fails load the <b style="color: black; background-color: rgb(153, 255, 153);">login</b> form again
}
else
{
$result = $this->common->login($this->input->post('username'),$this->input->post('password')); //If validation success then call the <b style="color: black; background-color: rgb(153, 255, 153);">login</b> function inside the common model and pass the arguments
if($result)
{ //if <b style="color: black; background-color: rgb(153, 255, 153);">login</b> success
foreach($result as $row)
{
$this->session->set_userdata(array('logged_in'=>true,'id'=>$row->id,'username'=>$row->username)); //set the data into the session
}
$this->load->view('success'); //Load the success page
}
else
{ // If validation fails.
$data = array();
$data['error'] = 'Incorrect Username/Password'; //<b style="color: black; background-color: rgb(160, 255, 255);">create</b> the error string
$this->load->view('login_form', $data); //Load the <b style="color: black; background-color: rgb(153, 255, 153);">login</b> page and pass the error message
}
}
}
else
{
$this->load->view('login_form');
}
}
}
What am i missing guys?