catch e exception? in the class or return the error in the function like me
Printable View
catch e exception? in the class or return the error in the function like me
You can also use Smarty.
use twig, your template will be cleaner and readable
stop telling him to use anything, he wants his own system. the best way to improve programming skills.
but i would suggest to check some existing tpl systems to understand the procedure.
The most efficient approach is having the div elements ready; hide the div containing the error message in the html template and activate it by replacing the css display value to block through the template class in your PHP script:
login.php
login.tpl.phpPHP Code:$thisTemplate->set("ErrorLogin", "none");
if(login) $thisTemplate->set("ErrorLogin", "block");
That way you reduced the html involved within your PHP script to minimal.PHP Code:<!-- HTML -->
<div style='display: [@ErrorLogin];'>
An error has occured while attempting to login...
</div>
<!-- END HTML -->
useless method if you want to print out detailed error messages, although dont send more html than u need for the view to the client, always. (I would only do that method if i check anything with javascript (so the page wont reload at all).
to prevent the use of html inside of php functions (on larger dynamic content), i would rather use more than one tpl file. you could write a error.tpl that will be included on any error, and use a {ERROR} mark inside the error.tpl to put the detailed error message in it.
You seem to barely know what you're talking about, I have to say.
It depends what sort of details you're talking about, as far as anything goes the technique can be applied sufficiently.
The script can be tailored to suit pretty much any details you want to output to the tpl file
PHP Code:$thisTemplate->set("ErrorLogin", "none");
if(!login) {
$thisTemplate->set("ErrorLogin", "block");
$thisTemplate->set("ErrorDetail", "An error has occured");
$thisTemplate->set("ErrorDate", date("Y-m-d"));
}
PHP Code:<!-- HTML -->
<div style='display: [@ErrorLogin];'>
[@ErrorDetail] - [@ErrorDate]
</div>
<!-- END HTML -->
i kno what im talking about, but i was more focusing on phpbb's concept to handle tpl files.
(we currently talking about 2 different things ive to realize, but for my part, i would never send anything to a tpl file to let it print out. i would rather scan the tpl and replace marks.)
your example still sends several html lines (hidden divs) that arent neccessary if there is no error.
the only reason why i would print out a hidden div container is when i expect the div gets visible by any action the user does on my page without any reload (e.g. javascript).
however, about the dynamic content i agree with you.
Heres how I did it using my tpl system:
PHP Code:<?php
/*==========================================================================\
| LeightCMS - Content Management System for Habbo Hotel Private Servers |
| Compatible with PhoenixEmulator 3.0 (+ higher builds) |
| ==========================================================================|
| Revision: 1 Copyright (c) Livar Shekhani Build: 0.2 |
| My thanks fly to: Jospiek, Jonteh, and Kryptos! |
| ==========================================================================|
| Attention: If any bugs occur contact Livar on RaGEZONE |
\==========================================================================*/
//Running some required statementS
include 'leight.php';
//Checking if the user is Logged in?
if($users->IsLoggedIn())
{
Header("Location: ./me.php");
}
//Adding some Parameters!
$tpl->AddParam("page_title", "Login");
$tpl->AddParam("login_error", "Login below!");
if(isset($_POST["login_username"]) && isset($_POST["login_password"]))
{
$username = $_POST['login_username'];
$password = $app->passwordHash($_POST['login_password']);
$query = $db->prepare("SELECT * FROM `users` WHERE username = '$username'")->execute();
if($query->num_rows() == 1)
{
$query_login = $db->prepare("SELECT `password` FROM `users` WHERE username = '$username'")->execute();
$correct = $query_login->result();
if($correct == $password)
{
$_SESSION['Leight_Username'] = $username;
Header("Location: me.php");
}
else
{
$tpl->AddParam("login_error", "Invalid password combination!");
}
}
else
{
$tpl->AddParam("login_error", "Username does not exist!");
}
}
//Add our Page
$tpl->AddTemplate('index');
?>
And you know that posting this code is completely useless without the template class, right?
His template system is obviously a function with str_replace, so that must work?
That script isn't very secure..
Also, How can I use this or work from it without your db or mysql class? You seem to have it sorted out some strange way..maybe I could just use a query instead of renaming 12 functions :P:.
Thanks, But I don't think I can use this. I get the idea, I can do it from here. Thanks
also:Code:<?php
/*==========================================================================\
| LeightCMS - Content Management System for Habbo Hotel Private Servers |
| Compatible with PhoenixEmulator 3.0 (+ higher builds) |
| ==========================================================================|
| Revision: 1 Copyright (c) Livar Shekhani Build: 0.2 |
| My thanks fly to: Jospiek, Jonteh, and Kryptos! |
| ==========================================================================|
| Attention: If any bugs occur contact Livar on RaGEZONE |
\==========================================================================*/
//So the page doesn't load directly!
if(!DEFINED('SECURITY')) { die ('Direct Loading is Forbidden!'); }
//Construct our Classes
class Template
{
//An array to hold our values
public $values = array();
//So we can use our parameters on tpl files
function AddParam($key, $value)
{
$this->values[$key] = $value;
}
//So we can add our templates in our php files
function AddTemplate($template)
{
global $app;
if(!file_exists("./includes/tpl/$template.tpl"))
{
$app->showError('1', '1');
}
$output = file_get_contents("./includes/tpl/$template.tpl");
//Filter our Params
foreach($this->values as $key => $value)
{
$output = str_ireplace('{' . $key . '}', $value, $output);
}
//Star outbuffering and Echo our Page
ob_start();
echo $output;
ob_flush();
}
}
?>
https://github.com/Livar/LeightCMS/
includes mysqli class (works amazing and lightweight), tpl system, php oop ect