i have downloaded your mvc cause i want to learn the mvc pattern while see it at work. i must say it was very fast and easy to understand how to install it and understand most of the flow.
as an experiment i have a users table. so i made a listusers action and list them all. that works great. i made each a link (to go to the details "page"), that looks like that (i`m using my own database class):
echo "<a href='user/id/$user->id'>" . $user->first_name .' ' . $user->last_name . "</a><br/>";
then in a user action i do that:
$id = $_GET['id'];
but i get the error that: Undefined index: id
how do i pass get variables?
2 other issues:
1- do i have to declare the template parts on each action? is that not DRY?
2- i thought that i can make variables that are accessible across the application in the starter file, but it does not do that. so maybe i did not really understood the flow of data:)
in any case, this sime mvc does teach me a lot and i thank you for that.
lattuada - 2010-04-18 09:54:54 - In reply to message 1 from Ron Shtigliz
thanks for your interest. if you download the github's version (http://github.com/nicolaslattuada/minimal-php-mvc) source you'll get an exemple on how to pass vars from the url. for exemple if you have an url as it follows http://localhost/mvc-test/www/mymodule/exemple/valueofthefirstparam/123anothervalue , according you have a module called mymodule, an index controller an you are executing the exemple action, from the exemple action you can access a var called params which is an array of all the params ( echo $this->params ) if you want to pass this value to the view you'll have to do smth like this $this->_view->myvar = $this->params.
then to access get values if you have the same context and the following url localhost/mvc-test/www/mymodule/exe ... i thing you can print and access $_GET['test'] from anywhere you want.
about the dry issue, for exemple when i have an admin module which always uses the same template i implement a __destruct method in the parent class from which i call $this->show('main.tpl'); you could define from your actions a variable called content for exemple you would do in the actions :
$this->content = 'exemple.phtml';
and then in the destructor call
and doing like this you would not have to repeat yourself.
then to make variable accessibles from the entire application it depends on their types if you just have some strings or ints and you just need read access to them you may use constant which i define in the ./config/defines.php script.
if you want to pass arrays or ressourses i would do it from the ./www/index.php file, add the following line just before the $front-run(), $front->somevar = array(1,2,3); and then access it from your controllers like this echo $this->front->somevar;