Over a million developers have joined DZone.

PHP: Dynamically Call A Function From List Of Allowed Actions

This function simply calls another function based on the argument, assuming that argument ($action) is in the "allowed" list of actions.


$settings['actions'] = "list,view,delete,update";


public function process_action($action) {
	global $settings;
	$allowed_actions = explode(",",$settings['actions']);
	if (is_numeric(array_search($action, $allowed_actions))) {
		$f_name = "product_" . $action;
	} else {
		$this->error_msg = 'ACTION_NOT_ALLOWED';
private function product_list() {
private function product_view() {
private function product_delete() {
private function product_update() {
private function product_create() {

Even if product_create() exists, if you do process_action('create'), it will not work... it's basically like a function wrapper.. or something like that...

UPDATE: Yes I know I could have created an array like $settions['actions'] = array('list','view','delete','update'); but I've modified this code a bit for snippet/display purposes... anyways this is just a reminder for myself, not of actual use or interest for others... comments are welcome though :D

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}