Jump to content

MVC help!


jbwebdesign

Recommended Posts

Hello, I am working on my own lightweight MVC framework. I ran into a little situation when determining what page i am on.

 

below is my Controller.....

The problem i have is when checking if the method exists....

$this->{$boom[0]}();

how do i pass unlimited parameters inside this function?

 

basically what i am trying to do is explode everything by a / and the first array is the method, anything after that will be parameters...

 

<?php 
class Controller{

public $load;
public $model;

function __construct()
{
	$this->load = new Load;
	$this->model = new Model;

//determine page were on...
	if(isset($_GET['url'])):
		//blow up the url by /
		$boom = explode('/', $_GET['url']);

		if(method_exists(__CLASS__,$boom[0])): 	

			$this->{$boom[0]}();

		else:
			$this->error_page(); //method doesn't exist so we can show error page or default page.
		endif;


	else:
		//default page to show...
		$this->home();
	endif;

}//end constructor

function home()
{
	$data = $this->model->user_info();
	$this->load->view('myview.php',$data);
}

function error_page()
{
	$data = $this->model->user_info();
	$this->load->view('error.php',$data);
}


}   


?>

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...