Jump to content

Ocs-server/Gfx4/Views

From KDE Community Wiki
Revision as of 21:08, 27 July 2015 by Snizzo (talk | contribs) (Created page with "Then there's the View folder, which is at the root of the local gfx application and is called "views". This one contains php files named under the following syntax: ''<vi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Then there's the View folder, which is at the root of the local gfx application and is called "views". This one contains php files named under the following syntax:

    <viewname>.views.php

Each view has the php final extension but can contain both php and standard templating code like pure html, css, js. In fact, a view should contain exaclty the code needed to display data to the user in the desired way. This will be achieved by a particular interaction that we'll see later in this guide.

You can also create a views hierarchy simply by creating a set of folders. The load process will be completely transparent for the engine, and it's done by simply putting the entire url starting from "views" in the load command. This will be seen in a pratical example later.

When inside a controller you can just load a view by calling:

EStructure::view($view_path, [$params]) $view_path is the URI of the yourname.views.php starting from the "views" local folder of your website and without "views.php" part of the filename. [$params] is a list of parameters that the view will receive in the $data array. You can also load other components of your website (controllers and views) inside a view simply by using EStructure::view() and EStructure::controller(). Check Controller for info. Short example of loading a view that resides in views/menu/adminpanel.views.php passing some data.

<?php
$name = 'Claudio';
$surname = 'Desideri';
EStructure::view('menu/adminpanel', $name, $surname);
?>

Content of views/menu/adminpanel.views.php:

<html>
    <body>
    <?php EStructure::controller('user', 'show'); ?>
    My name is <?=data[0]?>.
    My surname is <?=data[1]?>.
    </body>
</html>

We're working on changing the way of passing variables to views since $data seems to be confusing and messy so this can be changed in the near future.