User_agent in my_config.php? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: User_agent in my_config.php? (/showthread.php?tid=41521) |
User_agent in my_config.php? - El Forum - 05-10-2011 [eluser]ThatAirplaneGuy[/eluser] I would like to be able to detect the user's platform via user_agent library during config load. Depending on what platform the user is running, I will set an 'ENV_TYPE' config variable that I will access throughout the application to create different views, menus, functionality, etc. I know I can do the user_agent detection in the default controller, but if I link to a separate controller and bypass the default controller, I would bypass the platform detection and would need the platform detection in every one of my controllers. I would rather have it done at the core application level, and let the config variable be accessible by all controllers afterwards. I have the user_agent library in autoload, but I can't access the library in config.php. Am I missing an easy fix? Any ideas? Thanks ahead of time... CJ User_agent in my_config.php? - El Forum - 05-10-2011 [eluser]ThatAirplaneGuy[/eluser] Well, I found a work-around. Hard-code in config.php: Code: if(!$config['IS_DEV']){ In my mind, it isn't ideal to hard-code a 'require' statement in the config file, so if anyone has a better way to get the same result, I'm open to suggestions. CJ User_agent in my_config.php? - El Forum - 05-10-2011 [eluser]InsiteFX[/eluser] Code: $ua = $_SERVER['HTTP_USER_AGENT']; InsiteFX User_agent in my_config.php? - El Forum - 05-10-2011 [eluser]ThatAirplaneGuy[/eluser] [quote author="InsiteFX" date="1305072776"] Code: $ua = $_SERVER['HTTP_USER_AGENT']; InsiteFX[/quote] Thanks for the reply. I was hoping to find a way to do it using only CI functions. As it turns out, I decided to go a different direction, so I'm not even going to need this at all now... Thanks, CJ User_agent in my_config.php? - El Forum - 05-10-2011 [eluser]Nick_MyShuitings[/eluser] Just a question... but why would you have a preference for using only CI functions over plain PHP (when the answer is the difference between loading an entire new class and using a PHP function). secondly, for sake of future readers of the forum, any details in your final solution are welcomed... if nothing else to give closure to the thread. User_agent in my_config.php? - El Forum - 05-11-2011 [eluser]ThatAirplaneGuy[/eluser] [quote author="Nick_MyShuitings" date="1305109635"]Just a question... but why would you have a preference for using only CI functions over plain PHP (when the answer is the difference between loading an entire new class and using a PHP function). secondly, for sake of future readers of the forum, any details in your final solution are welcomed... if nothing else to give closure to the thread.[/quote] No real reason for not mixing PHP with CI. If nothing else - just to keep the same look of the rest of the code. Once I get this project off the ground, I will be working with folks that have never used CI before and are barely experienced with PHP. Anything I can do to keep it all it one 'realm' - all PHP 'core' code or all CI code - would make it easier to get them up to speed. It prevents having to explain "No, that is not a CI function, it is a PHP function. No that is not a PHP function, it is a CI function." etc. etc. There is no functional reason for preferring not to mix the code. My end solution for the project was to split my application out into two separate projects. I was trying to build a 'mobile' version of the application - complete with separate templates, etc. - in the same classes as a PC version of the application. I eventually decided that any 'pros' of having one set of code were far outweighed by not having jumbled mixed-environment code (again, going back to simplicity for the other people that will be working on the project). It also turned out that there wasn't a lot of overlap of functionality between the mobile vs. pc based versions. Is it possible to do a mixed-environment project with CI? Definitely. It just wasn't the best scenario for my project this time. |