Codeigniter视图未加载

时间:2013-01-27 12:00:28

标签: php codeigniter hybridauth ion-auth

我安装了Codeigniter,IonAuth + Hybridauth,我正在重新编写,因此我的用户可以选择自己的用户名,而不是使用facebook返回的名字和姓氏来生成用户名。

所以在下面的代码中我检查是否发布了用户名,如果不是我想加载choose_username视图但由于某种原因视图没有加载并且它完全跳过该部分这就是为什么我已添加die('Why no view')

更新:第一段代码在新控制器中正常运行

在此处查看代码:

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?');
                            };

更长的版本:

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?');
                            };

因此,当我运行上面的代码时,我得到的是一个空白页面:Why no view

1 个答案:

答案 0 :(得分:1)

如上所述,通常当我遇到这类问题时,它来自视图代码中的错误。

此外,我不知道在没有用户名数据的情况下,这篇文章实际上是通过了什么,但您可能还想检查用户名的空值。这可能不是问题,但最好确认最初的if是评估你期望的方式。