PHP MVC Framework

+2 Dezmen Sykes · November 25, 2014
Im working on a MVC based framework in php with custom routing and bootstrapping. I think itll be an excellent way to start large-scale web apps because of the structure organization and capability, though its not much to go on at the moment, I'm willing to share the code for people interested in using it and even building on to it :)

Post a Reply

Replies

Oldest  Newest  Rating
0 Ron Butcher · November 26, 2014
I would be interested in checking out your code.  I am working on an MVC as well.  I am having a difficult time bringing in the main page elements along with the information to be displayed.  
0 Dezmen Sykes · November 26, 2014
No doubt! we could even build something together! im going to upload it to a repo soon asap, but i can help you with urs if u need it also
0 Ron Butcher · November 26, 2014
That would be cool.  I have mine on github right now.  Here is the link.

https://github.com/butcherman/mvcTest

I am looking for any feedback and how to make it better.
0 Dezmen Sykes · November 27, 2014
Nice man, looks like we viewed the same starter series lol, wht i added on to it was more error handling on the app class to handle routeing better. My code is on my other computer but i can post scripts and snippets to help ya out. I

This is my App.php(Routing handler) setup i have.


<?php

class App
{
protected $controller = '';
protected $redir_controller = '';
protected $viewMethod = '';
protected $params = [];


public function __construct()
{
$url = $this->parseUrl();

//print_r($url);

if(!file_exists(strtolower('app/controllers/'.$url[0].'.php')) && $url[0] != 'home')
{
header("Location: home/");
}
else
{
$this->controller = $url[0];
$this->_controller = $url[0];
unset($url[0]);
//$this->controller = 'home';
}

if(!require_once strtolower('app/controllers/'.$this->controller.'.php'))
{
exit('Invalid Controller Specified.');
}


$this->controller = new $this->controller;

if(isset($url[1]) && !empty($url[1]))
{
if(method_exists($this->controller, $url[1]))
{
$this->viewMethod = $url[1];
unset($url[1]);
}
else
{
//echo $this->_controller;
header("Location: /".$this->_controller."/");
//unset($url[1]);
}
}
else
{
header("Location: /".$this->_controller."/index/");
}

$this->params = $url ? array_values($url) : [];

call_user_func_array([$this->controller, $this->viewMethod], $this->params);
}

public function parseUrl()
{
if(isset($_GET['url']))
{
return $url = explode('/', filter_var(rtrim($_GET['url'], '/'), FILTER_SANITIZE_URL));
}
}
}

?>



I also created a simple PDO like generic class to handling pulls and pushes to the database based off of arguments, which was basically a class which all the generic data waiting to be replaced which whatever data is given, which will be not only based on the model, but for conditional logic as well. But I've just recently seen how to create a data entity setup in php so i may replace the setup i have now
0 Brendon McBain · November 27, 2014
If you're looking for good tutorials on this, check out JREAM on YouTube. That's where my journey of learning MVC started, it was a helpful resource.

https://www.youtube.com/watch?v=Aw28-krO7ZM
0 Ron Butcher · November 29, 2014
I like it, thanks.  I am updating mine as well.  I prefer mysqli myself, so I am making a SQL class that the model will expand on.  I hope to have it uploaded to the repository Monday or Tuesday.
0 Dezmen Sykes · December 4, 2014
Yessir! Its gonna b pretty boss!
0 Dezmen Sykes · December 4, 2014
Yessir! Its gonna b pretty boss!
0 Jragon Chan · December 5, 2014
Hiya, 

I wrote a little MVC framework a couple years ago. Honestly it's not worth re-inventing the wheel. There are plenty of good frameworks already out there.

However, it was pretty fun! Here's the git repo: https://github.com/Jragon/Midget-MVC

Cheers,

-Jragon
0 Ron Butcher · December 6, 2014
Thanks Jragon.  For me it's not about re-inventing the wheel but learning more about PHP.  I have a pretty good grasp of basic PHP, but I am trying to learn more about advanced PHP.  I think that building my own framework is a good chance to work better with OOP and some advanced features of PHP.
  • 1

PHP

107,059 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators