Snippets > CodeIgniter Transform


#codeigniter#php

Transform from one user to another in CodeIgniter.

namespace App\Controllers;

class Transform extends BaseController
{
	private $user_model;
	
	public function __construct()
	{
		$this->user_model = model('App\Models\UserModel');
	}
	
    public function index()
    {
        $users = $this->user_model->where('active', 'y')->findAll();

        return view('/transform', $users);
    }

    public function user()
    {
        $id = $this->request->uri->getSegment(3);

        if($id) {
			
            if(!session()->get('original_user_id')) session()->set('original_user_id', session()->get('user_id'));
			
        } else {
			
            $id = session()->get('original_userID');
			
        }

        $user = $this->user_model->where('id', $id)->first();
        session()->set(['user_id' => $user->id]);
		
        return redirect()->to('/transform');
    }
}