jimfog Posted August 23, 2012 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? Link to comment Share on other sites More sharing options...
birbal Posted August 23, 2012 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 Link to comment Share on other sites More sharing options...
jimfog Posted August 23, 2012 Author Share Posted August 23, 2012 Is it easy to write a code example so I can grasp better this "template logic"? Thanks in advance. Link to comment Share on other sites More sharing options...
birbal Posted August 23, 2012 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 Link to comment Share on other sites More sharing options...
jimfog Posted August 24, 2012 Author Share Posted August 24, 2012 So Smarty is a template engine, not a framework? 1 Link to comment Share on other sites More sharing options...
birbal Posted August 24, 2012 Share Posted August 24, 2012 yes smarty is template engine. Link to comment Share on other sites More sharing options...
niche Posted August 24, 2012 Share Posted August 24, 2012 birbal, what's the difference between a template engine and a framework? Link to comment Share on other sites More sharing options...
birbal Posted August 24, 2012 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 Link to comment Share on other sites More sharing options...
niche Posted August 24, 2012 Share Posted August 24, 2012 Great explanation bribal. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now