Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7561725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:13:50+00:00 2026-05-30T13:13:50+00:00

I am developing a stats site in Codeigniter locally. I have a url like

  • 0

I am developing a stats site in Codeigniter locally. I have a url like localhost/sitename/player/show_profile/PlayerName

I currently have the following:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Player extends CI_Controller
{

  public function __construct()
  {
    parent::__construct();
    $this->load->model('player_model');
    $player_name = $this->uri->segment(3);
  }


  public function index()
  {
        echo "index";
  }

  public function show_profile($player_name)

  {

        $data['player_stats'] = $this->player_model->get_stats( $player_name );
        $this->load->view('player/player_stats', $data);
  }

}

?>

This works, but my question is regarding the $player_name variable. I have $player_name = $this->uri->segment(3); in the __construct so it’s available to all of the class methods. Is this the way I should be doing it?

Is this safe?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:13:52+00:00Added an answer on May 30, 2026 at 1:13 pm

    Fist of all, there is no point in assigning the variable in the constructor because it’s going to get overwritten. When you pass CI a url like localhost/sitename/player/show_profile/PlayerName, anything passed the method (i.e. PlayerName) get’s set as the parameters. Therefore, your variable in

    public function show_profile($player_name){
    

    is already set when you get to your method code.

    Secondly, I agree with Peter’s:

    protected $player_name;
    

    for making it globally accessible in the controller. BUT, I don’t agree with setting it in the constructor. If you have another method in this controller that passes a variable in that spot, you’re going to get the wrong data in there. Set it in the method you called:

    public function show_profile($player_name){
    
        $this->player_name = $player_name;
    
        $data['player_stats'] = $this->player_model->get_stats( $player_name );
        $this->load->view('player/player_stats', $data);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am developing a site which demo URL is http://www.abc.com now my client wants
I have a query. I am developing a site that has a search engine.
I'm trying to integrate Facebook into a site I'm developing, I have created a
I am currently developing 2 sites that have identical functionality for a single client,
I'm developing a typical dating site like male/female seeks male/female between ages x and
Developing a project of mine I realize I have a need for some level
I'm developing an ASP.NET site off of my Windows XP IIS Installation, and whenever
i m developing site in Joomla, meanwhile i stuck in a problem,please help me
I'm developing a site which has a flash background playing a small video loop
I am developing a site similar to a portal with loads of individual portlets.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.