0

A few months ago I asked a question on SO related to route issue.

CodeIgniter routes issues to access the frontend and backend folder

After adding the answer in my code my issue got resolved.

Now, I created a controller called as Menu_controlle in the frontend folder and created a services.php file inside frontend on view.

Menu_control

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Menu_control extends CI_Controller {
  public $current_date;
  function __construct()
    {
        parent::__construct();
        $this->load->helper('form');
        $this->load->helper('url');
        date_default_timezone_set('Asia/Kolkata');
        $this->current_date= date('d-m-Y H:i:s');      
    }
 public function index()
  {
   $this->load->view('frontend/home');
  }
  public function services()
  {
   $this->load->view('frontend/services');
  }
}
?>

I added in the menu

<li><a href="<?php echo site_url('Menu_control/services');?>">Our Servces</a></li>

Now when I click on Our service menu then It gives me "object Not found" error. enter image description here

enter image description here Can anyone know my I am getting this error? .htaccess file is empty.

user9437856
  • 2,360
  • 2
  • 33
  • 92
  • The class name must match the controller's file name. If the class is `Menu_control` the file should be `Menu_control.php` not `Menu_controlle.php` – Javier Larroulet Sep 24 '18 at 12:10
  • @JavierLarroulet, Yes, I edited my question. I have the same name. – user9437856 Sep 24 '18 at 12:13
  • oh ok... and does the view exist? the 404 could be for either the controller (which doesn't seem to be the case) or the view. Is the PHP file for the view created under `views/frontend/services`? – Javier Larroulet Sep 24 '18 at 14:21
  • Yes, view/frontend/services file exists in the view. Even my index function is working but not able to access the other page. If I user public function index() { $this->load->view('frontend/services'); } Then it's working – user9437856 Sep 24 '18 at 17:27

2 Answers2

0

try PrettyURL for your project. write following code in .htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

or you can also use following codeigniter basic url

{{domain}}/index.php/{{controller_name}}/{{method_name}}
  • Thanks for the reply, I added your code in htaccess and I am getting an error 404 Page Not Found The page you requested was not found. – user9437856 Sep 24 '18 at 11:55
  • try basic url as i have provided – Vrushabh Ranpariya Sep 24 '18 at 11:58
  • I tried http://localhost/foldername/Menu_control/services, It gives me an error, Than I tried http://localhost/foldername/index.php/Menu_control/services then also same error. – user9437856 Sep 24 '18 at 12:04
  • then check file name and class name under this file that both should be same.if still not work then try something dump print and exit; in __cunstruct function to check class is works or not. – Vrushabh Ranpariya Sep 24 '18 at 12:10
  • The class name is same. I added exit(); in the __construct and it's working now what is the next process? – user9437856 Sep 24 '18 at 12:16
  • now you have to understand where is your errors. (may be in global variable) – Vrushabh Ranpariya Sep 24 '18 at 12:31
  • My helper is $autoload['helper'] = array('form','url','file'); – user9437856 Sep 24 '18 at 12:33
  • if you have already autoload 'form and url' then why are you trying to again load it in constructor? remove it. – Vrushabh Ranpariya Sep 24 '18 at 12:38
  • I remove it now. @Vrushabh, I just want to know the htaccess code. I have two htaccess file one is inside application and one is outside project. I added your code outside of the project – user9437856 Sep 24 '18 at 12:43
  • As for files not being accessible within the application folder, that's due to a .htaccess file in that folder denying all access in general. To prevent unintended file exposal. – Vrushabh Ranpariya Sep 25 '18 at 04:54
  • Yes, denying the file . Even my index function is working but not able to access the other page. If I user public function index() { $this->load->view('frontend/services'); } Then it's working – user9437856 Sep 25 '18 at 08:05
  • Not till now. I am still facing same issue. – user9437856 Sep 26 '18 at 06:21
0

try below code in .htaccess file of your root folder.

RewriteEngine on
RewriteBase /folder_name/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|style)
RewriteRule ^(.*) index.php?/$1

Replace the folder_name with your project folder name.

UPDATED ANSWER

Folder structure and Menu_control.php file.

enter image description here

It's working for me. Root folder's .htaccess file contains the code i have provided earlier.

enter image description here

Updated htaccess file with folder name

RewriteEngine on
RewriteBase /project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|style)
RewriteRule ^(.*) index.php?/$1
sady
  • 115
  • 6
  • Thanks for the reply, I added your code in htaccess but still getting the same issue – user9437856 Sep 24 '18 at 13:47
  • Which htaccess have you updated?There are two .htaccess files one is in the application folder and another one outside of application folder(i.e. into root folder). – sady Sep 25 '18 at 09:28
  • Yes, I updated root htaccess which is outside of the application folder – user9437856 Sep 25 '18 at 10:03
  • I don't know why it's not working for me. Can you share your htaccess code with folder name? – user9437856 Sep 26 '18 at 06:23
  • @user9437856..Yes i have updated the answer.you can certainly look into it. – sady Sep 26 '18 at 07:26
  • Give me some time to implement your code.. Reply you soon – user9437856 Sep 26 '18 at 07:44
  • @user9437856..No its not actually. – sady Sep 26 '18 at 11:05
  • I don't know why it's not working for me. I am deleting CI and downloading again and then I will try your code. So give me some time. I will update you. Please – user9437856 Sep 26 '18 at 14:15
  • @user9437856..yes please do fresh installation. – sady Sep 26 '18 at 15:13
  • I tried your code after fresh installation but still not working. Can you share the controller folder image? – user9437856 Nov 22 '18 at 11:54
  • @user9437856..Okay then access the url as "base_url/index.php/menu_control/services".See if it works. – sady Nov 22 '18 at 13:32
  • I have backend and frontend folder in view as well as on controller. If I directly call Menu_control then it's working but If I add backend/Menu_control then it's not working. This is my image folder path https://i.stack.imgur.com/frkdG.png I updated the controller name from menu_controler to Access_control – user9437856 Nov 22 '18 at 18:02