I have two controllers in the same folder. One is named criteria, and one is named reviewApprove. Their code is identical (other than the class name).
If I set criteria to the default controller in routes, then I am able to access it, but no matter what I cannot navigate to the reviewApprove controller.
If I don't set a default controller and navigate to index.php/reviewApprove, or index.php/criteria.. that will work just fine.
If I set reviewApprove to the default controller I can see it as well.
My htaccess file is set. I have compared my project to a few other code igniter projects and can't tell what I'm doing wrong.
Anyone have any ideas?
criteria controller
class Criteria extends APN_Controller {
public function __construct() {
parent::__construct();
$this->load->vars(array('nav' => array('','', 'current', '', '')));
}
public function index(){
$this->_set('title', "Certified Analytics");
$this->_set('js', "/resources/authenticated/js/coverage");
$this->_set('css', "/resources/authenticated/css/enroll");
$this->load->view('authenticated/header/header', $this->_data);
$this->load->view('authenticated/content/coverage');
$this->load->view('authenticated/footer/footer');
}
}
reviewApprove controller
class ReviewApprove extends APN_Controller {
public function __construct() {
parent::__construct();
$this->load->vars(array('nav' => array('','current', '', '', '')));
}
public function index(){
$this->_set('title', "Certified Analytics");
$this->_set('js', "/resources/authenticated/js/criteria");
$this->_set('css', "/resources/authenticated/css/enroll");
$this->load->view('authenticated/header/header', $this->_data);
$this->load->view('authenticated/content/reviewApprove');
$this->load->view('authenticated/footer/footer');
}
}
routes
$route['default_controller'] = "criteria";
htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /certifiedAnalytics/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Is anything else necessary?
Related
I have two codeigniter installations under my public_html folder on my server. One is directly under public_html and the other is under public_html/posts_receive.
The instance under public_html is working normal but when I try to access the codeigniter controller inside public_html/posts_receive it shows:
404 Page Not Found
tried url http://www.example.com/posts_receive/index.php/dashboard
To solve this problem I have added an .htaccess file under public_html/posts_receive which contain the following:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /posts_receive
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
My controller is named dashboard.php and contains the following:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Dashboard extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->library("pagination");
}
public function index() {
$config = array();
$data['link_sel']='dashboard';
$data['stats']=$this->fetch_stats();
$this->load->view("header_inc", $data);
$this->load->view("dashboard", $data);
$this->load->view("footer_inc", $data);
}
}
?>
config.php includes:
$config['base_url'] = 'http://www.example.com/posts_receive/';
$config['index_page'] = 'index.php';
You should run both applications from one CodeIgniter base. You will have 2 sub folders in your application folder. Take a look at the documentation: https://www.codeigniter.com/userguide3/general/managing_apps.html
From there on you can create the same index.php file as in your root in your posts_recieve folder and point it to the right application directory. That is how i managed to do it. Otherwise the CodeIgniter instance in your root will think you are navigating to a controller called posts_recieve which does not exists in that application.Hope this helps. Otherwise, just ask when things are unclear.
Inside .htaccess, RewriteBase /posts_receive part is not needed.
RewriteRule ^(.*)$ index.php?$1 [L]
should become
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
(<IfModule mod_rewrite.c> is a server configuration condition. It means you should have mod_rewrite module installed and active on the web server for these settings to work.)
You could leave empty $config['index_page'] inside config.php:
$config['index_page'] = '';
And you can call the controller without the index.php part:
http://www.example.com/posts_receive/dashboard
So I'm rather new to Codeigniter...
I have a file on my local host that submits a form:
$id =array('id' => 'commentForm');
echo form_open("form_validate", $id);
public function form_validate()
{
$this->load->library("form_validation");
$this->form_validation->set_rules('date', 'Date', 'required');
$this->form_validation->set_rules('Cname', 'Client Name', 'required');
....
}
From what I understand is that when I hit submit on the form, it goes to the function "form_validate()"(or whatever you set at the submission page) in the controller and executes that.
The Code works just fine on my localhost, however once I upload it to my live server, instead of going to the function in the controller it looks for a page called form_validation(at least thats what I think from the URL)
I've rewritten my base path as:
$config['base_url'] = 'http://mysite.com/ci_form';
And gotten rid of the index.php under index
I've also taken the Codeigniter mod_rewrite form their site
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci_form/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
<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
You're missing your controller in the form_open("form_validate"); function, that's why it's looking for a controller called form_validate.
It needs to be form_open("your_controller_name/form_validate");
http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html
Also your forms should be in your views
Maybe this will help
I am using CodeIgniter and need to get rid of the "index.php" in the URL.
I copied the .htaccess file from codeigniter tutorial, emptied the $config['index_page'] = '';
and put the .htaccess in the root directory.
Without the .htaccess file it works fine, but ugly: www.example.com/index.php/site/home
For some reason it's not working and just throws a 500's error.
Where is the bug and how can I resolve it?
Thank you in advance
My .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folders by users.
#Additionly this will allow you to create a System.php controller,
#previously this would not have not been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^{.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
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>
My site controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Site extends CI_Controller {
public function index(){
$this->home();
}
public function home(){
echo "default function started.<br/>";
$this->hello();
$data['title'] = 'Home!';
$data['name'] = 'Ilia';
$data['fname'] = 'Lev';
$data['operation'] = 'minus';
$data['val1'] = 5;
$data['val2'] = 7;
echo $data['operation']."<br/>";
$data['result'] = $this->math($data);
$this->viewLoad("home_view", $data);
echo "<br/>";
}
public function hello(){
echo "hello function started.<br/>";
}
public function math($data){
$operation = $data['operation'];
$val1 = $data['val1'];
$val2 = $data['val2'];
$this->load->model("math");
return $this->math->calculate($operation, $val1, $val2)."<br/>";
}
public function viewLoad($whatToView, $data){
try{
$this->load->view($whatToView, $data);
}catch(Exception $e){
echo "There is no such view";
}
}
public function about(){
$data['title'] = "About!";
$this->viewLoad("about_view",$data);
}
}
If this is really part of the .htaccess file, it would cause your problem:
RewriteRule ^{.*)$ /index.php?/$1 [L]
^^^ typo?
Should be:
RewriteRule ^(.*)$ /index.php?/$1 [L]
I too had the same problem but my code was correct and i was using wamp server, then
I found rewrite module is not enabled
so went to apache/conf/httpd.conf and uncommented line
LoadModule rewrite_module modules/mod_rewrite.so
Now its working fine.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
.htaccess throws a 500 error
I am using CodeIgniter and need to get rid of the "index.php" in the URL.
I copied the .htaccess file from CI tutorial, emptied the $config['index_page'] = '';
and put the .htaccess in the root directory.
Without the .htaccess file it works fine, but ugly: www.example.com/index.php/site/home
For some reason it's not working and just throws a 500's error.
In the log there is a row that repeats itself in every attempt: [Thu
Dec 20 04:01:13 2012] [alert] [client 2.55.118.161]
/home/morro1980/data/www/knight-guard.org/.htaccess:
directive requires additional arguments.
The mod_rewrite is installed and working
Where is the bug and how can I resolve it?
Thank you in advance
My .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folders by users.
#Additionly this will allow you to create a System.php controller,
#previously this would not have not been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
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>
My site controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Site extends CI_Controller {
public function index(){
$this->home();
}
public function home(){
echo "default function started.<br/>";
$this->hello();
$data['title'] = 'Home!';
$data['name'] = 'Ilia';
$data['fname'] = 'Lev';
$data['operation'] = 'minus';
$data['val1'] = 5;
$data['val2'] = 7;
echo $data['operation']."<br/>";
$data['result'] = $this->math($data);
$this->viewLoad("home_view", $data);
echo "<br/>";
}
public function hello(){
echo "hello function started.<br/>";
}
public function math($data){
$operation = $data['operation'];
$val1 = $data['val1'];
$val2 = $data['val2'];
$this->load->model("math");
return $this->math->calculate($operation, $val1, $val2)."<br/>";
}
public function viewLoad($whatToView, $data){
try{
$this->load->view($whatToView, $data);
}catch(Exception $e){
echo "There is no such view";
}
}
public function about(){
$data['title'] = "About!";
$this->viewLoad("about_view",$data);
}
}
The first <ifModule> is not closed, this:
RewriteRule ^(.*)$ index.php?/$1 [L]
<IfModule>
has to be
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
#^
Make sure you have <IfModule></IfModule> matched in your .htaccess.
Followed a tutorial to remove index.php from the URLs in Code Igniter.
It works now for my default_controller, but not for other pages(or views) properly.
I have one controller, Pages, and it has one method, View($page = 'home'), to load pages with other content based on the parameter passed.
If I type localhost/dev into URL - I land on my home page, which is correct.
If I type localhost/dev/aboutus - I receive 404. It only works if I type localhost/dev/pages/view/aboutus.
What I wanted to happen is by typing localhost/dev/aboutus it would show me the AboutUs view.
Routes.php
$route['default_controller'] = "pages/view";
$route['dev/(:any)'] = "dev/pages/view/$1";
$route['404_override'] = '';
Pages.php (controller)
<?php
class Pages extends CI_Controller
{
public function view($page = 'home')
{
if (!file_exists('application/views/pages/' . $page . '.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->load->view('templates/header', $data);
$this->load->view('pages/' . $page);
$this->load->view('templates/footer');
}
}
?>
.htaccess file (located in /dev/ folder)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /dev/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
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>
This route $route['dev/(:any)'] = "dev/pages/view/$1"; is a little fishy because CodeIgniter routes should not include the project name (dev in your case). They begin on the controller level, not the project one.
The route you have written would imply that if a user typed http://localhost/dev/dev/something (yes, two dev's) they would be routed to a controller dev.php and into a function with prototype: function('view', 'something'){}
Why so complicated? You should make all of your main page names into controllers. Routes should only be touched for special cases.
Create a file aboutus.php in application/controllers with contents:
<?php
class Aboutus extends CI_Controller{
function __construct(){
parent::__construct();
}
function index(){
"I'm in the about controller!";
//$this->load->view("some_view") ;
}
}
You can access it with http://localhost/dev/aboutus
In your config.php leave it blank if you haven't
$config['index.php'] = '';