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 7692989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:58:50+00:00 2026-05-31T20:58:50+00:00

I want to pass a language id for each link i click from my

  • 0

I want to pass a language id for each link i click from my view to controller.
My view code is

  <?php foreach ($languages as $lang) { ?>
     <li>
       <a href="<?php echo base_url(); ?>home/box/<?php echo $template_data['box_id']?>/<?php echo $lang['language_name']?>"></a>
     </li>
   <?php } ?> 

My controller is

public function box($box_id=null, $language_name=null, $language_id=null) {
   /// my function code
        echo $box_id;
        echo $language_name;
        echo $language_id;
   $data['languages'] = $this->Home_model->getLanguages($box_id);
  }

The languages array contain the language id and language name

i want the name to be in url but not the id

The url looks like this

http://localhost/mediabox/home/box/12/en

if i send the language id in url it is then visible otherwise it is not visible in the controller.
How can I get language id for each link in controller without sending it in url

Thanks

  • 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-31T20:58:51+00:00Added an answer on May 31, 2026 at 8:58 pm

    pass the language name in the url without the ID, compare to languag_name column in table.

    Lets assume you have url: http://localhost/mediabox/home/box/en

    controller

    <?php
    # I wont write a controller but you should know how to do that, im also writing code as if you are just focusing on getting language.
    public function box( /**pass in your other uri params as needed **/ $lang_name = 'en'){
      #you could load this in the constructor so you dont have to load it each time, or in autoload.php if your using it site wide.
      $this->load->model('lang_model', 'langModel');
    
      #this example shows loading the library and running the function
      $this->load->library('lang_library');
      $this->lang_library->_getLang($lang);
    
      #this example shows putting the getLang function inside the controller itsself.
      self::_getLang($lang);
    }
    

    library/private function

    <?php
    private functon _getLang($lang = 'en'){
      #run the query to retrieve the lang based on the lang_name, returns object of lang incl id
      $lang = $this->langModel->getLang($lang_name);
      if (!$lang){
        die('language not found');
      }else{
        return $lang;
      }
    

    lang model

    <?php
    public function getLang($lang_name = 'en'){
      $this->db->where('lang_name', $lang_name);
      $this->db->limit(1);
      $q = $this->db->get('languages');
    
      if ($q->mysql_num_rows > 0){
        return $q->result();
      }else{
        return false;
      }
    }
    

    you will then have a variable with object associated to it then you can simply call $lang->lang_name; or $lang->lang_id;

    Session storage

    <?php
    #you could call this in the beginning after using an ajax `$.post();` to retrieve the ID.. the easiest route though is whats above. I use this in my REST APIs
    $this->session->set_userdata('lang', $lang);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass parameters from PHP Command Line Interface, and then read in
I want to pass callback from my python code to c++ I want my
My data is just number, I want pass it from VC1 to VC2 for
I want to pass a string that contains few words to jQuery when click
I want pass a class-instace to a method of an other and be sure
I want to pass an ImageIcon instance by value as we know that by
I want to pass '#' to the query string like ?page.aspx?someParam=1234#5 .
I want to pass an uninitialized object pointer to some method. Within that method
I want to pass these parameters with a HTTP request to a WebApp hosted
I want to pass some arguments to the my Javascript template in Rails3 application

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.