【问题标题】:CodeIgniter user profile controllerCodeIgniter 用户配置文件控制器
【发布时间】:2010-06-24 18:31:06
【问题描述】:

为什么这不起作用?我正在尝试创建一个 php 用户配置文件 URL。

<?php
class Users extends Controller {
  function Users() {
    parent::Controller();
  }
  function index($id == null) {
    if($id == null) {      
      redirect('/', 'refresh');      
    }
    else {
      $data['title']  = 'User Page';
      $data['result'] = $this->users_model->get_all_data();
      $data['userid'] = $id; // in the view, you can use $userid as a variable
      $this->load->view('users',$data);
    }
  }
}
?>

解析错误:解析错误,在第 7 行的 C:\wamp\www\system\application\controllers\users.php 中需要 `')''

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    您可能打算使用= 赋值运算符为$id 赋予默认值null,如下所示:

    function index($id = null) {
    

    您发布的代码在函数声明中使用了== 相等运算符,这是一个语法错误。

    【讨论】:

      【解决方案2】:

      我不认为你可以让index 页面接受任何参数,我之前尝试过(如果你这样做,它将可以通过example.com/user/index/5 访问,但不能通过example.com/user/5 访问。我会说所有这些代码都在另一个名为 profile 的函数中。或者你可以试试这个论坛帖子中的一些建议:

      http://codeigniter.com/forums/viewthread/94028/

      希望这会有所帮助!

      【讨论】:

        猜你喜欢
        • 2014-01-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多