我在代码点火器上开发了一个网络应用程序..这是我第一次在代码点火器上工作..在我的本地主机上开发Web应用程序后,所以我决定将我的代码点火器Web应用程序放在临时免费服务器上.. 所以我在这个网站上上传了我的网站1免费托管...然后我导入了我的数据库..之后,我更改了数据库.php文件中数据库的设置。而且我还更改了 config.php 文件中的基本 URL..因为这是我的域名 http://hello.hostingsiteforfree.com/...所以我把它改成了这个网址..但是后来我收到以下错误...我不知道出了什么问题..我已经搜索了很多,但没有任何帮助。而且我忘了提到我的.htaccess文件是空的..表示其中没有一行
这是我得到的错误
404 Page Not Found
The page you requested was not found.
路线.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$route['default_controller'] = "loginController";
$route['404_override'] = '';
/* Location: ./application/config/routes.php */
我的控制器
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
类 LoginController 扩展CI_Controller {
function index(){
$new['main_content'] = 'loginView';
$this->load->view('loginTemplate/template', $new);
}
function verifyUser(){
//getting parameters from view
$data = array(
'username' => $this->input->post('username'),
'password' => $this->input->post('password')
);
$this->load->model('loginModel');
$query = $this->loginModel->validate($data);
if ($query){ //if the user c validated
//data variable is created becx we want to put username in session
$data = array(
'username' => $this->input->post('username'),
'is_logged_in' => true
);
$this->session->set_userdata($data);
redirect('sessionController/dashboard_area');
}
else
{
$this->index();
}
}
function logout()
{
$this->session->sess_destroy();
$this->index();
}
}
?>
配置文件
$config['base_url'] = 'http://hello.hostingsiteforfree.com/';
$config['index_page'] = 'index.php';
由于您没有任何.htaccess来编辑您的网址,因此您必须添加一个index.php
当调用控制器时,例如
http://hello.hostingsiteforfree.com/index.php/loginController
我尝试通过上面的 url 访问它,它可以工作,但数据库连接设置不正确
在您的配置文件中,如果它为空,则$config['index_page'] = ''
添加一个index.php
检查它是否有效
查看您的application/routes.php
,并确保$route['default_controller']
正确设置为默认控制器。如下,这是我的路线.php:
$route['default_controller'] = "home";
$route['404_override'] = '';
另外,请确保您的默认控制器(在我的例子中,它的application/controllers/home_controller.php
和其中是class Home extends CI_Controller {...}
--
如果这不起作用,请确保您的默认控制器正确调用默认视图并按此方式加载它:
$this->load->view('home_view', $data);
--
如果这不起作用,请查看您的application/config/config.php
并确保以下内容正确设置如下,如果您想摆脱 url 中的index.php
(对于干净的 url):
$config['index_page'] = '';$config['uri_protocol'] = "自动";
如果你要找干净的URL,请发布你的.htaccess(应该遵循这样的内容:http://www.farinspace.com/codeigniter-htaccess-file/),这样我们就可以更详细地查看它,如果以上都不能修复它,我们会尝试修复它。
你用.htaccess删除了index.php吗? 如果没有,那就把它放在最后。