SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: MVC Question

Hybrid View

  1. #1
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    MVC Question

    For pure MVC methods, how does one do things like selected in select form?

    If view is supposed to have no logic how do I solve something like this?

    PHP Code:
    echo "<select name='statelist'>";
    foreach (
    $state as $v) {
        
    $sel = ($_GET['state'] == $v) ? "selected='selected'" '';
        echo 
    "<option value='$v$sel>$v</option>";

    }
    echo 
    '</select>'

  2. #2
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Either build the string in your model (including whether or not it's selected), or bite the bullet and allow this small amount of logic in your view. I don't think it's a big deal, honestly - I put this exact thing in my view. And really, it makes sense when you think about it - default values would be associated with how you view the form, and aren't really part of business logic per se.
    PHP questions? RTFM
    MySQL questions? RTFM


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •