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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:14:55+00:00 2026-06-10T19:14:55+00:00

I am trying to create a function that changes the locale of a site

  • 0

I am trying to create a function that changes the locale of a site based on the domain extension but when I try and set the value of a Variable in AppModel as a function I get an error. I am not sure what I am doing wrong.

FYI: $_SERVER[‘HTTP_HOST’] = ‘.de’;

class AppModel extends Model {

//var $locale = 'de_de'; // Example of what I need

var $locale = $this->getLocale();

    function getLocale() {

        $domain = explode('.', $_SERVER['HTTP_HOST']); 

        if ($domain[1] == 'de') {

            return 'de_de';

        } else {

        return 'en_gb';

        }

    }

}

Error Returned:

Parse error: syntax error, unexpected T_VARIABLE in /var/www/devsite/v1/site/app/app_model.php on line 7 Call Stack: 0.0002 671648 1. {main}() 
/var/www/devsite/v1/site/app/webroot/index.php:0 0.0255 5883776 2. Dispatcher->dispatch() /var/www/devsite/v1/site/app/webroot/index.php:83 0.0264 5949592 3. 
Dispatcher->__getController() /var/www/devsite/v1/site/cake/dispatcher.php:116 0.0264 5949672 4. Dispatcher->__loadController() 
/var/www/devsite/v1/site/cake/dispatcher.php:385 0.0265 5951760 5. App->import() /var/www/devsite/v1/site/cake/dispatcher.php:413 0.0265 5953552 6. 
App->__settings() /var/www/devsite/v1/site/cake/libs/configure.php:916 0.0265 5954000 7. App->import() 
/var/www/devsite/v1/site/cake/libs/configure.php:1171 0.0265 5957624 8. App->__find() /var/www/devsite/v1/site/cake/libs/configure.php:955 0.0268 5984264 9. 
App->__load() /var/www/devsite/v1/site/cake/libs/configure.php:1019 0.0269 6047416 10. require('/var/www/devsite/v1/site/app/app_controller.php') 
/var/www/devsite/v1/site/cake/libs/configure.php:1060 0.0269 6047560 11. App->import() /var/www/devsite/v1/site/app/app_controller.php:8 0.0270 6051456 12. 
App->__find() /var/www/devsite/v1/site/cake/libs/configure.php:955 0.0270 6052240 13. App->__load() /var/www/devsite/v1/site/cake/libs/configure.php:1036 
0.0272 6164128 14. require('/var/www/devsite/v1/site/cake/libs/sanitize.php') /var/www/devsite/v1/site/cake/libs/configure.php:1060 0.0272 6164416 15. 
App->import() /var/www/devsite/v1/site/cake/libs/sanitize.php:2 0.0273 6165128 16. App->__settings() /var/www/devsite/v1/site/cake/libs/configure.php:916 0.0337 8579264 17. 
App->import() /var/www/devsite/v1/site/cake/libs/configure.php:1149 0.0337 8582864 18. App->__find() /var/www/devsite/v1/site/cake/libs/configure.php:955 0.0338 8583952 19. 
App->__load() /var/www/devsite/v1/site/cake/libs/configure.php:1019

Thanks in advance.

  • 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-06-10T19:14:56+00:00Added an answer on June 10, 2026 at 7:14 pm

    the error message says it pretty clearly: invalid php

    you still have to code valid PHP (even if it is cakePHP)! using a proper IDE will outline the error right away:

    var $uses ('App');
    

    should be

    public $uses = array('App');
    

    as documented!

    if you are still on PHP4 you would need “var” instead of “public”

    you should really start reading basic php books because you seem to lack the basic stuff.
    you can also not use dynamic methods in the class declaration:

     var $locale = $this->getLocale();
    

    you need to use the constructor for this:

    public function __construct($id = false, $table = null, $ds = null) {
        parent::__construct($id, $table, $ds);
    
        $this->locale = $this->getLocale();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a function that would append two vectors together, but I
I am trying to create a function that updates another value, and initially (after
I am trying to create a simple javascript based extension for Google Chrome that
I'm trying to create a function that searches up a WebControl's parent-child relationship (basically
I am trying to create a function that will block access to some of
I'm trying to create a function that would dynamically allocate an array, sets the
I am trying to create a function that given a divid, and a list
I'm trying to create a function that will simply allow me to pass an
I am trying to create a function that sends 100 call per second, and
I’m trying to learn Haskell and I was trying to create a function that

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.