Saturday 15 August 2015

php - View in MVC, what is a layout and how to create one -


I did not understand what the layout is, in the view I already asked about templating in PHP, but I still did not understand enough. I think that you create a general layout for the site and then include each specific view within that layout .... I would like to know how to know about doing this. Also, the template should be done using html just because I have called these assistants .... I am just confused over the scene of MVC, and the actual templates and how they make them. I learn the best with examples, if you have any questions.

In addition to this, another important question is that I have a form that the user only logs in when he is logged in, I control it, or in the controller ?

So what will I do

  contains 'header' in the controller; If (isset ($ _ session ['userID'])) {include 'form'; } Include 'footer';  

or

  in the template & lt; Html & gt; & Lt ;? Php if (isset ($ _ session ['user_id'])):? & Gt; & Lt; Form & gt; .... & lt; / Form & gt; & Lt ;? Php endif ;? & Gt; & Lt; / Html & gt;  

edit

So, to see a specific visual template, there is a included statement from within the layout? I hesitate to answer this question only because of religious jealousy around the devotee.

To get a good understanding of the issues behind general concepts, see this wiki article of MVC The surrounding discussion page is

Here is the rule of thumb which I want to follow (use the BTW I CodeIgniter and it's like sounds like you):

There is almost no logic in "view" should be there. It should be in HTML (web world) with PPP, which is only ace variable In your example, you will break the form in your own view and the controller will determine whether it has been loaded or not.

I like to see it like this: This scene should not have any concept where the data comes from or where the model is going Ageless should look at the controller looking at the model's data and looking at it - And it takes input from the scene and filters it into the model.

Theapp.php (App Controller)

  increases class Theapp controller {var $ _authenticated; var $ _user; var $ _ menu} // array of menu function // __ composition () {session_start (); if (isset ($ _ session [' Authenticated ']) and $ _SESSION [' authenticated ']) {$ this-> _ = certified = $ _SESSION [' authenticated ']; // or something like $ this-> _user = $ _SESSION ['User'];} $ this-> _menu = array ("logout", "help", "more"); parent Ta: __ build (); $ this-> loadView ("welcome"); // loads main welcome view - but not necessarily a complete "html" page} function index () ( If (! $ This-> _authenticated) $ this-> LoadView ("Login Form"); Else {$ viewData ['Menu'] = $ this- & gt; _menu; $ ViewData ['user'] = $ This-> _user; $ this-> LoadView ("Menu", $ ViewData);}} Function Login () {/ code to authenticate the user} / / function logout () {/ * Code to select logout menu} Function Help () {/ * Code Help menu selection process more for more menu selection * /}}  

welcome.php

  & Lt; H1 & gt; Code to process) Welcome to this quick and dirty app! & Lt; / H1> All kinds of good HTML, Javascript, etc. will be added!  

loginform.php

  & lt; Form action "/ Theapp / login" method = "post" & gt; User: & lt; Input id = 'user' name = 'user' & gt; Near: & lt; Input id = 'pass' name = 'pass' type = 'password' & gt; & Lt; Input type = 'submit' & gt; & Lt; / Form & gt;  

menu.php

  Hi & lt ;? = $ User? & Gt ;! & Lt; Br> Here's your menu & lt; Br> By & lt;? Forex Currency ($ menu $ as option) {? & Gt; & Lt; Div class = 'menu option' & gt; & Lt; A href = '/ theapp / & lt ;? = $ Option? & Gt; ' & Gt; & Lt ;? = $ Option? & Gt; & Lt; / A & gt; & Lt; / Div & gt; By & lt;? }? & Gt;  

Hope it helps.


No comments:

Post a Comment