CodeIgniter: Tips & Tricks

Hello, Today I’ll post few modifications I use on every CI project. First, on the “url_helper“, I made this modification oon base_url() function:

[cc lang=”php”]
if ( ! function_exists(‘base_url’))
{
function base_url($link=FALSE)
{
$CI =& get_instance();
$baseUrl = $CI->config->slash_item(‘base_url’);
if ($link===TRUE) $baseUrl .= $CI->config->slash_item(‘index_page’);
return $baseUrl;
}
}
[/cc]

This allow me to use the base_url() function to work with and without the index.php. Sometimes you don’t know where your project will be hosted, and if the host supports mod_rewrite. In this case, on your links (those with index.php/controller) you just put

[cc lang=”php”]

[/cc]

and you will get the index.php or not, depending on your configuration, on config.php. If I use the TRUE parameter, the “index.php” string will be inserted before the controllers. Of course, you can alter the function to something like base_url(‘link’), or base_url(1), or anything you like. I don’t like to mess with the CI Core, so I saved this new helper on application/helpers directory.

Another Tip. This is very simple. Using the form validation, when I have a not required field, it isn’t repopulated with set_value() function if you don’t set any rules for the field. But if you set a blank rule, it will work:

[cc lang=”php”]
$this->form_validation->set_rules(‘field_name’, ”, ”);
[/cc]

When I use upload class, sometimes I have to delete the file when I change the file on database. And then It’s a good thing to use the absolute path when deleting, so I made a small constant declaration to set my root folder, the folder with index.php inside. In the index.php, add this line on bottom of the constant declarations:

[cc lang=”php”]
define(‘FULLPATH’, pathinfo(__FILE__, PATHINFO_DIRNAME));
[/cc]

Now, my FULLPATH constant is set with my base directory. Hope this can be usefull to someone. 😉

Did you like this? Share it:

4,585 Comments

  • gardening express voucher code |

    Your home in addition to garden are commonly the particular two most essential areas you deal with on a day-to-day time frame.
    Associated with the two, nearly all may say it is really harder for you
    to sustain right gardening strategies and create a beautiful
    picture. It could be tougher to some, nonetheless that is only because that they are not following these kinds of simple
    words of suggestions that are discussed right here.

    Know what grows in the region. When you see the wide wide variety associated with seed bouts offered online, it is usually easy to get drew into the idea of growing everything plus
    anything! Within reality, though, simply several of them may blossom in your own personal regional setting.

    Study through to your place and what plants can easily survive.

    If you desire your garden to hit your objectives, concentrate on your soil.

    So as to protect your plants via unwanted pests, this can be essential to possess healthy soil.
    It will feed, nurture your own personal vegetation and help all of them grow into strong plant life that are
    able to fight off disorder and damage from discrepancies.

    Are you questioning in the event you need to drinking water your backyard?

    One good way to tell should be to simply walk across this.
    If you can observe your footprints, there is a thirsty yard.
    Every week, your current lawn should be receiving about one inch
    connected with liquid. If you dwell in an area wherever it doesn’t rain regularly, make sure to offer
    your lawn the particular “footprint test” whenever you’re not positive if it’s had enough to drink.

    When planting your own personal organic garden anyone must remember that some plants do not raise nicely together while other
    people carry out. Remember that some crops cannot be planted
    subsequent to every some other, thus you must prevent certain combinations.
    For example of this, brokkoli cannot be planted
    close to tomato, and so with.

    To keep your vegetation from suffering irreparable harm, be sure to check out them to get bugs
    and even various illnesses at very least once a week.
    These difficulties are much less complicated to
    handle if found instantly, in addition to monitoring these people tightly can continue them from spreading
    additional plants. Exploration ways to take care of frequent problems so that you may prepared for whatever you encounter.

    To be certain a tree isn’t going to come to be a trouble with age, think of
    what sizing it can become before anyone plant it.
    The great place for a shrub may possibly not be
    a great area for the tree several years later on. You should be
    specially careful to not plant some sort of tree
    way too closely for you to your house, as often the root base
    can cause destruction.

    A beneficial solution to get getting eliminate of some slugs in your garden is always to set out some sort of textbox of beer.
    Just have a small clear plastic mug or container (plastic margarine bowl
    works great) and even tuck it into your garden beds near typically
    the place where the slugs are recognized to appear. End up being sure the lip connected with the
    dish is degree to the ground together with then fill it having beer.

    The beer draws in the slugs into this dish where they are going to block.

    You will have for you to dispose of often the slugs and reset the particular light beer “trap” every few days and nights, but your slugs
    will disappear.

    Install a sprinkler program to water your
    own personal garden. It might be difficult for you to find the time to water your
    own personal plants each one day, specifically in the event you job outside of the residence.
    Right hydration is important to the achievements connected with your garden, so adding a simple sprinkler system can help you save time and vitality.

    To have the very best rose garden pick vegetation that will
    bloom at diverse times of the growing season. This is possible to get varieties of plants and flowers that full
    bloom via January until Late based on where you survive.
    By simply planting plants of which pinnacle at different
    moments of all four you may ensure that there is definitely always
    coloring and life in your garden.

    Build a precise schedule to be aware of when you should grow your own personal seeds.
    Even when you are growing your own personal plants indoors,
    you have to comply with a new schedule the fact that matches the growing season and outdoors heat range.
    Spend some time on the schedule at the particular beginning of a
    period and you should get able to improve that the next year.

    Start off the organic garden having a good preparing
    program. This helps you recognize wherever each plant will certainly go
    inside your garden consequently that you can increase typically the few hours a person have to garden daily.
    As part of your plan, take remarks about what plants you
    will require to replace short-lived seeds for example spinach and lettuce.

    You should continue your seeds wet devoid of drowning them throughout drinking water.
    Spray water over the earth to keep this moist,
    and place typically the pots or the trays in which you have
    your seed products in water thus that the ground can certainly absorb the water.
    Ensure you replace the water in which your pots are standing frequently.

    By adding a nice layer involving bio-degradable material (mulch) close to your plants,
    you may utilize the natural pest-fighting ability
    within just the mulch to stop predators to your plants.
    By locating a one to two half inch layer about your crops, you are in addition incorporating a good source of
    nourishment and a source associated with water.

    Occasionally when a person are growing vegetables or even fruits, it can become
    beneficial to slice off fresh formed buds or additional
    non-fruit keeping areas. This kind of will stimulate typically the growth of heavier
    berry mainly because the plant re-routes vitamins to where its development
    should be navigating. When being careful your garden, they
    have important to make the difference between harvesting the plant, or maybe encouraging its growth.

    Usage soap upon your plants. Not necessarily substantially is worse than a good bad aphid pests.
    Your own vegetation will look horrible, and eventually expire, in the
    event the bugs go on to get results on your plants.
    To get eliminate of them all now, fill a spray package with dish water
    and soap. Product thoroughly, and duplicate like
    needed.

    By staying true to the formula and finding ways to implement that into your expanding
    garden, you will be sure that will each season much more lovely than the last.
    You no longer need to be born with a new green thumb any time you can follow these kind of rules and
    simply develop one right on your own hand! http://chuganwang.com/comment/html/?192570.html

  • gardening without work |

    Your home together with garden are generally the two most
    crucial destinations you deal with about a every day foundation. Connected with the two, almost
    all will certainly say it is in fact harder for you to keep suitable gardening tactics and develop a beautiful field.
    It might be more challenging to some, nevertheless
    that is definitely only because they are not following all these
    simple words of guidance that are discussed below.

    Understand what grows in your current region. When you see the vast selection involving seed
    bouts available on the net, it is definitely easy to get taken into your
    idea of growing everything and even anything!
    Inside reality, though, merely many of them may
    increase in your own personal regional setting. Study through
    to your place and what vegetation can survive.

    If you would like your garden to be successful, concentrate
    on your soil. So that you can protect your plants by unwanted pests, this can be essential to have healthy dirt.
    It will nurture the vegetation and help these individuals grow
    into strong vegetation that can fight off disease and
    harm from discrepancies.

    Are you thinking in case you need to waters your backyard?
    One fine way to tell is always to simply walk across it.
    If you can discover your footprints, you have a parched yard.
    Every week, your own lawn should be receiving approximately one inch regarding
    normal water. If you reside in an spot exactly where it doesn’t rain usually,
    make sure to present your lawn typically the “footprint test” whenever you’re not confident if it’s had enough to drink.

    When growing and maintaining the vegetable garden a person must keep in mind that some crops do not raise nicely together while other folks do.

    Remember that some plants cannot be planted subsequent to each and every additional, thus you must avoid certain combinations.
    For example, spargelkohl cannot be planted beside tomato, and
    so about.

    To keep your plants from suffering irreparable destruction,
    be sure to verify them with regard to bugs together with various illnesses at very least once a
    good week. These issues are much less difficult to take care of if
    caught immediately, plus monitoring all of them directly can continue
    them coming from spreading some other plants.
    Homework ways to handle frequent problems so that you’ll certainly be prepared for whatever
    anyone face.

    To be positive a tree won’t turn out to be a
    challenge with get older, think of what dimensions it
    can become before an individual plant that. The ideal place
    for a sapling may not be a new great spot for some sort of tree several years
    within the future. You should be in particular careful not to ever plant
    a new tree too closely to your house, as the particular sources can cause harm.

    A valuable solution intended for getting eliminate of some slugs
    in your garden is usually to set out a good box of beer.
    Just take a small cosmetic glass or container (plastic margarine bowl works great)
    in addition to tuck it down into your current garden beds near often the region where the slugs are proven to appear.

    End up being sure the lip connected with the dish is stage to
    the ground together with then complete it together with beer.

    The particular beer draws the slugs into typically the dish where they will likely block.
    You will have to help dispose of often the slugs and reset the particular ale “trap” every partners times, but your
    slugs may disappear.

    Install a sprinkler system to water your own garden. It can be difficult to be able to find
    the time for you to water your plants every day, in particular if you do the job outside of the home.
    Proper hydration is vital to the achievement of your
    garden, so setting up a simple sprinkler program can save you time and energy.

    To have the very best bloom garden pick crops that will bloom at distinct times of the growing season.
    That is possible to find varieties of plants and flowers that bloom via January until The fall of
    based on where you are living. By planting plants
    that top at different occasions of 12 months you can easily ensure that there will be
    always coloration and living in your property.

    Establish a precise schedule to discover when you should seed your own seeds.
    Even when you are growing your current plants indoors, you have
    to abide by the schedule that will matches the summer season and outdoors temperature.
    Spend some period on the schedule at often the beginning
    of a time of year and you should become able to improve it the next year.

    Start off your own personal organic garden using a good proper system.
    This helps you find out where each plant will certainly go in the garden so that you can increase typically the
    few hours anyone have to garden every day. As part of your own personal plan, take records on what
    plants you can use to replace short-lived plants like spinach and member of
    the lettuce family.

    You should continue your seeds damp without drowning them
    inside water. Spray water more than the dirt to maintain that
    moist, make the pots or trays around which you have your seed in water thus that
    the ground can absorb the water. Be sure you replace the water throughout which the
    pots can be standing regularly.

    By incorporating a nice layer associated with bio-degradable
    material (mulch) about your plants, you could utilize the natural pest-fighting
    ability in the mulch to stop possible predators in order to your plants.
    By putting a one to two inch layer close to your crops, you are likewise putting a good source of nourishment and
    a source associated with water.

    In some cases when anyone are growing vegetables or maybe fruits,
    it can get useful to take off brand new formed buds or additional non-fruit bearing areas.
    This particular will stimulate typically the growth of heavier berries
    since the plant re-routes nourishment to where its expansion should be navigating.
    As soon as excellent your garden, is actually important to make
    often the big difference between harvesting the plant, or encouraging their growth.

    Make use of soap about your plants. Not necessarily much is worse than some sort
    of terrible aphid pests. The crops will look dreadful, and eventually perish, when the bugs go on to work on your plants.
    For you to get clear of them now, fill a twig package with
    dish soap and water. Squirt thoroughly, and repeat since needed.

    By staying accurate to the formula and finding ways to implement this into
    your developing garden, you could be sure that each season is far more beautiful than the last.

    You no longer need to be born having a new green thumb if you can comply with these kind of guidelines and
    simply increase one right on your own hand! http://www.hyprn.com/comment/html/?92601.html

  • Karissa |

    We are a group of volunteers and opening a new scheme in our community.
    Your site offered us with valuable info to work
    on. You have done an impressive job and our whole community will bee thankful to
    you.

  • lubin |

    Its like you read my mind! You appear to know so much about this, like you
    wrote the book in it or something. I think that
    you can do with a few pics to drive the message home a bit, but instead of that,
    this is fantastic blog. A great read. I will
    definitely be back.

  • Agen Bola 24 Jam |

    I’m truly enjoying the design and layout of your website.

    It’s a very easy on the eyes which makes it much more enjoyable for me to
    come here and visit more often. Did you hire out a developer to create your theme?

    Fantastic work!

  • ceh training in chennai |

    Hey There. I found your blog using msn. This
    is a really well written article. I will make sure to bookmark it and return to read more of
    your useful info. Thanks for the post. I’ll certainly comeback.

  • kopek egitimi |

    I all the time used to read article in news papers but now
    as I am a user of net therefore from now I am using net
    for posts, thanks to web.

So, what do you think ?