Logic/Presentation separation
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
3
down vote
favorite
I have the following code:
<div id="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-lg-11">
<div id="featured_users></div>
</div>
</div>
<div class="row">
<div class="col-lg-11">
<h1> Visitors </h1>
<?php while($visitor = $visitors->fetch_object()) ?>
<?php $time = $visitor->time; ?>
<?php $visitor = new User($visitor->viewer_id); ?>
<?php
$this->insert('visitors/visitor',[
'id' => $visitor->id,
'profile_image' => $visitor->profile_image,
'name' => $visitor->name,
'time' => $time->convertToAgo($time);
]);
?>
<? ?>
</div>
</div>
</div>
</div>
I've been trying to think of a way to better separate the logic from the presentation. I'm already using a template engine (Plates, native php templating), this code is from one of my template files. However, as it stands, it won't easy for anyone who has no understanding of PHP to edit my template file without getting confused with all of the PHP code.
Can anyone help me with ideas on the way to do this logic/presentation separation?
php template
add a comment |Â
up vote
3
down vote
favorite
I have the following code:
<div id="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-lg-11">
<div id="featured_users></div>
</div>
</div>
<div class="row">
<div class="col-lg-11">
<h1> Visitors </h1>
<?php while($visitor = $visitors->fetch_object()) ?>
<?php $time = $visitor->time; ?>
<?php $visitor = new User($visitor->viewer_id); ?>
<?php
$this->insert('visitors/visitor',[
'id' => $visitor->id,
'profile_image' => $visitor->profile_image,
'name' => $visitor->name,
'time' => $time->convertToAgo($time);
]);
?>
<? ?>
</div>
</div>
</div>
</div>
I've been trying to think of a way to better separate the logic from the presentation. I'm already using a template engine (Plates, native php templating), this code is from one of my template files. However, as it stands, it won't easy for anyone who has no understanding of PHP to edit my template file without getting confused with all of the PHP code.
Can anyone help me with ideas on the way to do this logic/presentation separation?
php template
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I have the following code:
<div id="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-lg-11">
<div id="featured_users></div>
</div>
</div>
<div class="row">
<div class="col-lg-11">
<h1> Visitors </h1>
<?php while($visitor = $visitors->fetch_object()) ?>
<?php $time = $visitor->time; ?>
<?php $visitor = new User($visitor->viewer_id); ?>
<?php
$this->insert('visitors/visitor',[
'id' => $visitor->id,
'profile_image' => $visitor->profile_image,
'name' => $visitor->name,
'time' => $time->convertToAgo($time);
]);
?>
<? ?>
</div>
</div>
</div>
</div>
I've been trying to think of a way to better separate the logic from the presentation. I'm already using a template engine (Plates, native php templating), this code is from one of my template files. However, as it stands, it won't easy for anyone who has no understanding of PHP to edit my template file without getting confused with all of the PHP code.
Can anyone help me with ideas on the way to do this logic/presentation separation?
php template
I have the following code:
<div id="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-lg-11">
<div id="featured_users></div>
</div>
</div>
<div class="row">
<div class="col-lg-11">
<h1> Visitors </h1>
<?php while($visitor = $visitors->fetch_object()) ?>
<?php $time = $visitor->time; ?>
<?php $visitor = new User($visitor->viewer_id); ?>
<?php
$this->insert('visitors/visitor',[
'id' => $visitor->id,
'profile_image' => $visitor->profile_image,
'name' => $visitor->name,
'time' => $time->convertToAgo($time);
]);
?>
<? ?>
</div>
</div>
</div>
</div>
I've been trying to think of a way to better separate the logic from the presentation. I'm already using a template engine (Plates, native php templating), this code is from one of my template files. However, as it stands, it won't easy for anyone who has no understanding of PHP to edit my template file without getting confused with all of the PHP code.
Can anyone help me with ideas on the way to do this logic/presentation separation?
php template
asked Feb 8 at 23:55
Ivan Grigorov
255
255
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
<?php
// this code goes into your controller
$visitor_rows = ;
// lets do all the hard work here
while($visitor = $visitors->fetch_object())
$time = $visitor->time;
$visitor = new User($visitor->viewer_id);
$visitor_rows = [
'id' => $visitor->id,
'profile_image' => $visitor->profile_image,
'name' => $visitor->name,
'time' => $time->convertToAgo($time),
]);
// the template only needs to know about $visitor_rows now
?>
<!-- the template is now a lot simpler to follow and understand -->
<!-- i prefer the foreach: endforeach; loop syntax when embedded in html -->
<div id="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-lg-11">
<div id="featured_users"></div>
</div>
</div>
<div class="row">
<div class="col-lg-11">
<h1> Visitors </h1>
<?php foreach ($visitor_rows as $row): ?>
<?= $this->insert('visitors/visitor', $row) ?>
<?php endforeach ?>
</div>
</div>
</div>
</div>
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
<?php
// this code goes into your controller
$visitor_rows = ;
// lets do all the hard work here
while($visitor = $visitors->fetch_object())
$time = $visitor->time;
$visitor = new User($visitor->viewer_id);
$visitor_rows = [
'id' => $visitor->id,
'profile_image' => $visitor->profile_image,
'name' => $visitor->name,
'time' => $time->convertToAgo($time),
]);
// the template only needs to know about $visitor_rows now
?>
<!-- the template is now a lot simpler to follow and understand -->
<!-- i prefer the foreach: endforeach; loop syntax when embedded in html -->
<div id="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-lg-11">
<div id="featured_users"></div>
</div>
</div>
<div class="row">
<div class="col-lg-11">
<h1> Visitors </h1>
<?php foreach ($visitor_rows as $row): ?>
<?= $this->insert('visitors/visitor', $row) ?>
<?php endforeach ?>
</div>
</div>
</div>
</div>
add a comment |Â
up vote
1
down vote
accepted
<?php
// this code goes into your controller
$visitor_rows = ;
// lets do all the hard work here
while($visitor = $visitors->fetch_object())
$time = $visitor->time;
$visitor = new User($visitor->viewer_id);
$visitor_rows = [
'id' => $visitor->id,
'profile_image' => $visitor->profile_image,
'name' => $visitor->name,
'time' => $time->convertToAgo($time),
]);
// the template only needs to know about $visitor_rows now
?>
<!-- the template is now a lot simpler to follow and understand -->
<!-- i prefer the foreach: endforeach; loop syntax when embedded in html -->
<div id="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-lg-11">
<div id="featured_users"></div>
</div>
</div>
<div class="row">
<div class="col-lg-11">
<h1> Visitors </h1>
<?php foreach ($visitor_rows as $row): ?>
<?= $this->insert('visitors/visitor', $row) ?>
<?php endforeach ?>
</div>
</div>
</div>
</div>
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
<?php
// this code goes into your controller
$visitor_rows = ;
// lets do all the hard work here
while($visitor = $visitors->fetch_object())
$time = $visitor->time;
$visitor = new User($visitor->viewer_id);
$visitor_rows = [
'id' => $visitor->id,
'profile_image' => $visitor->profile_image,
'name' => $visitor->name,
'time' => $time->convertToAgo($time),
]);
// the template only needs to know about $visitor_rows now
?>
<!-- the template is now a lot simpler to follow and understand -->
<!-- i prefer the foreach: endforeach; loop syntax when embedded in html -->
<div id="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-lg-11">
<div id="featured_users"></div>
</div>
</div>
<div class="row">
<div class="col-lg-11">
<h1> Visitors </h1>
<?php foreach ($visitor_rows as $row): ?>
<?= $this->insert('visitors/visitor', $row) ?>
<?php endforeach ?>
</div>
</div>
</div>
</div>
<?php
// this code goes into your controller
$visitor_rows = ;
// lets do all the hard work here
while($visitor = $visitors->fetch_object())
$time = $visitor->time;
$visitor = new User($visitor->viewer_id);
$visitor_rows = [
'id' => $visitor->id,
'profile_image' => $visitor->profile_image,
'name' => $visitor->name,
'time' => $time->convertToAgo($time),
]);
// the template only needs to know about $visitor_rows now
?>
<!-- the template is now a lot simpler to follow and understand -->
<!-- i prefer the foreach: endforeach; loop syntax when embedded in html -->
<div id="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-lg-11">
<div id="featured_users"></div>
</div>
</div>
<div class="row">
<div class="col-lg-11">
<h1> Visitors </h1>
<?php foreach ($visitor_rows as $row): ?>
<?= $this->insert('visitors/visitor', $row) ?>
<?php endforeach ?>
</div>
</div>
</div>
</div>
edited Feb 9 at 7:42
Your Common Sense
2,435524
2,435524
answered Feb 9 at 6:36
bumperbox
1,800614
1,800614
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f187134%2flogic-presentation-separation%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password