Php 如何在codeignaitor中将用户名放入配置文件的链接中

Php 如何在codeignaitor中将用户名放入配置文件的链接中,php,codeigniter,Php,Codeigniter,我有一个控制器可以打开用户行的配置文件:- public function index() { if(!isset($_SESSION['user_id']) || empty($_SESSION['user_id'])){ redirect('./home'); } else {$user = new User($_SESSION['user_id']);} $user = new User($_SES

我有一个控制器可以打开用户行的配置文件:-

public function index() {
        if(!isset($_SESSION['user_id']) || empty($_SESSION['user_id'])){
            redirect('./home');
        }
        else {$user = new User($_SESSION['user_id']);}


        $user = new User($_SESSION['user_id']);

        if($this->input->post()){


            $user->username = $this->input->post('name');
            $user->address = $this->input->post('address');
            $user->phone = $this->input->post('phone');
            $user->skype = $this->input->post('skype');
            $user->facebook = $this->input->post('facebook');
            $user->mobile = $this->input->post('mobile');
            $user->tall = $this->input->post('tall');
            $user->fullname = $this->input->post('fullname');
            $user->wieght = $this->input->post('wieght');
            $user->fittnes = $this->input->post('fittnes');
            $user->fat = $this->input->post('fat');
            $user->email = $this->input->post('email');
            $user->birthdate = $this->input->post('birthdate');
            $user->gender = $this->input->post('gender');
            if(strlen($_FILES['pic']['name']) > 0){
                $config['upload_path'] = './uploads/';
                $config['allowed_types'] = 'gif|jpg|png';
                $config['max_size'] = '2048';
                $config['encrypt_name'] = true;
                $this->load->library('upload', $config);
                if (!$this->upload->do_upload('pic'))
                {
                    $error = $this->upload->display_errors();
                    if(is_array($error)){
                        foreach($error as $er){
                            $this->errors[] =$er;
                        }
                    }else{
                         $this->errors[] =$error;
                    }
                }
                else
                {
                    $updata =$this->upload->data();
                    $imagePath = './uploads/'.$user->pic;
                    if(file_exists($imagePath)){
                         @unlink($imagePath);
                    }
                    $user->pic = $updata['raw_name'].$updata['file_ext'];
                }
        }
此控制器扩展了MY_控制器,MY_控制器代码为:-

class MY_Controller extends CI_Controller {

    var $data;



    function __construct() {
        parent::__construct();
        session_start();
        $this->defualt_template();

        $options = new Option();
        $options->get();
        $oppArray = array();
        foreach($options as $opt){
            $oppArray[$opt->name]= $opt->value;
        }
        $this->data['options'] = $oppArray;
        if(isset($_SESSION['user_id']) && $_SESSION['user_id'] > 0){
            setcookie("logged", 1, time()+86400);
        }else{
            setcookie("logged", 0, time()+86400);
        }
    }



    function defualt_template() {
        $this->template->append_metadata('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
        $this->template->append_metadata('<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />');
        $this->template->append_metadata('<link href="js/themes/default/default.css" rel="stylesheet" type="text/css" media="screen" />');
        $this->template->append_metadata('<script type="text/javascript" src="js/jquery-1.7.min.js"></script>');
        $this->template->append_metadata('<script type="text/javascript" src="js/sortable.js"></script>');
        $this->template->append_metadata('<script type="text/javascript" src="js/jquery.nivo.slider.pack.js"></script>');
        $this->template->append_metadata('<script type="text/javascript" src="js/jquery.vibrate.js"></script>');
        $this->template->append_metadata('<script type="text/javascript" src="js/jquery.cookie.js"></script>');
        $this->template->append_metadata('<script type="text/javascript" src="js/jquery.tipsy.js"></script>');
        $this->template->append_metadata('<script type="text/javascript" src="js/admin/ajaxupload.3.5.js"></script>');
        $this->template->append_metadata('<script type="text/javascript" src="js/script.js"></script>');


        $this->layout();
    }

    function layout() {
        $this->template->set_layout('default');
        $this->template->set_partial('menu', 'partials/menu');
        $this->template->set_partial('header', 'partials/header');
        $this->template->set_partial('main_header', 'partials/main_header');
        $this->template->set_partial('right', 'partials/right');
        $this->template->set_partial('rightAccount', 'partials/rightAccount');
        $this->template->set_partial('leftAccount', 'partials/leftAccount');
        $this->template->set_partial('main_left', 'partials/main_left');
        $this->template->set_partial('left', 'partials/left');
        $this->template->set_partial('footer', 'partials/footer');
        $this->template->set_partial('main_footer', 'partials/main_footer');
    }

}


class MY_Admin extends CI_Controller {

    public $title = "";
    public $model = "";
    public $objects;
    public $cols = array();
    public $form_cols = array();

    var $page_url ;
    function __construct() {


        parent::__construct();
          session_start();
        $this->page_url = base_url()."administrator/".$this->uri->segment(2);
        $this->default_template();

        if(empty($_SESSION['userID'])){
            $this->session->set_flashdata('redirect_url', current_url());
            redirect('./administrator/login');
            exit();
        }
    }

    function default_template() {
        $this->template->append_metadata('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');

        $this->template->append_metadata('<link href="css/colorbox.css" rel="stylesheet" type="text/css" media="screen" />');
        $this->template->append_metadata('<link href="css/jquery-ui.css" rel="stylesheet" type="text/css" media="screen" />');
        $this->template->append_metadata('<link href="css/icon-library.css" rel="stylesheet" type="text/css" media="screen" />');
        $this->template->append_metadata('<link href="css/paginate.css" rel="stylesheet" type="text/css" media="screen" />');
        $this->template->append_metadata('<link href="css/admin.css" rel="stylesheet" type="text/css" media="screen" />');

        $this->template->append_metadata('<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>');
        $this->template->append_metadata('<script type="text/javascript" src="js/jquery.ui.min.js"></script>');
        $this->template->append_metadata('<script type="text/javascript" src="js/jquery.visualize.js"></script>');
        $this->template->append_metadata('<script type="text/javascript" src="js/jquery.visualize.tooltip.js"></script>');

        $this->template->append_metadata('<script type="text/javascript" src="js/jquery.ui.selectmenu.js"></script>');
        $this->template->append_metadata('<script type="text/javascript" src="js/jquery.datatables.min.js"></script>');
        $this->template->append_metadata('<script type="text/javascript" src="js/jquery.potato.menu.min.js"></script>');
        $this->template->append_metadata('<script type="text/javascript" src="js/jquery.masonry.min.js"></script>');
        $this->template->append_metadata('<script type="text/javascript" src="js/jquery.lightbox.min.js"></script>');

        $this->template->append_metadata('<script type="text/javascript" src="js/jquery.ui.totop.js"></script>');

        $this->template->append_metadata('<script type="text/javascript" src="js/colorbox/jquery.colorbox-min.js"></script>');
        $this->template->append_metadata('<script type="text/javascript" src="js/admin/jquery.ba-outside-events.js"></script>');
        $this->template->append_metadata('<script type="text/javascript" src="js/admin/ajaxupload.3.5.js"></script>');

        $this->template->append_metadata('<script type="text/javascript" src="js/admin/script.js"></script>');
        $this->layout();
    }

    function layout() {
        $this->template->set_layout('adminlayout');
        $this->template->set_partial('afooter', 'admin/adminfooter');
        $this->template->set_partial('aheader', 'admin/adminheader');
    }

    public function get_object($page, $per_page) {
        $this->objects = new $this->model();
        $this->objects->get_paged($page, $per_page);
    }

    public function view() {
        $uri = $this->uri->uri_to_assoc(4);

        $page = 1;
        $per_page = 10;
        extract($uri);

        $this->get_object($page, $per_page);

        /// urls ///
        $admin_url = site_url('admin');
        $current_url = $admin_url . $this->uri->slash_segment(2, 'both');

        /// paged ///
        $uri['page'] = 1;
        $this->objects->paged->first_url = $current_url . 'view/' . $this->uri->assoc_to_uri($uri);
        $uri['page'] = $this->objects->paged->previous_page;
        $this->objects->paged->previous_url = $current_url . 'view/' . $this->uri->assoc_to_uri($uri);
        $uri['page'] = $this->objects->paged->next_page;
        $this->objects->paged->next_url = $current_url . 'view/' . $this->uri->assoc_to_uri($uri);
        $uri['page'] = $this->objects->paged->total_pages;
        $this->objects->paged->last_url = $current_url . 'view/' . $this->uri->assoc_to_uri($uri);


        //$this->template->set_partial('footer','head');


        $this->template->build('admin/list', array(
            'objects' => $this->objects->all,
            'paged' => $this->objects->paged,
            'admin_url' => $admin_url,
            'current_url' => $current_url,
            'cols' => $this->cols
        ));
    }

    public function form($id = 0) {
        $this->objects = new $this->model($id);

        $form = $this->objects->render_form(
                        $this->form_cols
                        , 'admin' . $this->uri->slash_segment(2, 'both') . 'add/' . $this->objects->id
        );

        $this->template->build('admin/form', array('form' => $form));
    }

    function add($id = 0) {


        $this->objects = new $this->model($id);

        foreach ($this->file_cols() as $file) {
            $data = $this->do_upload($file);
            $_POST[$file] = $data['upload_data']['file_name'];
        }

        $save = $this->objects->from_array($_POST, $this->add_cols(), TRUE);

        if (!$save) {
            echo $c->error->string;
        }
        else
            redirect('admin' . $this->uri->slash_segment(2, 'both') . 'view/');
    }

    function do_upload($field) {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '1000';
        $config['max_width'] = '1024';
        $config['max_height'] = '768';

        $this->load->library('upload', $config);

        if (!$this->upload->do_upload($field)) {
            $error = array('error' => $this->upload->display_errors());

            return $error;
        } else {
            $data = array('upload_data' => $this->upload->data());

            return $data;
        }
    }

    function delete($id) {
        $this->objects = new $this->model($id);

        if (!$this->objects->delete()) {
            echo $c->error->string;
        }
        else
            redirect('admin' . $this->uri->slash_segment(2, 'both') . 'view/');
    }

    function add_cols() {
        $cols = array();
        foreach ($this->form_cols as $key => $value) {
            if (is_int($key))
                $cols[] = $value;
            else
                $cols[] = $key;
        }
        return $cols;
    }

    /*
      public $form_cols = array(
      0 => 'id',
      1 => 'post',
      'attach' => array('type' => 'file'),
      3 => 'body'
      );


     */

    function file_cols() {
        $cols = array();

        foreach ($this->form_cols as $key => $value) {
            if (isset($this->form_cols[$key]['type'])) {
                if ($this->form_cols[$key]['type'] == 'file')
                    $cols[] = $key;
            }
        }
        return $cols;
    }

}
类MY_控制器扩展CI_控制器{
var$数据;
函数_u构造(){
父项::_构造();
会话_start();
$this->default_模板();
$options=新选项();
$options->get();
$oppArray=array();
foreach($options作为$opt){
$oppArray[$opt->name]=$opt->value;
}
$this->data['options']=$opprarray;
如果(isset($\u会话['user\u id'])和&$\u会话['user\u id']>0){
setcookie(“已记录”,1,time()+86400);
}否则{
setcookie(“已记录”,0,time()+86400);
}
}
函数defualt_模板(){
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->layout();
}
功能布局(){
$this->template->set_布局('default');
$this->template->set_partial('menu','partials/menu');
$this->template->set_partial('header','partials/header');
$this->template->set_partial('main_header','partials/main_header');
$this->template->set_partial('right'、'partials/right');
$this->template->set_partial('righaccount','partials/righaccount');
$this->template->set_partial('leftAccount','partials/leftAccount');
$this->template->set_partial('main_left','partials/main_left');
$this->template->set_partial('left','partials/left');
$this->template->set_partial('footer','partials/footer');
$this->template->set_partial('main_footer','partials/main_footer');
}
}
类MY_Admin扩展CI_控制器{
公开$title=“”;
公共$model=“”;
公共物品;
public$cols=array();
public$form_cols=array();
var$page\u url;
函数_u构造(){
父项::_构造();
会话_start();
$this->page\u url=base\u url().“administrator/”$this->uri->segment(2);
$this->default_template();
if(空($\u会话['userID'])){
$this->session->set_flashdata('redirect_url',current_url());
重定向(“/管理员/登录”);
退出();
}
}
函数默认值_模板(){
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->template->append_元数据(“”);
$this->layout();
}
功能布局(){
$this->template->set_布局('adminlayout');
$this->template->set_partial('afooter','admin/adminfooter');
$this->template->set_partial('aheader','admin/adminheader');
}
公共函数get_对象($page,$per_page){
$this->objects=new$this->model();
$this->objects->get_paged($page,$per_page);
}
公共功能视图(){
$uri=$this->uri->uri\u to\u assoc(4);
$page=1;
每页$10;
摘录($uri);
$this->get_对象($page,$per_page);
///网址///
$admin_url=站点_url('admin');
$current_url=$admin_url.$this->uri->slash_段(2,'both');
///寻呼///
$uri['page']=1;
$this->objects->paged->first\u url=$current\u url.'view/'。$this->uri->assoc\u to\u uri($uri);
$uri['page']=$this->objects->paged->previous\u页面;
$this->objects->paged->previous\u url=$current\u url.'view/'。$this->uri->assoc\u to\u uri($uri);
$uri['page']=$this->objects->paged->next_page;
$this->objects->paged->next_url=$current_url.'view/'。$this->uri->assoc_to_uri($uri);
$uri['page']=$this->objects->paged->total_pages;
$this->objects->paged->last\u url=$current\u url.'view/'。$this->uri->assoc\u to\u uri($uri);
//$this->template->set_partial('footer','head');
$this->template->build('admin/list',数组(
“对象”=>$this->objects->all,
“paged”=>this->objects->paged,
“admin\u url”=>$admin\u url,
“当前url”=>$current\u url,
'cols'=>this->cols
));
}
公共函数表单($id=0){
$this->objects=new$this->model($id);
$form=$this->objects->render\u form(
$this->form\u cols
,'admin'.$this->uri->slash_段(2,'both').'add/。$this->objects->id
);
$this->template->build('admin/form',array('form'=>$form));
}
函数添加($id=0){
$this->objects=new$this->model($id);
foreach($this->file\u cols()作为$file){
$data=$this->do_upload($file);
$\u POST[$file]=$data['upload\u data']['file\u name'];
}
<a href="./myaccount/" >My Account</a>