PHP Classes

problem with GET

Recommend this page to a friend!

      Another simple MVC  >  All threads  >  problem with GET  >  (Un) Subscribe thread alerts  
Subject:problem with GET
Summary:some issue
Messages:4
Author:Ron Shtigliz
Date:2010-04-18 06:25:26
Update:2010-04-18 11:48:07
 

 


  1. problem with GET   Reply   Report abuse  
Picture of Ron Shtigliz Ron Shtigliz - 2010-04-18 06:25:26
Hi
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'];
echo $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.

best regards

  2. Re: problem with GET   Reply   Report abuse  
Picture of lattuada lattuada - 2010-04-18 09:54:54 - In reply to message 1 from Ron Shtigliz
Hi Ron

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[0] ) if you want to pass this value to the view you'll have to do smth like this $this->_view->myvar = $this->params[0].
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
$this->template('content', $this->content);
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[1];

hope it helped. regards

  3. Re: problem with GET   Reply   Report abuse  
Picture of Ron Shtigliz Ron Shtigliz - 2010-04-18 11:43:41 - In reply to message 2 from lattuada
Hi

first thanks for answering.

how do i get the github version? i went there and there is nothing in the download section.

  4. Re: problem with GET   Reply   Report abuse  
Picture of Ron Shtigliz Ron Shtigliz - 2010-04-18 11:48:07 - In reply to message 3 from Ron Shtigliz
Hi

just saw the download source and used it:)

thanks for all your help.

i know i`ll learn a lot from it.