I'm trying to develop a webpage (menu.php
) which has a <div>
when clicked accesses "one" of the many methods in the stock-c.php
. The code I have developed as follows:
menu.php
<?php
require_once '../control/stock-c.php';
?>
<html>
<body>
<div onclick="<?php $obj=new StockController(); $obj->checkAccessRights();?>"> //I know this is a wrong implementation
//some code here
</div>
</body>
</html>
stock-c.php
class StockController{
public function checkAccessRights(){
//some code here
}
public function getPID(){
//some code here
}
}
I know menu.php
file's onclick
event is a wrong implementation.
Since there will be other situations that I will need to call other methods (like getPID()
) in other PHP web pages, I'm not sure if using jQuery to create an AJAX call on the onclick
event in menu.php
to access an "altered" stock-c.php
file such as:
class StockController{
$obj=new StockController();
$obj->checkAccessRights();
public function checkAccessRights(){
//some code here
}
public function getPID(){
//some code here
}
}
which was suggested in How to Call PHP Function in a Class from HTML Button Click would work as this breaks my ability to access the other function. I just am not sure what alternatives I have. Any help will be appreciated.