Skip to content
Jeroen edited this page Jan 11, 2016 · 11 revisions

The Quantiweb MVC allows you to keep your interface and code separate, and thus cleaner and more secure. This feature is highly in development, but here are some examples on how to use it.

The goal of this tutorial is to make a page that shows "Hello, Your Name" and show's which day of the week it is.

First, you have to create your interface. You can do this in plain HTML.

Create a file page.qhtml

<html>
   <div class="header">
     <h1>My title</h1>
     <p>Hello, <span id="yourname"></span></p>
   </div>
   <div class="content">
      <p>Its <span id="day"></span>!</p>
   </div>
</html>

Now we can create the logic behind the page. Create a file page.php

<?php
   $mvc = new Mvc(__FILE__);
   $mvc->_("#yourname")->set_html(system_currentuser());
   $mvc->_("#day")->set_html(date("D"));
   $mvc->get_all();
   //Output:
   //<html>
   //<div class="header">
   //  <h1>My title</h1>
   //  <p>Hello, <span id="yourname">Username</span></p>
   //</div>
   //<div class="content">
   //  <p>Its <span id="day">10-10-2016</span>!</p>
   //</div>
   //</html>
?>

Thats it! the _("#div"); function gives you the correct element, where the # stands for ID. set_html sets the html of the element you've selected using the _() function. get_all(); output's the qhtml page.

Hiding elements

You can hide elements with the MVC. This is usefull if you want to make an multistep form for example.

<html>
<form id="step1">
<!-- Your super awesome form here !-->
</form>
<form id="step2">
<!-- Another super awesome form !-->
</form>
<form id="step3">
<!-- This form is a little bit less awesome !-->
</form>
</html>
<?php
   $mvc = new Mvc(__FILE__);
   if(step1()){
      $mvc->_("#step2")->hide();
      $mvc->_("#step3")->hide();
   }
   if(step2()){
      $mvc->_("#step1")->hide();
      $mvc->_("#step3")->hide();
   }
   if(step3()){
      $mvc->_("#step1")->hide();
      $mvc->_("#step2")->hide();
   }
   $mvc->get_all();
?>

Forms

The MVC has some functions only usable on <input> and <textarea> tags. In this example we're going to show the username of the currently signed in user and it's roleid.

<form>
   <input type="text" name="username" id="username" disabled>
   <input type="text" name="role" id="role" disabled>
</form>
<?php
   $mvc = new Mvc(__FILE__);
   $mvc->_("#username")->set_value(system_currentuser());
   $mvc->_("#role")->set_value(system_getuserinfo(system_currentuser(), "role");
   $mvc->get_all();
?>

Changing Elements

MVC also allows to change all elements in your page.

<html>
  <input type="text">
  <input type="text">
  <input type="text">
  <input type="text">
</html>
<?php
  $mvc = new Mvc(__FILE__);
  $mvc->_("input")->addClass("form-control");
  //This will return 4 times <input type="text" class="form-control">
  $mvc->get_all();
?>

Variables

The variable syntax looks like this:

<html>
   <div class="header">
     <h1>My title</h1>
     <p>Hello, $username</p>
   </div>
   <div class="content">
      <p>Its $day!</p>
   </div>
</html>
<?php
   $mvc = new Mvc(__FILE__);
   $mvc->set_var("username", system_currentuser());
   $mvc->set_var("date", date("D"));
   $mvc->get_all();
?>
Clone this wiki locally