Aditya Rahadian
Aditya Rahadian

Reputation: 73

Default Controller not Working

I have a problem.

I cant access default controller. I tried to modify my routes and htaccess so many times but default controller does not work.

my routes.php

$route['default_controller'] = 'front';
$route['page/(:any)'] = "front/page/$1";
$route['cake/(:any)'] = 'front/cake/$1';
$route['product'] = 'front/allcakescategory';
$route['login'] = 'front/login';
$route['register'] = 'front/register';
$route['logout'] = 'front/logout';
$route['invoice/(:any)'] = 'cart/invoice/$1';
$route['404_override'] = '';

my .htaccess file

<IfModule mod_rewrite.c>
  RewriteEngine On
  # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
  #  slashes.
  # If your page resides at
  #  http://www.example.com/mypage/test1
  # then use
  # RewriteBase /mypage/test1/
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  # If we don't have mod_rewrite installed, all 404's
  # can be sent to index.php, and everything works as normal.
  # Submitted by: ElliotHaughin

  ErrorDocument 404 /index.php
</IfModule>

i really appreciate many kindof help. thanks before

UPDATE front.php (controller)

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
*
*/
class Front extends CI_Controller
{

    function __construct(){
        parent::__construct();
        $this->load->model('globalfunc');
        $this->load->model('cartmodel');

    }


    function index(){
        $data['cakes'] = $this->globalfunc->getCakes();
        $data['sliders'] = $this->globalfunc->getSlider();
        $data['title'] = 'Home';
        $this->load->view('front/home',$data);
    }

    public function login(){
        if(!is_login()){
            $data['title'] = 'Login';
            $data['redirectLogin'] = 'user/action/login?redirect=/';
            $this->load->view('front/login',$data);
        }else{
            redirect(base_url());
        }
    }

    public function register(){
        if(!is_login()){
            $data['title'] = 'Register';
            $data['redirectRegister'] = 'user/action/register?redirect=register';
            $data['cities'] = $this->globalfunc->getDelivery();
            $this->load->view('front/registerHome',$data);
        }else {
            redirect(base_url());
        }
    }

    public function page($slug){
        $data['content'] = $this->globalfunc->getSlugId($slug);
        if(!empty($data['content'])){
            $data['title'] = $data['content']->title;
            $this->load->view('front/page',$data);
        }else {
            echo 'not found';
        }
    }

    public function forget_password(){
        $data['title'] = 'Forget Password';
        $this->load->view('front/forget_pass',$data);

        if($this->input->post('forget_password')){
            $email_address = $this->input->post('email_address');
            $get = $this->globalfunc->validate(array('email_address' => $email_address),'user');
            if(!empty($get)){
                $data = array(
                    'user_id' => $get->id,
                    'key' => md5($email_address.time()),
                );
                $config = Array(
                    'protocol' => 'smtp',
                    'smtp_host' => 'ssl://smtp.mandrillapp.com',
                    'smtp_port' => 465,
                    'smtp_user' => '[email protected]',
                    'smtp_pass' => 'nbKsjydlNFv4pONa3g-1bA',
                    'mailtype' => 'html',
                    'charset' => 'iso-8859-1',
                    'wordwrap' => TRUE,
                );
                $msg = 'Click <a target="_blank" href="'.base_url('front/reset/'.$data['key']).'">here</a> to reset your password ';

                $this->load->library('email', $config);
                $this->email->set_newline("\r\n");
                $this->email->from('[email protected]', 'Reinaldo Yosua');
                $this->email->reply_to('[email protected]', 'Reinaldo Yosua');
                $this->email->to($email_address);
                $this->email->subject('Karaya Reset Password');
                $this->email->message($msg);
                $this->email->send();

                $this->db->insert('forget_password',$data);
            }

            else{
                echo 'not found';
            }
        }


    }

    public function reset($key){
        $get = $this->globalfunc->validate(array('key' => $key, 'status' => 0),'forget_password');
        if(!empty($get)){
            $data['title'] = 'Reset Password';
            $this->load->view('front/forget_pass',$data);
        }else{
            echo 'not found';
        }
    }

    /*public function allCakes(){
        $data['title'] = 'Our Product';
        $data['cakes'] = $this->globalfunc->getCakes();
        $this->load->view('front/list_cake',$data);
    }*/

    public function AllCakesCategory(){
        $data['title'] = 'Our Product';
        $data['cakes'] = $this->globalfunc->getCakes();
        $this->load->view('front/list_cake',$data);
    }

    public function cake($id, $slug =''){
        $data['cake'] = $this->globalfunc->getCake($id);
        $data['title'] = $data['cake']->name;
        $data['variations'] = $this->globalfunc->getVariation($id);
        $this->load->view('front/cake',$data);
    }

    public function logout(){
        $this->session->sess_destroy();
        redirect(base_url());
    }

    public function forget(){

    }
}

Upvotes: 1

Views: 119

Answers (1)

user5303823
user5303823

Reputation:

Update your controller name to front from Front and controller file Front.php from front.php. Recently i also faced this error.

Upvotes: 1

Related Questions