Jump to content

Matic

Members
  • Posts

    42
  • Joined

  • Last visited

Everything posted by Matic

  1. Exactly so it is safe to say that I can use session variables to achieve the same result in my front controller?
  2. Wow great answers guys thanks. However now that I understand this better I must ask you why would I use this if my user has to log in to access the page anyway? I could simply use $_SESSION variables to display correct data on my index page... like so (I am building a simple browser game): if ($_SESSION['combat'] = true) { include 'certain_page.php'; } else if (...) { include 'another_page'; } else if ..... etc...
  3. I see, does that return results back to front controller? And then front controller shows the result? Are there any examples how this can be achieved with code?
  4. So if I set up my front contoller right, then everything will be displayed on index.php, every template I have? But why would I want this
  5. So every request we make on a specific controller is redirected via .htaccess modrewrite to the front controller, which then displays the output of that controller?
  6. I know some people make a single point of entry to their website which is usually index.php - the first site you visit and login from. But what is this exactly? Is it a controller that decides which webpages to show like in this tutorial http://www.technotaste.com/blog/simple-php-front-controller/ ? Why would you want a controller for a whole page? How does it work? Does it just redirect every link you click to the index.php and every header in php leads to index.php? In the provided tutorial, author goes on how we type the url and it redirects us to index.php. But what does this mean in reality, when you must click links and forms to navigate through a website? Does this mean that every submitted form and every new php page redirects to controller page and then the controller page redirects everything to index.php?
  7. I think I understand more clear now what is what! Can you confirm that this page I made is indeed a simple controller. My model redirected to this page and now on this page I handle all sort of variables and on the bottom I included the view/template: session_start(); require_once 'includes/save.php'; require_once 'includes/stats.php'; $igralec_ime = $_SESSION['username']; if (isset($_SESSION['monster_ime']) or isset($_SESSION['monster_curhp']) or isset($_SESSION['moznost']) or isset($_SESSION['poskodbe']) or isset($_SESSION['spol']) or isset($_SESSION['combat']) or isset($_SESSION['turns']) or isset($_SESSION['zmaga']) or isset($_SESSION['zguba']) or isset($_SESSION['cekini']) or isset($_SESSION['post']) ) { $monster_ime = $_SESSION['monster_ime']; $monster['curhp'] = $_SESSION['monster_curhp']; $moznost = $_SESSION['moznost']; $poskodbe = $_SESSION['poskodbe']; $spol = $_SESSION['spol']; $combat = $_SESSION['combat']; $turns = $_SESSION['turns']; $zmaga = $_SESSION['zmaga']; $zguba = $_SESSION['zguba']; $cekini = $_SESSION['cekini']; $_POST = $_SESSION['post']; if ($monster['curhp'] <=0 and isset($_SESSION['monster_curhp'])) { update_save($igralec_ime, 'gozd', ''); } else if (prikazi_stat('curhp', $igralec_ime) != 0) { update_save($igralec_ime, 'gozd', $monster_ime); } } else { $poskodbe = prikazi_stat('curhp', $igralec_ime); $moznost = 'Tvoje zdravje je resno ogroženo, vrni se domov!'; $monster_ime = prikazi_borba($igralec_ime); $spol = sprintf("SELECT spol FROM monsters WHERE ime = '%s'", mysql_real_escape_string($monster_ime)); $result = mysql_query($spol); list($spol) = mysql_fetch_row($result); if (prikazi_stat('curhp', $igralec_ime) <= 0) { update_save($igralec_ime, 'gozd', ''); } } include '../public/gozd.html';
  8. Hmmm so where do I put my variables that display data to user etc.. in my template?
  9. What would be this structure I use for my project? <body> <?php if(!$_POST and $poskodbe != '0') { ?> <p>Presenetil<?php text($spol); ?> te je <?php text($monster_ime); ?> !</p> <form action='../igra/gozd.php' method='post'> <input type='submit' name='action' value='Napadi' /> ali <input type='submit' name='action' value='Pobegni' /> <input type='hidden' name='monster' value= '<?php text($monster_ime); ?>' /> </form> Would this be template or a view?
  10. But overall a template is just a mixture of html and php right? And a view is broader, its a set of variables, session variables or whatever and it includes templates at the bottom. Did I get this straight? PS is a view also used in a post-redirect-get pattern? The way I see it the view is a mediator between actual database input code in the back and it includes templates to present the output to the user
  11. you should write it like this: $result = mysql_query($query); and if you want to get a row from your base: list($row) = mysql_fetch_row($result); EDIT: also, what are you trying to say in your if statement? if ($row) isn't enough. If you simply want to check if you have any rows in your signup table under the $sname, do it like so: if($row > 0) { //do stuff here } else { //do stuff here }
  12. You are including $body and all the other variables before they are stated... In php code runs from top to bottom. Solution would be to move your if statements: if ($title&&$body) below the code for your news page
  13. I have a question, no a rant even because there is absolutely no information about this topic. Sure I read a lot about templating engines and MVC frameworks already out there. But what if I am building a small php app and frameworks would be an overkill and template engines are just redundand for me... I want to make a nice organized app but so far my directory strucute is: models (backend, bussiness logic) and html, php mix (for displaying php results to the user). Regarding views, what the hell is is? Is this just a mixed php file with html to display output? What is a template? What is the difference? Is a template purely in html? How does a template structure even look like? I really want to separate php from html but so far I have a bunch of <?php tags inside html files... and it really looks nasty. Lets say I want to make a template or a proper view, or only one of the two, whatever is needed... Simply put: I want php in one place and html, css design in other... And in a really simple way, with nothing else but my own code. Templates, views?
  14. yes but where in there is the encounter probability? It looks jut like a random selection on a first glance
  15. I see this could be a nice probability algorithm but I don't understand this: floor( 10 + (RAND() * 190))
  16. Hey there, using this mysql string: "SELECT name FROM monsters ORDER BY RAND() LIMIT 1" I retrieve a random monster encounter from my database. I have a question though, how would one influence the apperance rate of particular rows from my table? In practices this means that some monsters would appear more, some less.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.