![]() |
CodeIgniter helpful hints - 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: CodeIgniter helpful hints (/showthread.php?tid=5909) |
CodeIgniter helpful hints - El Forum - 02-09-2008 [eluser]tonanbarbarian[/eluser] just to add to lones comments if you need to add a "global" variable at run time then use Code: $this->config->set_item('variable', $value); Just be aware that this does not save the value in any config files for later use CodeIgniter helpful hints - El Forum - 02-12-2008 [eluser]xwero[/eluser] some hints : - When you have to use an input value multiple times put it in a variable it saves typing and you only have to make one call to the input->post method. - Put form validation and other form related actions in a separate library. It keeps your controller cleaner and you see patterns sooner Code: // controller CodeIgniter helpful hints - El Forum - 02-12-2008 [eluser]frenzal[/eluser] I can't take credit for this as I found it on the forum myself once, however it's very handy and I use it for all my projects for setting the base url: $root = "http://".$_SERVER['HTTP_HOST']; $root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']); $config['base_url'] = $root; CodeIgniter helpful hints - El Forum - 02-12-2008 [eluser]Firestorm ZERO[/eluser] I totally agree with Point 1. The first thing I do is put the application directory separate from the system directory. Really this should be the default IMO. CodeIgniter helpful hints - El Forum - 02-12-2008 [eluser]Isern Palaus[/eluser] Hello, I ever put the directory application out of the system, and the system out of the public_html. My structure is like this: /domain_tld/application /domain_tld/system /domain_tld/public_html Regards, -- Isern Palaus CodeIgniter helpful hints - El Forum - 02-12-2008 [eluser]Lone[/eluser] Yet Another Hint - Easy Array/Variable Output From the previous CMS we built we had the following function to help us with out with viewing what is in an array or variable. It's not the prettiest looking output but saves a heap of time when developing. We added it to CodeIgniter by making it a helper called 'debug_helper.php' and just autoload it. Example Code: $people = array('John','Mary','Alberto'); Helper Code Code: function p($var) CodeIgniter helpful hints - El Forum - 02-14-2008 [eluser]xwero[/eluser] more hints : - Use config files for most of your configurable libraries. Then values only have to be changed in one place. config upload.php image_lib.php - When you extend a controller or a model use include to import the baseclass in the children classes Code: // basecontroller.php CodeIgniter helpful hints - El Forum - 02-14-2008 [eluser]Référencement Google[/eluser] [quote author="xwero" date="1203003692"] - When you extend a controller or a model use include to import the baseclass in the children classes Code: // basecontroller.php You won't have to use include if you use a MY_Controller.php in your library folder as Basecontroller. So one hint would be to use: Code: // In application/library/MY_Controller.php Then yourfunction() will be avaible sitewide in every other controllers that extends the MY_Controller (without having to include them) for example using: Code: $this->yourfunction(); CodeIgniter helpful hints - El Forum - 02-14-2008 [eluser]xwero[/eluser] elitemedia that is an extra tip ![]() I've seen snippets on the forum where people do this Code: class MY_Controller extends Controller { You also can't extend a child class of a class that is defined in the my_controller file. Most people won't need to do this but if you have to do it it's best to have a consistent method of extending classes. CodeIgniter helpful hints - El Forum - 02-14-2008 [eluser]codex[/eluser] [quote author="Lone" date="1202892803"]Yet Another Hint - Easy Array/Variable Output From the previous CMS we built we had the following function to help us with out with viewing what is in an array or variable. It's not the prettiest looking output but saves a heap of time when developing. We added it to CodeIgniter by making it a helper called 'debug_helper.php' and just autoload it. Example Code: $people = array('John','Mary','Alberto'); Helper Code Code: function p($var) Actually that's not a bad idea at all. I'm going to copy this. Thanks! ;-) |