用户编辑页面无效

时间:2014-09-21 09:36:32

标签: codeigniter

点击我的用户编辑按钮<?php echo anchor('users/edit/'. $user->user_id, '<div class="btn btn-primary"><i class="fa fa-edit"></i> Edit</div>');?>

它将我发送到http://localhost/codeigniter/codeigniter-blog/admin/users/edit/1,但显示错误404 Page Not Found。的&#39; 1&#39;示例是user_id

但编辑功能存在。如何在我的用户控制器上使用用户ID进行编辑功能。因此,如果我点击某个用户,它将只更新该id行信息。

模型

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Model_user extends CI_Model {

    protected $id;

    function getAll() {
        $query = $this->db->get('user');

        if ($query->num_rows() > 0) {

            return $query->result();
            return $query->row('user_id');
            return true;
        } else {
            return false;
        }
    }

    public function editUser() {

    }

    public function getID($user_id) {
           $user_query = $this->db->get('user');

            if ($user_query->num_rows() == 1) {

                  return  $user_query->row('user_id', $user_id);

                  return true;

            } else {

                  return false;

            }
      }
}

控制器

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Users extends CI_Controller {

    public function __construct() {
        parent::__construct();

        $this->load->library('user');

        if ($this->session->userdata('isLogged') == TRUE) {

            return true;

        } else {

            redirect('/');

        }
    }

    public function index() {
        $this->getList();
    }

    public function edit() {

        $this->load->library('form_validation');

        $this->load->model('users/model_user');

        $this->form_validation->set_rules('name', 'Name');
        $this->form_validation->set_rules('username', 'Username');

        if ($this->form_validation->run() == TRUE) {

            redirect('users');

        } else {

            $this->getForm();   
        }

    }

    function getForm() {
        $data['title'] = "Users";

        $data['base'] = config_item('HTTP_SERVER');

        $data['isLogged'] = $this->user->isLogged();

        $this->load->model('users/model_user');

        $data['users'] = $this->model_user->getAll();

        $data['header'] = $this->load->view('template/common/header', $data, TRUE);
        $data['footer'] = $this->load->view('template/common/footer', NULL, TRUE);

        return $this->load->view('template/users/users_form', $data);
    }

    function getList() {
        $data['title'] = "Users";

        $data['base'] = config_item('HTTP_SERVER');

        $data['isLogged'] = $this->user->isLogged();

        $this->load->model('users/model_user');

        $data['text_enabled'] = "Enabled";
        $data['text_disabled'] = "Disabled";

        $data['users'] = $this->model_user->getAll();

        $data['header'] = $this->load->view('template/common/header', $data, TRUE);
        $data['footer'] = $this->load->view('template/common/footer', NULL, TRUE);

        return $this->load->view('template/users/users_list', $data);
    }

}

2 个答案:

答案 0 :(得分:0)

您可能错过了在网址

中使用 index.php

(OR)

使用以下代码 base_url(&#39;&#39;);

<?php 
$url=base_url('users/edit/'. $user->user_id);
echo anchor($url, '<div class="btn btn-primary"><i class="fa fa-edit"></i> Edit</div>');?>

答案 1 :(得分:0)

我现在可以查看有关路线$route['users/edit/(:num)'] = "users/users/edit/$1";

的页面
相关问题