0

I have an installation of Codeigniter, IonAuth + Hybridauth which I am reworking so my users can choose their own username instead of generating one using the first and last names returned by facebook.

So in my code below I check to see if a username was posted, if not I want to load the choose_username view but for some reason the view is not loading and its completely skipping that section which is why I added die('Why no view')

Update: This first piece of code runs fine in a new controller

Checkout the code here:

if(isset($_POST['username'])){
                            $username = $this->input->post('username', TRUE);   
                            die($username);
                            }else{
                                $this->data['message'] = 'Please choose a username.';
                                $this->data['template'] = 'guests/partials/choose_username';
                                $this->load->view('guests/template/standard', $this->data);
                                die('Why no view?');
                            };

Longer version:

function login_provider($provider = '')
    {
        if(empty($provider)) redirect();


    try
    {
        // create an instance for Hybridauth with the configuration file
        $this->load->library('HybridAuthLib');

        if ($this->hybridauthlib->serviceEnabled($provider))
        {
            // try to authenticate the selected $provider
            $service = $this->hybridauthlib->authenticate($provider);

            if ($service->isUserConnected())
            {
                // grab the user profile
                $user_profile = $service->getUserProfile();
                ////////////
                //var_dump($user_profile);
                //die();
                ////////////

                    $provider_uid = $user_profile->identifier;

                if($this->ion_auth->login_by_provider($provider,$provider_uid))
                {
                    $data['user_profile'] = $this->ion_auth->user_by_provider();
                    //$this->load->view('auth/user_profile',$data);
                    $user = $this->ion_auth->user()->row();


                    //Redirect to custom subdomain
                    $url = explode('://',site_url());
                    if (strpos(site_url(),$user->username) !== false) {
                    redirect($url[0].'://'.str_replace('www','',$url[1]).'dashboard','refresh');
                    }
                        else{
                        redirect($url[0].'://'.$user->username.str_replace('www','',$url[1]).'dashboard');
                        };

                }
                else
                { // if authentication does not exist and email is not in use, then we create a new user 

                //Check if username was posted

                        if(isset($_POST['username'])){
                            $username = $this->input->post('username', TRUE);   
                            die($username);
                            }else{
                                $this->data['message'] = 'Please choose a username.';
                                $this->data['template'] = 'guests/partials/choose_username';
                                $this->load->view('guests/template/standard', $this->data);
                                die('Why no view?');
                            };

So when I run the above code, all i get is a blank page with: Why no view.

Tommy Arnold
  • 3,339
  • 8
  • 31
  • 40
  • 1
    I'm not sure why, but i've found that doing die after load view doesn't load it. try to uncomment the die and if it doesn't load could be a different problem. but it won't show the view as long as the die is there. – eric.itzhak Jan 27 '13 at 12:07
  • Forget about the die(); i tried removing it and as I said in the question, the view doesnt load and the rest of the code continues to run. – Tommy Arnold Jan 27 '13 at 12:08
  • I know i just meant you'll never solve it with the die there. Sometimes i've expirienced that an error in the view might cause this. try and loading the view as a string( using an extra `true` parameter and echo it, if it's `null` then 99% u got some error throwing in the view. – eric.itzhak Jan 27 '13 at 12:10
  • You probably shouldn't use `$this->data`. Try using a variable in the method scope instead. – Repox Jan 27 '13 at 12:11
  • @Repox I tried that too, still get the same result. – Tommy Arnold Jan 27 '13 at 12:16
  • Its ok I ended up rebuilding the whole controller differently and its working fine. – Tommy Arnold Jan 27 '13 at 12:40
  • The aforementioned problem with "die" being present after, also exists with "exit". Anyone of these present inside the controller's function will block $this->load->view. – Christian Bonato May 23 '16 at 17:38

1 Answers1

1

As above, usually when I run into this sort of issue it's from a bug in the view code.

Also, I don't know what, is actually being passed by this post in the event of there not being username data but you might want to also be checking for an empty value for username. This is probably not the issue but it would be good to confirm that the initial if is evaluating the way you expect.

Freqout
  • 116
  • 4
  • Bit old, but good to update here. If an error is there in the view file and having the error reporting turned off will not load the view file, resulting an empty page. – Vaishak Dec 08 '15 at 05:18