473,769 Members | 5,900 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MVC: some questions on views

Hello,

I 'm writting an application using an MVC approach of mine (not with a
framework). Notice that I 'm not writting a framework but an application
with such an approach.

I 'm having trouble understanding how views work. I have understood
(from web reading) that MVC is a flexible approach and not something
strict so I want some advice.

I have index.php as a front controller. Depending on the module being
asked (index.php?modu le=professors for example) I load an appropriate
class controller.

Then in index.php I have a $controller->Process() function and a
$controller->view->Display() where view is a view defined in the controller.

But how do you define a view? Lets assume I am a teacher with a login in
the system and visit the site. A login in form should be presented upon
first visit to login. Is this a view by itself? Then if you login you
are shown a menu and a default page. This page holds a list of notes you
have uploaded, and you can upload/delete/edit the data. Is this a page a
single view? And what about the menu of the user. Is it a separated view
included from the main view?

I find it a little bit complicated to undestand. And to give you an
example this is my view now:

class gView {
var $header;
public $title;
public $jsscripts;
public $metakeywords;
public $metadescriptio n;
public $todisplay;

function header(){
$title=$this->title;
include('static pages/top.php');
}

function footer() {
include('static pages/footer.php');
}

function Display() {
$this->header();
print $this->todisplay;
$this->footer();

}
}

The $controller->Process() function loads the appropriate function and
sets the $view->todisplay string. Just to clarify that each controller
holds also the buisness model is the class. I don't use a separate model
class for each controller.

Any help/hint would be valuable.

Thanks a lot
Harris
Jun 27 '08 #1
4 1605
Harris Kosmidhs wrote:
Hello,

I 'm writting an application using an MVC approach of mine (not with a
framework). Notice that I 'm not writting a framework but an application
with such an approach.

I 'm having trouble understanding how views work. I have understood
(from web reading) that MVC is a flexible approach and not something
strict so I want some advice.

I have index.php as a front controller. Depending on the module being
asked (index.php?modu le=professors for example) I load an appropriate
class controller.

Then in index.php I have a $controller->Process() function and a
$controller->view->Display() where view is a view defined in the
controller.

But how do you define a view? Lets assume I am a teacher with a login in
the system and visit the site. A login in form should be presented upon
first visit to login. Is this a view by itself? Then if you login you
are shown a menu and a default page. This page holds a list of notes you
have uploaded, and you can upload/delete/edit the data. Is this a page a
single view? And what about the menu of the user. Is it a separated view
included from the main view?
The idea behind MVC is to separate data from it's presentation.
Controller acts as a director, listens to user and decides what to do.

View should be only responsible for presentation data it was given.
As so, you should not decide here, what is the state of navigation, or
if user needs to login first. Those are both controller responsibilitie s.

Your controller should process all data in context of your application
state, and pass only the result to view, for sole purpose of
presentation this data (rendering).

It's not said, that you must render single view per request. Your output
might be composed of many views. You can render your menu, other bocks
and main content, compose those (within controller) and then send it to
user.

In some of the frameworks, you also has a Layout module, this is a kind
of view decorator/composer. It takes separate views, and combines them
into complete web page. You can think of it as a html template with
options to set blocks. Ie.:
$layout->setMenu($someM enuViewNameOrRe nderedString);

As you can see, controller has a lot of work with handling request, this
is why there is a separate 'MODEL' component, that should hold data
handling logic. Just to keep things simple and readable. You are free to
do what is best for you, but this pattern has been proven right many times.

On the side note, it's good to use a framework. Lets leverage the fact
that there are so many good programmers that are willing to do the job
for us. Hell, we might even learn something from them.

Hope this helps you a bit

best regards
Piotr N
Jun 27 '08 #2
The $controller->Process() function loads the appropriate function and
sets the $view->todisplay string. Just to clarify that each controller
holds also the buisness model is the class. I don't use a separate model
class for each controller.
Why would you do that ? The beauty of a MVC structure is that you
seperate the model and view

This is how I would do it

class ProfessorModel extends Model{
// etc
}

class CourseModel extends Models{
//etc
}

class ProfessorContro ller extends Controller{

public function index($id){

// get Professor Info
$oProfessor = new ProfessorModel( $id);

// get all Courses given by this professor
$oCourses = new CoursModel($Pro fessor->getId());

// etc
}
Then pass the data ($oProfessor and $oCourses) to a View and process

Jun 27 '08 #3
floortje wrote:
>
>The $controller->Process() function loads the appropriate function and
sets the $view->todisplay string. Just to clarify that each controller
holds also the buisness model is the class. I don't use a separate
model class for each controller.

Why would you do that ? The beauty of a MVC structure is that you
seperate the model and view

This is how I would do it

class ProfessorModel extends Model{
// etc
}

class CourseModel extends Models{
//etc
}
yes I understand this. But what does Model consists of? I mean what are
the basic functionalities that can be extended?
Unless by ProfessorModel you mean a class that consists the name, id,
and general fields of professor master data...
Jun 27 '08 #4
Harris Kosmidhs wrote:
floortje wrote:
>>
>>The $controller->Process() function loads the appropriate function
and sets the $view->todisplay string. Just to clarify that each
controller holds also the buisness model is the class. I don't use a
separate model class for each controller.

Why would you do that ? The beauty of a MVC structure is that you
seperate the model and view

This is how I would do it

class ProfessorModel extends Model{
// etc
}

class CourseModel extends Models{
//etc
}

yes I understand this. But what does Model consists of? I mean what are
the basic functionalities that can be extended?
Unless by ProfessorModel you mean a class that consists the name, id,
and general fields of professor master data...
Most people extend a database abstraction layer as their model base.
So they can make save, update an so on on the data.

You can also add logic that is common across your models

So you can think of it like this

class Model {

//so your model can load data he needs
protected function getById();
public function getByName();

//so model user can change the data
public function save();
public function delete();

}

class PersonModel extends Model {
public function getName()
public function getLastName()
public function getDayPlan()
}

class ClassModel() {
public function addStudent(Stud entModel $student);
public function removeStudent(S tudentModel $student);
public function getProfessor();
public function setProfessor(Pr ofessorModel $processor);
}

class ProfessorModel extends PersonModel {
public function getClasses()
public function addClass(ClassM odel $class,$timeSta rts,$duration);
public function removeClass(Cla ssModel $class);
}

class StudentModel extends PersonModel {
public function addNote($note, ClassModel $class);
public function kickOut();
public function graduate();

}

ect ect :)

If your models are well designed, and have good, consistent api, you
will have no trouble dealing with them inside controllers. And your
controllers will be easy to read and maintain

best regards
Piotr N
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1891
by: Santi | last post by:
Hi, If I am correct the MVC basics are: The primary goal is to decouple the model from the views and controller. - Model: Holds data and business logic. - View: represents data and queries the model. - Controller: Responds to user input, sends change notifications to the model and to the views.
0
2063
by: Brent Clements | last post by:
I have been trying to determine the best way to setup a directory structure for my homegrown MVC application. What do you guys suggest? I am thinking about doing the following: | +-- app
5
1379
by: -pb- | last post by:
Hi, We are developing an windows application and decided to use the MVC design pattern. We decided to use windows application due to varuous business processes which cannot be implemented in web very easily Now my problem is very specific. We have a main screen which shows some data called Main view. We have a controller calss which holds a reference to the object of Main view and
1
2437
by: Gigs_ | last post by:
Hi all! I have just finished my tkinter text editor, learning tkinter purpose. Now I want to learn canvas so I want to make my paint program, I think that this will be the best to do over model-view-controler pattern which I need to learn also. Is there any good tutorial for mvc in python or can someone explain me little bit about mvc? or maybe some code snippet in mvc, that will be nice.
3
1372
by: -pb- | last post by:
We are developing a Windows client using .NET 2.0 and C#. We have decided to use MVC based architechture due to its obvious advantages. This application shows data from database in a Grid. We want to add a functionality of Printing grid and export grid to XL sheet. I would like to know where will I have to code above functionalities? Should it be in view or controller? Any suggestion is well come.
1
1968
by: shapper | last post by:
Hi, I was checking the new ASP.NET MVC Preview 4 features and I found the following: var dataTokens = new RouteValueDictionary(); dataTokens.Add("namespaces", new HashSet<string>( new string { "MyApp.Blog.Controllers", "MyApp.Forum.Controllers",
0
1322
by: Maric Michaud | last post by:
Le Tuesday 16 September 2008 14:47:02 Marco Bizzarri, vous avez écrit : It is not about QT, it is about MVC. In MVC, code which implement the model should be completely ignorant of the libraries used for gui, and the gui part of the application shouldn't acces directly to your model logic. This why there is a third layer which abstract the logic of your datas and provide standard operation for the gui code. This third layer...
13
1417
by: Author | last post by:
I happened to see this asp.net MVC tutorial at http://www.asp.net/learn/mvc/tutorial-01-cs.aspx Indeed as the author says it is gonna look like classic ASP at the very beginning of this tutorial. I think form post with an action (which is classic asp style) like <form method="post" action="/Home/CreateNew">
3
1642
by: ChevronBoyde | last post by:
Hi All I am a systems architect that has been on a 3 year extended sabbatical from development and I am busy with a new project. I am designing a new event website and need some advice on some of the new architectures. There seems to be a lot of hype around MVC at the moment, but see we are still in beta. I fear for the Tag Soup I see unfolding and remember how MS pushed us away from that in the 90's. Are there any issues with AJAX in...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.