jbwebdesign Posted November 22, 2011 Report Share Posted November 22, 2011 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); } } ?> Quote Link to comment Share on other sites More sharing options...
falkencreative Posted November 23, 2011 Report Share Posted November 23, 2011 Perhaps pass in an array of perameters? That's the way that CodeIgniter works, though I'm not sure about other MVC frameworks. Quote Link to comment Share on other sites More sharing options...
jbwebdesign Posted November 25, 2011 Author Report Share Posted November 25, 2011 well how would i pass an array through in this example? if i do.... $this->{$boom[0]}($boom = array()); it will only return "array" Quote Link to comment Share on other sites More sharing options...
ivanpanchev Posted December 9, 2011 Report Share Posted December 9, 2011 Just a suggestion: You can pass boom[1] as parammeter of function boom[0]. Then explode boom[1] inside boom[0]. Hope helps. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.