user.php的(控制器)
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller {
public function index()
{
$this->load->view('view_login');
}
public function login(){
echo 'You landed Here!!!';
}
}
?>
view_login.php(视图)
<body>
<h1>Please Login!</h1>
<p>Use the Form below to login to our site...</p>
<?php echo validation_errors();?>
<?php echo form_open(base_url() . 'user/login'); ?>
<label>Username</label>
<?php echo form_input(array('id' => 'username', 'name' => 'username'));?>
<label>Password</label>
<?php echo form_password(array('id' => 'password', 'name' => 'password'));?>
<?php echo form_submit(array('name' => 'submit'), 'Submit'); ?>
<?php echo form_close();?>
routes.php文件
$route['default_controller'] = "";
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
的config.php
$config['base_url'] = 'http://localhost/codeigniter/user/';
$config['encryption_key'] = 'REALLY_LONG_NUMBER';
$config['index_page'] = '';
有谁知道这段代码有什么问题?点击提交按钮后,控件不会进入用户控制器功能登录,也不会显示消息&#34;您已经到达此处&#34;。如果基本网址是否正确,我不应该指定默认控制器。
答案 0 :(得分:2)
如果要从URL中删除index.php,请将文件config.php中的配置'base_url'替换为:
$config['base_url'] = 'http://localhost/codeigniter/';
否则,将文件config.php中的配置'base_url'替换为:
$config['base_url'] = 'http://localhost/codeigniter/index.php';
答案 1 :(得分:0)
在routes.php
$route['default_controller'] = "";//you must provide your default controller name
和form
打开应该是
<?php echo form_open('user/login'); ?>
在config.php
$config['base_url'] = '';//remove this
您删除了['index_page']
,因此您必须.htaccess
挑衅
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
答案 2 :(得分:0)
它还没有工作...... user.php的
<?php
if(!defined(&#39; BASEPATH&#39;))退出(&#39;不允许直接访问脚本&#39;);
类用户扩展CI_Controller {
public function index()
{
$this->load->view('view_login');
}
public function login(){
echo 'You landed Here!!!';
}
}
&GT;
view_login.php
body>
<h1>Please Login!</h1>
<p>Use the Form below to login to our site...</p>
<?php echo validation_errors();?>
<?php echo form_open('user/login'); ?>
<label>Username</label>
<?php echo form_input(array('id' => 'username', 'name' => 'username'));?>
<label>Password</label>
<?php echo form_password(array('id' => 'password', 'name' => 'password'));?>
<?php echo form_submit(array('name' => 'submit'), 'Submit'); ?>
<?php echo form_close();?>
routes.php文件
$route['default_controller'] = "user";
$ route [&#39; 404_override&#39;] =&#39;&#39 ;; $ route [&#39; translate_uri_dashes&#39;] = FALSE;
的config.php
$config['index_page'] = '';
$ config [&#39; base_url&#39;] =&#39;&#39;;
htaccess.php
<IfModule authz_core_module>
Require all denied
拒绝所有人 RewriteEngine On RewriteCond%{REQUEST_FILENAME}! - f RewriteCond%{REQUEST_FILENAME}!-d RewriteRule ^(。*)$ index.php / $ 1 [L]
答案 3 :(得分:0)
我明白了你的意思。
如果您使用的是form和base_url(),则必须使用helper。我做了演示和它的工作。 此帮助程序用于通过控制器重定向您的页面。为此,您必须创建构造函数,并在控制器调用时自动调用该构造函数。
user.php的:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper('form');
$this->load->helper('url');
}
public function index()
{
$this->load->view('view_login');
}
public function login(){
echo 'You landed Here!!!';
}
}
?>
view_login.php:
<body>
<h1>Please Login!</h1>
<p>Use the Form below to login to our site...</p>
<?php echo form_open(base_url() . 'user/login'); ?>
<label>Username</label>
<?php echo form_input(array('id' => 'username', 'name' => 'username'));?>
<label>Password</label>
<?php echo form_password(array('id' => 'password', 'name' => 'password'));?>
<?php echo form_submit(array('name' => 'submit'), 'Submit'); ?>
<?php echo form_close();?>