Preview-release of (my) “php-mvc” project (a simple php mvc barebone)

Voila! The very first pre-final release of the “php-mvc” repository is online: https://github.com/panique/php-mvc and http://www.php-mvc.net. It’s a very simple but very useful barebone application written in PHP. This little thing is not another framework, it is simply a totally reduced file-and-folder structure that should 1.) help developers to create PHP applications without a framework the right way and 2.) show younger devs how “good” code could look like and how MVC applications are structured. I know, some people will scream now “but why you don’t learn Zend2 etc. ?”, but that’s exactly the point: Many younger developers simply have problems to learn Zend2 etc.! Most mainstream frameworks, even the micro ones, are really hard to understand, even with some years of PHP experience.
It’s a common problem that masses of non-professional developers try to build PHP applications in their own way, without having ever heard of MVC or how to organize such a project. This usually results in a quite wild and weird file structure, with more than 15 php files for just handling one little form, and a horrible mix of database requests, HTML and CSS and php-generated JavaScript. I think we all have gone through this. The php-mvc project/repository (I’m still in the name-finding process) tries to solve that problem by providing an extremely easy-to-learn skeleton application for PHP projects, while it DOES NOT try to be a real framework. Everything is as non-automatic as possible. Everything is as clean as possible, as reduced as possible.
The project aims at people with shorter PHP experience, but tries to fit the most modern PHP standards at the same time. We are talking about PSR-1/2, autoloaders, Composer, PDO, MVC for sure, potential Unit Testing (just a plan!), Post/Redirect/Get, speaking variables/methods, proper comments etc.
To give a short introduction how this project looks and behaves, check out these 5 tutorials I’ve made (they are currently images, as this is the best possibility to bring stuff like that into a GitHub README file): And, you’ll find a file/folder structure explanaition on the last one.
Looks quite okay I think. It would be awesome if everybody who’s interested could try out this thing and give feedback, commit improvements or just send hatemails because this project is totally useless. The repo URL is https://github.com/panique/php-mvc, feel to do whatever you want with this skeleton app.
Hello
I’m starting with PHP-MVC and I have tried to write a function that gets music using the artist’s name. I couldn’t get any result from de DB
Could you please take a look at my code below and give me a hint about what is going wrong?
Just two notes:
. the variable $musics (in the next block of code) is always undefined (even after the has been submited)
. these are the only changes I made
Thank you very much
bito
/////////////////////////////////////////////////////////////////////////////////
added in songsapplicationviewssongsindex.php
—————————————————————-
Choose a song by artist’s name
<form action="songs/getsong” method=”POST”>
Artist
Id
Artist
Track
Link
id)) echo $music->id; ?>
artist)) echo $music->artist; ?>
track)) echo $music->track; ?>
link)) { ?>
<a href="link; ?>”>link; ?>
/////////////////////////////////////////////////////////////////////////////////
added in songsapplicationcontrollersongs.php
———————————————————————————
public function getSong()
{
if (isset($_POST[“submit_get_song”])) {
// load model, perform an action on the model
$songs_model = $this->loadModel(‘SongsModel’);
$musics = $songs_model->getSong($_POST[“artists_name”]);
}
header(‘location: ‘ . URL . ‘songs/index’);
}
/////////////////////////////////////////////////////////////////////////////////
added in songsapplicationcontrollersongs.php
———————————————————————————
public function getSong($artists_name)
{
$artists_name = strip_tags($artists_name);
$sql = “SELECT * FROM song WHERE artist LIKE :artists_name “;
$query = $this->db->prepare($sql);
$query->execute(array(‘:artists_name’ => $artists_name));
return $query->fetchAll();
}
Hello your project are amazing, but i have a question, how i make a jQuery
Ajax GET and POST calls to controller methods and get these arguments? for example in my js
$.post(‘../myController/myAction’, {
arg: “hello”,
arg2: “world”
});
in my controller
…
public function myAction(){
var_dump($_POST);
}
the server response: array(0) {
}
Thanks and sorry for my poor english
Good question! I’ve created a ticket on https://github.com/panique/php-mvc/issues/70 to create a demo ajax call and integrate it into the tutorial. Expect this to be ready within some days!
Hey man, I am the exact person this thing is made for. Thank you so much for creating this. I’m struggling a bit with some things, but learning a ton about proper coding standards.
Would love to see a full project built upon it, so I could see how a real world project might be further organized and built upon it.
Great framework! Job well done. It’s fast and lean. Just the way I like to write code. Keep up the development. You’ve got something here.
I love the framework and i did some post on your forum.
Currently i try to use a different approach for the views and i succeed.
https://bitbucket.org/krzysztofr/sm-view/src/dea3cf49c496337407cd42ca745444242273b1ff/custom-class/MyView.php?at=default but initially i would like to work with TWIG.I also have intentions to include something like boxes for left/right or whatever position, of course with a admin interface.
The posts i made on your forum under the name : osc2nuke
;)
Thanks :) … there’s a new “branch” of the php-mvc in https://github.com/panique/php-mvc-advanced, with Twig support. More features likes ORM, SASS, routing etc. are planned! Feel free to check this out.
Extremely useful, thanks for your work!
I have been building one myself for the last few weeks as I refuse to use a big third party framework for an own project, so even if this comes a bit late for me, I’m sure I will be able to grab some ideas from it :-)