jimfog 31 Posted August 23, 2012 Report Share Posted August 23, 2012 I have created a function that holds/outputs links such as logout, sign in... etc.Here is it: function output_header($username=false) {?><div id="header"> <ul id="headelem"> <li><?php echo $username ?></li> <li><a href="contact.php">Επικοινωνία</a></li> <li><a href="day.php">Calendar</a></li> <li><a href="login.php">Είσοδος</a></li> <li><a href="register_form.php">Εγγραφή</a></li> <li><a href="logout.php">Αποσύνδεση</a></li> </ul></div><?php} When called, the above li items will appear in the browser. My aim though, is that I want the logout link appearing ONLY after the user has signed(that is the logical thing to do, anyway) A scheme I have though is sth like that: function output_header($username=false,$logout=false) {?><div id="header"> <ul id="headelem"> <li><?php echo $username ?></li> <li><a href="contact.php">Επικοινωνία</a></li> <li><a href="day.php">Calendar</a></li> <li><a href="login.php">Είσοδος</a></li> <li><a href="register_form.php">Εγγραφή</a></li> echo $logout </ul></div><?php} Where logout will be replaced by the li item, which will be a string as an argument of the function. What do you think about the above? Do you have to propose anything better? Quote Link to post Share on other sites
birbal 168 Posted August 23, 2012 Report Share Posted August 23, 2012 (edited) I would not use a function just to print something. It will make it harder to maintain if you mix codes with visual representation and logics.also it makes it little messy when you look. You can just make a template file of header for authenticated user and inject them (include()) if user are logged in. you can also make another template for unregister user and inject them same way when user is not logged in. Edited August 23, 2012 by birbal Quote Link to post Share on other sites
jimfog 31 Posted August 23, 2012 Author Report Share Posted August 23, 2012 Is it easy to write a code example so I can grasp better this "template logic"? Thanks in advance. Quote Link to post Share on other sites
birbal 168 Posted August 23, 2012 Report Share Posted August 23, 2012 there is several template engines. popular is smarty. if you see this i am sure you will get the idea of templates. though i don't like template engines as php itself is template engine and in some points it feels like they are creating another language based on php which adds a processing layer too. 1 Quote Link to post Share on other sites
jimfog 31 Posted August 24, 2012 Author Report Share Posted August 24, 2012 So Smarty is a template engine, not a framework? 1 Quote Link to post Share on other sites
birbal 168 Posted August 24, 2012 Report Share Posted August 24, 2012 yes smarty is template engine. Quote Link to post Share on other sites
niche 140 Posted August 24, 2012 Report Share Posted August 24, 2012 birbal, what's the difference between a template engine and a framework? Quote Link to post Share on other sites
birbal 168 Posted August 24, 2012 Report Share Posted August 24, 2012 (edited) template engine is a system which uses templates (in this case html template) to generate pages. templates makes an outline of the document and the changing data is inserted into placeholders. Framework is some sort of library build around some well worked design patterns maintaining some sort of relation on each components to get done certain jobs efficiently. common development works is moved to framework to enhance speed of development process. eg an template engine could be a part of framework. (an MVC framework may use template engines for Views) Edited August 24, 2012 by birbal 1 Quote Link to post Share on other sites
niche 140 Posted August 24, 2012 Report Share Posted August 24, 2012 Great explanation bribal. Thanks. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.