#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,653
    Rep Power
    171

    How to re-populate the forms with CodeIgniters Template engine parser


    Hello world;

    I have never been a fan of template engines but after doing a few websites with Smarty I thought I try Codeigniters and I find this feature weak, helpless and incomplete.

    For example:

    In case there is an error in the form, how can I keep the selected option selected?
    Controller:
    PHP Code:
     $this->load->model('model_products');
    $classes $this->model_products->list_classes(); 
    View
    PHP Code:
     <select name="class" class="search_drop_down">
     <
    option value="all">All</option>
        {
    classes}
         <
    option value="{class}">&nbsp;{class}</option>
        {/
    classes}
    </
    select
    I know I can use:
    PHP Code:
    <?php if(set_value('class')== ){ ?>{class} selected ="selected"<?php}
    but I dont want php tags in the view. That's the whole point of using the template enginea after all isnít it?
    Thank you
    Last edited by zxcvbnm; May 8th, 2013 at 02:15 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,972
    Rep Power
    375
    cant you use smarty in conjunction with CI? or maybe look at the parser file and tinker around with it (risky i know)
  4. #3
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Hi,

    the manual explicitly says that the built-in parser is not fully-featured. As far as I understand, it can only do variable replacement and foreach loops. For anything else, you'll need to include a "real" template engine.

    RTM
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo