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.
-
Just wondering, why not using a framework?BenMorel– BenMorel2011-05-24 14:03:39 +00:00Commented May 24, 2011 at 14:03
-
Welcome to SO. There is very similar question: stackoverflow.com/questions/3824775/…user680786– user6807862011-05-24 14:04:12 +00:00Commented May 24, 2011 at 14:04
-
I think this might need some more detailmartynthewolf– martynthewolf2011-05-24 14:04:26 +00:00Commented May 24, 2011 at 14:04
4 Answers
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']);
}
?>
Comments
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.