SitePoint Sponsor

User Tag List

Results 1 to 19 of 19

Thread: ?action

  1. #1
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ?action

    Hey.

    I can get to a function by making the form action
    ?action=function_name

    How do I get to a function inside a function, like this:
    PHP Code:
    function function_name() {

    show_form() { // stuff here }


    I tried
    ?action=function_name=show_form
    ?action=function_name?show_form

    Im not really sure how id look this up sorry

  2. #2
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh i figured it out from looking at sitepoint

    its ?action=something#another

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What you mean by this? Do you mean that you can post a form to a particular PHP function? I am really wonder if it is possible, HOW? The way you are talking about will work in case of HTML anchor tag/link.

    Can you please share the link where you found that solution? I am really eagerly waiting for that maybe I am newbie in this case.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,194
    Mentioned
    17 Post(s)
    Tagged
    5 Thread(s)
    From the looks of it are you attempting to create a Controller?

    /controller/method

    /news/main

    class NewsController {

    protected function main() {
    }

    }

  5. #5
    Coding and Breathing CoderMaya's Avatar
    Join Date
    Feb 2008
    Location
    Atlit, Israel
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    JREAM, it's actually not how you found it. This is what you're looking for:
    Code:
    http://example.com/?action=function&&name=show_form
    Then in PHP
    PHP Code:
    $requested_action $_GET['action'];
    if(
    $requested_action == 'function')
    {
    $function_name $_GET['name'];
    if(empty(
    $function_name)
    throw new 
    Exception('Argument exception');
    // code here - or you could do
    if(function_exists($function_name))
    $function_name();

    Learn about the new Retro Framework
    Code PHP the way it was meant to be coded!

  6. #6
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why doesnt this work

    I dont understand some of what that php is in your maya

    PHP Code:
    function showblocks() {

    print 
    '<a href="?action=showblocks&&block-1">Block 1</a>';
    print 
    '<a href="?action=showblocks&&block-2">Block 2</a>';
    print 
    '<a href="?action=showblocks&&block-3">Block 3</a>';

    if (
    $_GET['action'] == 'showblocks&&block-1') {
        
    block('block-1');
        }
    elseif (
    $_GET['action'] == 'showblocks&&block-2') {    
        
    block('block-2');
        }
        
    elseif (
    $_GET['action'] == 'showblocks&&block-3') {    
        
    block('block-3');
        }
        


  7. #7
    Coding and Breathing CoderMaya's Avatar
    Join Date
    Feb 2008
    Location
    Atlit, Israel
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look, PHP URLs are built like this:
    http://[domain-name].[extension]/[file-name].php?[var]=[varValue]&&[var2]=[var2Value][...]
    The $_GET array is pretty much a result of:
    PHP Code:
    $uri $_SERVER['REQUEST_URI'];
    $uri explode('?'$uri);
    $queryVars explode('&'$uri[1]);
    foreach(
    $queryVars as $var) {
        
    $splitKeyValue explode('='$var);
        
    $_GET[$splitKeyValue[0]] = $splitKeyValue[1];
    }

    // As a result, if we had the URI
    // "/index.php?action=function&&name=show
    // Our get array would already be set up like this:
    $_GET['action'// Equals 'function'
    $_GET['name'// Equals 'show' 
    Get it?
    Last edited by CoderMaya; Sep 9, 2008 at 02:10.
    Learn about the new Retro Framework
    Code PHP the way it was meant to be coded!

  8. #8
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You do not use && to separate variables in the query string, you only use 1 &.

    If the URL is in HTML, remember to use the character entity &amp; instead.

  9. #9
    Coding and Breathing CoderMaya's Avatar
    Join Date
    Feb 2008
    Location
    Atlit, Israel
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It actually doesn't matter how many '&''s you use, for the record. I have always used 2 since it works well with programming syntax. But that's a preference.
    Learn about the new Retro Framework
    Code PHP the way it was meant to be coded!

  10. #10
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It has nothing to do with programming syntax, it is something entirely separate.

    2 Will work, but will create an 'empty' variable with no name in the middle - bit of a waste really.

  11. #11
    Coding and Breathing CoderMaya's Avatar
    Join Date
    Feb 2008
    Location
    Atlit, Israel
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I meant that it works well in my head when writing URLs with two of those since it makes more sense to me...

    And no, it does not create empty variables. It's just like using 1 or a million of them. Like I said before, it doesn't matter.
    Learn about the new Retro Framework
    Code PHP the way it was meant to be coded!

  12. #12
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It will create them, but they won't appear in the $_GET array because they have no name.

    You might like doing it that way, and it might not have an effect, but it doesn't mean it doesn't matter.

  13. #13
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Sorry, but i'm inclined to agree with Stormrider the RFC clearly states only one ampersand is to be used to separate URL variables.

    http://gbiv.com/protocols/uri/rfc/rfc3986.html

    Whilst it will work, surely you wouldn't allow them to creep into your coding knowingly?

    SilverB.

  14. #14
    Coding and Breathing CoderMaya's Avatar
    Join Date
    Feb 2008
    Location
    Atlit, Israel
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider View Post
    It will create them, but they won't appear in the $_GET array because they have no name.

    You might like doing it that way, and it might not have an effect, but it doesn't mean it doesn't matter.
    They are 'exploded' out of the URI string in C, so they won't be in the array.
    Learn about the new Retro Framework
    Code PHP the way it was meant to be coded!

  15. #15
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I know it won't appear in the array, that is what I said. That doesn't mean you should just use any way that works - if the specification changes in the future to have a special meaning for a && (unlikely but you might), then your code will break.

    You should do things the right way than just making up your own way to do it because you prefer it.

  16. #16
    Coding and Breathing CoderMaya's Avatar
    Join Date
    Feb 2008
    Location
    Atlit, Israel
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider View Post
    You should do things the right way than just making up your own way to do it because you prefer it.
    Haha well ain't that a depressing thought. If everyone did that, innovation wouldn't exist.

    Either way, I don't really use query strings.
    Learn about the new Retro Framework
    Code PHP the way it was meant to be coded!

  17. #17
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Are you saying you are innovating a new and radical approach to query string construction?

    What amazing advantages does your new innovation offer?

  18. #18
    Coding and Breathing CoderMaya's Avatar
    Join Date
    Feb 2008
    Location
    Atlit, Israel
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ohh no, why that's not what I meant at all! Apparently I overestimated your ability to construct proper sentences. See, when you said
    You should do things the right way than just making up your own way to do it because you prefer it.
    I took it for what it is, when what you mean was:
    You should go by the manual when it comes to using a built-in query string standard.
    But see, you didn't phrase it right, since you couldn't find a manual for that, and creativity must not be your strong point.
    Learn about the new Retro Framework
    Code PHP the way it was meant to be coded!

  19. #19
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Ah well, that's what comes from misunderstanding me :P


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
  •