0

How do i call the function registreer in my class called Controller.php when i klick on the 'Registreer je' button?`

this is the part from my Index.php file. Also it has a 'require_once('Controller.php');'

<form method="POST" action="<?php echo Controller::registreer()?>">
    <button type="submit" class="btn btn-primary">Registreer je</button>
</form>`

and my function in Controller.php:

public static function registreer(){
        header("Location:registreer.php");
        exit();
    }
1
  • Is this a framework or some MVC you are trying to put together on your own? How does your application route URLs? Commented Oct 22, 2013 at 14:48

2 Answers 2

1

I'd say "just call your route" but it seems that your design actually hasn't any routes...but I come to that later.

So for now you've got to

  1. Call the script again, checking if the method by which the site was called is POST and then call your Controller method
  2. Create a second script, maybe called registreer.php which is called when submitting the form, where you call the Controller method

The above example will not work, because you're basically calling your method Controller::registreer() and inserting the returned results from it (if it has any, in this case it hasn't) into the action attribute from your <form> tag.

If you want to actually have the file registreer.php to be called on form submission just write it into the action attribute.


Anyway, that's not a quite good design - due to the fact that your going to have some kind of Controller in your code it would be the best practice to actually create Routes which are calling methods you define.

Have a look at this tutorial to get a clue about what MVC actually is.

After that I recommend you to use one of the many many many MVC frameworks available out there.

Two of my favorites are

  • Silex, a micro framework, mainly giving you the change to create fast and easily routes for your application
  • Slim, yet another micro framework
  • Laravel, nice to use framework

If you think you've got the idea and want to get deeper, have a look at the "bigger" frameworks, like

  • Symfony2, not just a MVC framework, comes with a bunch of additional components (called bundles)
  • Zend Framework, another one

Those are just five examples of many frameworks out there. Go and grab one.

Sign up to request clarification or add additional context in comments.

Comments

0

You would be better off just getting the path from the controller, as you are not really executing anything but sending a redirect header, which is what the action does by default when a path is given.

Also you cannot echo redirects, this would cause errors due to there not being a string to echo.

If you know the path, set it manually (or dynamically via a variable) If the path is dynamic, retrieve it via getters and setters in the object itself.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.