0

Now i am using PHP OOP Programming, without framework, I start to create a Blog Application. First i create a Bootstrap file then all cases should be handle through this, then i create a Handler class for handle the login and post classes, right now display the value in login handler class, then how to connect into view part.

3
  • Just wondering, why not using a framework? Commented May 24, 2011 at 14:03
  • Welcome to SO. There is very similar question: stackoverflow.com/questions/3824775/… Commented May 24, 2011 at 14:04
  • I think this might need some more detail Commented May 24, 2011 at 14:04

4 Answers 4

3

Basic idea to initialize your understanding :) if you want the view class to be more powerful, you need to develop it further.

view.php

<?php
class View {    
    function __construct($tpl) {
        include $tpl;
    }
}
?>

handler.php

<?php
class Handler {
    function __construct() {}
    function process($post) {
        echo $post;
    }
}
?>

bootstrap.php

<?php
require('view.php');
require('handle.php');

$view = new View('form.html');
$handler = new Handler();

if (isset($_POST['login'])) {
    $handler->process($_POST['username']);
}
?>
Sign up to request clarification or add additional context in comments.

Comments

0

Views should not be classes, views should be pieces of PHP and HTML or any other format that you'd like to output, which can than be invoked by a controller.

Comments

0

i think first understand the MVC in detail, then play with some existing frameworks, may be start with codeigniter, its simple to understand one get the details then create your own(if required!)

Comments

0

Generally you'd have a specific function or class that is told which view template to load, and it loads it. $view->loadTemplate('userHome.html'); or the like. This limits the scope of the variables accessible in the view to variables you specifically assign to it ($view->userName = 'fred';). So you'll need to make that function/class.

For example if you have a user profile view, it could look like this:

<div class='profile'>
   <img src='<?php echo $avatar; ?>'>
   <h1><?php echo $username; ?></h1>
   <table>
      <tr><th>Registration date:</th><td><?php echo $regdate; ?></td></tr>
      <tr><th>Lastlogin:</th><td><?php echo $logindate; ?></td></tr>
      <tr><th>Topics created:</th><td><?php echo $topics; ?></td></tr>
   </table>
</div>

and your controller could declare the variables and then include this view in the output.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.