Why isn't this working? I'm trying to make a php user profile 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 u开发者_如何学JAVAse $userid as a variable
$this->load->view('users',$data);
}
}
}
?>
Parse error: parse error, expecting `')'' in C:\wamp\www\system\application\controllers\users.php on line 7
You probably meant to give $id
a default value of null
using the =
assignment operator, like this:
function index($id = null) {
Your posted code uses the ==
equality operator in the function declaration, which is a syntax error.
I don't think you can have the index
page take any parameters, I've tried it before (if you do that, it will be accessible at example.com/user/index/5
, but not example.com/user/5
. I would put all that code in another function called profile
. Or you can try what some suggest on this forum post:
http://codeigniter.com/forums/viewthread/94028/
Hope this helps!
精彩评论