我编的登录系统为什么url只有第二字段
我编写的登录系统为什么URL只有类和方法两个字段,我想现实用户ID为第三字段,却怎么也显示不出来,费解 可以看看你的代码吗 jeongee 发表于 2011-8-16 11:24 static/image/common/back.gif可以看看你的代码吗
嗯,谢谢了,
controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Users extends CI_Controller{
function __construct()
{
parent::__construct();
$this->load->library('session');
}
//登录
function index()
{
$data['title']='登录';
$this->load->view('login_view',$data);
}
//登录
function login()
{
header('refresh:60; url=' . site_url());
$this->form_validation->set_rules('username','用户名','trim|required|min_length|max_length|xss_clean');
if (!$this->form_validation->run())
{
$data['title'] = '登录';
$data['error'] = '登录失败,检查';
$this->load->view('login_view',$data);
}
else
{
if($this->Hou_model->check())
//设置验证规则
{
$data['title'] = '登录成功';
$this->login_n();
//登陆成功;
}
//设置验证规则
else
{
$data['title']='登录失败';
$data['error']='wrong';
$this->load->view('login_view',$data);
}
}
}
function login_n()
{
$data['title'] = '登录成功';
$this->load->view('success',$data);
}
//注册
function Registration()
{
$data['title']='注册';
$this->load->view('Regis_view',$data);
}
function Registration_n()
{
$this->form_validation->set_rules('username','用户名','trim|required|min_length|max_length|xss_clean|callback_username_check');
$this->form_validation->set_rules('password','密码','trim|required||min_length|max_length|matches');
$this->form_validation->set_rules('password2','确认密码', 'trim|required');
if(!$this->form_validation->run())
{
$data['title'] = '注册';
$data['error'] = '注册失败';
$this->load->view('Regis_view',$data);
}
else
{
header('refresh:60; url=' . site_url());
if($this->Hou_model->add())
{
$this->success();
}
else
{
$this->signup();
}
}
}
function success()
{
$data['title'] = '注册成功';
$this->load->view('Regis_success',$data);
}
function logout()
{
$this->session->sess_destiry();
redirect('login');
}
}
?>
以下是我的model:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Hou_model extends CI_Model
{
function __construst()
{
parent::__construst;
}
function check()
{
$username=$this->db->where('username', $this->input->post('username'));
$password=$this->db->where('password', md5($this->input->post('password')));
$q=$this->db->get('kingdom');
if($q->num_rows()>0)
{
return $q->row();
$newdata = array
(
'username'=>$row->username,
'logged_in'=>true
);
$this->session->set_userdata($newdata);
}
return $query->num_rows();
}
//检查登录
function add()
{
date("Y-M-d G:i:s");
$data['username'] = $this->input->post('username');
$data['password'] = md5($this->input->post('password'));
$data['userrole'] = $this->input->post('userrole');
$data['createtime'] = $this->input->date("Y-M-d G:i:s");
return $this->db->insert('kingdom',$data);
}
}
?>
以下是我的view:
<html>
<head>
<title>登录</title>
</head>
<body>
<h2><p align="center"><?php echo $title;?></p></h2>
<p align="center"><?php if(isset($error)) echo $error;?></p>
<?php
echo form_open('users/login');?>
<p align="center">用户名:<?php echo form_input('username');echoform_error('username'); ?></p>
<p align="center">密 码:<?php echo form_password('password');
echo form_error('password'); ?></p>
<p align="center"><?php echo form_submit('submit','登录')?></p>
<?php echo form_close()?>
<p align="center"><?phpecho anchor('users/Registration','注册') ?></p>
</body>
</html>
可能有点乱,不好意思,
没见你推送第三段的内容给uri,怎么会显示呢? 没有发现楼主哪里写了多于两段的 URL。
URL 有几段是由开发者自己控制的,不是 CI 帮你控制的。 jeongee 发表于 2011-8-16 11:50 static/image/common/back.gif
没见你推送第三段的内容给uri,怎么会显示呢?
那麻烦再问一下,怎么推送我的第三段给url呢,不好意思哈 Hex 发表于 2011-8-16 11:51 static/image/common/back.gif
没有发现楼主哪里写了多于两段的 URL。
URL 有几段是由开发者自己控制的,不是 CI 帮你控制的。 ...
那么麻烦问一下,怎么控制URL有几段,需要在哪里设置呢 kevin0171 发表于 2011-8-16 11:59 static/image/common/back.gif
那么麻烦问一下,怎么控制URL有几段,需要在哪里设置呢
很简单啊,URL 都是由你的代码生成的,你可以用 site_url('第一段/第二段/第三段/..../第n段'); 函数生成。
这个手册都有详细介绍。 Hex 发表于 2011-8-16 12:03 static/image/common/back.gif
很简单啊,URL 都是由你的代码生成的,你可以用 site_url('第一段/第二段/第三段/..../第n段'); 函数生成 ...
额。。。
echo site_url("news/local/123");
手册里只是个例子,这个例子我不会用,麻烦您了 kevin0171 发表于 2011-8-16 12:13 static/image/common/back.gif
额。。。
echo site_url("news/local/123");
手册里只是个例子,这个例子我不会用,麻烦您了 ...
不明白你哪里不会用?
<a href="<?=site_url('a/b/c/d')?>">链接标题</a>
这个不会用?
页:
[1]
2