尽管传递了参数,但CodeIngiter缺少参数

时间:2017-07-28 10:02:03

标签: php codeigniter codeigniter-3

我一直收到错误

Missing argument 1 for AdminPanel::viewUser()

问题是网址本身大致如下:

domain.com/AdminPanel/viewUser/1

然而,出于某种原因,值不会传递给控制器​​,尽管在控制器中它被定义为

public function viewUser($id)

如果我为ID设置了默认值,它将只使用默认值,而不是通过网址传递的值

4 个答案:

答案 0 :(得分:2)

发现错误。我一直在使用

  function _remap($method_name = 'index')
  {
    if(!method_exists($this, $method_name)){
         $this->index();
    }
    else{
         $this->{$method_name}();
    }
  }

如果用户尝试调用不存在的方法,则将用户重定向到某个页面。删除了这个,它现在有效。

答案 1 :(得分:0)

如果要从控制器中的URL访问该值。你需要在Routes.php上提一下一行,见下文:

$route['Admin/viewUser/(:num)'] = 'Admin/viewUser/$1';

它将自动获取方法$ id params

中的传递值

答案 2 :(得分:0)

清洁和简单,它期望它,在功能上需要变量,由于某些或其他原因,如果它没有通过

总是尝试这样做。

private static string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);

public async void CheckForCachedToken(PromptBehavior propmptBehavior)
    {
        //
        // As the application starts, try to get an access token without prompting the user.  If one exists, populate the To Do list.  If not, continue.
        //
        AuthenticationResult result = null;
        try
        {
            result = await authContext.AcquireTokenAsync(resourceUrl, applicationId, redirectUri, new PlatformParameters(propmptBehavior));
            TokenTextBox.Text = result.AccessToken;
            // A valid token is in the cache - get the To Do list.
            GetTokenButton.Content = "Clear Cache";
        }
        catch (AdalException ex)
        {
            if (ex.ErrorCode == "user_interaction_required")
            {
                // There are no tokens in the cache.  Proceed without calling the To Do list service.
            }
            else
            {
                // An unexpected error occurred.
                string message = ex.Message;
                if (ex.InnerException != null)
                {
                    message += "Inner Exception : " + ex.InnerException.Message;
                }
                MessageBox.Show(message);
            }
            return;
        }
    }

答案 3 :(得分:-2)

您不需要将其作为参数传递,请将其用作uri细分。它将如下声明和分配: -

$this->uri->segment(3, '0');

现在从功能中删除$id

相关问题