0

I have created a class named as "member" and inside the class I have a function named update(). Now I want to call this function when the user clicks 'UPDATE' button.
I know I can do this by simply creating an "UPDATE.php" file.

MY QUESTION IS :-

Can I call the "update() function" directly without creating an extra file? I have already created an object of the same class. I just want to call the update function when the user clicks on update button.

1
  • make the but on a link, read the status from the url Commented Sep 22, 2011 at 7:00

4 Answers 4

1

an action.php example:

<?
if (isset($_GET[update])){
$id=new myClass;
$id::update($params);
exit;}

//rest of your code here

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

Comments

0

Your button is in your view. Your method is in your class . You need a controller sitting in the middle routing the requests. Whether you use 1 file or many files for your requests is up to you. But you'll need a PHP file sitting in the middle to capture the button click (a POST) and then call the method.

Comments

0

As far as I know you can't do this without reloading your page, checking if some set parameters exist which indicate the button is clicked and than execute the button. If this is what you are looking for... yes it is possible on page reload. No as far as I know it is not possible directly because your php-function has to parse the results again.

Remember that a Model-View-Controller way is better and that this will allow you to ajax (or regular) requests to the controller-class.

Comments

0

You do it on the same page and have an if statement which checks for the button submission (not completely event driven) like so

if (isset($_POST['btn_update']))
{
    update();
}

<input type="submit" name="btn_update" value="Update" />

That will have to be wrapped in a form.

Or you could do it with AJAX so that a full page refresh isn't necessary. Check out the jQuery website for more details.

2 Comments

Thanks for your answer. What if there is a hyperlink instead of a button?
You could append a query string to the url of the current page ?update=yes and then check for that in your code if($_GET['update'] == 'yes') then just place that url in your href tag index.php?update=yes

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.