bigjoe11a Posted January 16, 2011 Share Posted January 16, 2011 What I'm looking for is a sample that will show me how to setup a CMS using templates from a mysql database. I been looking on google.com and haven't fount any thing yet. I'm looking for a way on how to read the template from the database and then display it. Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/ Share on other sites More sharing options...
denno020 Posted January 16, 2011 Share Posted January 16, 2011 I don't understand what you want? Can you explain it better? Denno Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160081 Share on other sites More sharing options...
bigjoe11a Posted January 16, 2011 Author Share Posted January 16, 2011 I don't understand what you want? Can you explain it better? Denno Ok, I'll try. I'm tryibng to learn how to use templates from a mysql database. I want to know how to load them is and then display them. Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160086 Share on other sites More sharing options...
denno020 Posted January 16, 2011 Share Posted January 16, 2011 That doesn't help at all. With a CMS, what you do is create your page (as a php page), style it using all of your html as normal. You can get away with only creating one .php file, and have the content loaded into that php file from the database. The pages are effectively created dynamically, and loaded into your temple php file. If you don't already know how to do it, then you need to look into a free solution of wordpress or drupal, or you need to pay someone to do it. I don't think anyone will spend time to explain step by step how to do it in a forum like reply. Well I wouldn't anyway.. I'll help you gix problems as you come across them, but I won't tell you how to start, how to expand, and how to finish it.. Denno Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160087 Share on other sites More sharing options...
phpfreak Posted January 16, 2011 Share Posted January 16, 2011 Are you wanting to code your own or use something you can install and use? There's tons of CMS out there - wordpress, drupal, joomla that can get you started easily. Otherwise, if you want to code your own - I recommend getting started with the tutorials: http://www.phpfreaks.com/tutorials and read the forums and learn it from scratch. Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160089 Share on other sites More sharing options...
bigjoe11a Posted January 16, 2011 Author Share Posted January 16, 2011 That doesn't help at all. With a CMS, what you do is create your page (as a php page), style it using all of your html as normal. You can get away with only creating one .php file, and have the content loaded into that php file from the database. The pages are effectively created dynamically, and loaded into your temple php file. If you don't already know how to do it, then you need to look into a free solution of wordpress or drupal, or you need to pay someone to do it. I don't think anyone will spend time to explain step by step how to do it in a forum like reply. Well I wouldn't anyway.. I'll help you gix problems as you come across them, but I won't tell you how to start, how to expand, and how to finish it.. Denno Ok, Let me see is I can try and explain this. I'm not sure how too. Since I never did this kind of PHP scripting before. Ok, I have a web site that I been coverting over to classes. Ok. Well the idea is to get an idea about how to add templates to it. so that they can be loaded in and displayed. Sorry, I don't know of any other way to explain this too. you. It you don't know what a template is or how to load it so it can be display. Then I registered at the wrong web site. Joe Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160091 Share on other sites More sharing options...
bigjoe11a Posted January 16, 2011 Author Share Posted January 16, 2011 Are you wanting to code your own or use something you can install and use? There's tons of CMS out there - wordpress, drupal, joomla that can get you started easily. Otherwise, if you want to code your own - I recommend getting started with the tutorials: http://www.phpfreaks.com/tutorials and read the forums and learn it from scratch. If this is what I wanted I won't have all ready install this and I wouldn't be asking for help. I want to add this option to my own projects for my web site. Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160094 Share on other sites More sharing options...
denno020 Posted January 16, 2011 Share Posted January 16, 2011 This is the best PHP site that I've found. If you're not getting your answer, then maybe you're not asking the right question. You're not going to find help by insulting the forum. Denno Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160095 Share on other sites More sharing options...
bigjoe11a Posted January 16, 2011 Author Share Posted January 16, 2011 This is the best PHP site that I've found. If you're not getting your answer, then maybe you're not asking the right question. You're not going to find help by insulting the forum. Denno Denno, If I wanted to insult the forums section I never would have registered. The problem is that you should all ready know what a template is and what a mysql database is. The templates are loaded from the database and then display on the page. There's no other way to explain this. Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160096 Share on other sites More sharing options...
phpfreak Posted January 16, 2011 Share Posted January 16, 2011 Create a table, write the code to query the correct template and then output it.... That's kind of a lot of info for a forum topic - I recommend http://www.phpfreaks.com/tutorials to get started. Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160098 Share on other sites More sharing options...
bigjoe11a Posted January 16, 2011 Author Share Posted January 16, 2011 Create a table, write the code to query the correct template and then output it.... That's kind of a lot of info for a forum topic - I recommend http://www.phpfreaks.com/tutorials to get started. Not really, How ever maybe what I need is a advance PHP forums section. Any way thanks, I all ready tried there. and there's nothing about using templates in a mysql database or even how to display them Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160107 Share on other sites More sharing options...
QuickOldCar Posted January 16, 2011 Share Posted January 16, 2011 From what I get out of this you think you are supposed to save the entire template in a table or something? Make folders naming each of your different templates/themes, and make a table that just refers to the location of the folder for that theme. More like options can do in the table, for users, theme selection and so on. When the template is called for it would then look at mysql for which theme is selected by the file location, and then display the proper files from the correct theme folder for that user. Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160114 Share on other sites More sharing options...
bigjoe11a Posted January 16, 2011 Author Share Posted January 16, 2011 Yes, That's the idea. It's called a template system in PHP. This forum is in PHP and it has templates that are added to the mysql database that it reads and then displays that page. This text box is a template too. It reads it from a mysql database and then displays it so you can type in the text box. A template is bothing but HTML or PHP. Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160119 Share on other sites More sharing options...
trq Posted January 16, 2011 Share Posted January 16, 2011 This forums 'templates' are coded in php and stored on the filesystem like any other php file. Template systems are generally regarded as another layer that isn't needed. They just slow things down. Anyway, if you wanted to store 'templates' in a database, just go ahead and do so. They are in no way different to any other data. Mind telling us where exactly you are stuck? Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160121 Share on other sites More sharing options...
Pikachu2000 Posted January 16, 2011 Share Posted January 16, 2011 So where are you stuck, exactly? Post your current code and a description of the problems you're having, along with any errors that are being returned when the code executes. Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160122 Share on other sites More sharing options...
QuickOldCar Posted January 16, 2011 Share Posted January 16, 2011 So really you want to make your own template engine. Something like smarty, savant, dwoo and so on that uses classes. Well can always download theirs and see how they go about it. Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160128 Share on other sites More sharing options...
bigjoe11a Posted January 16, 2011 Author Share Posted January 16, 2011 So where are you stuck, exactly? Post your current code and a description of the problems you're having, along with any errors that are being returned when the code executes. Ok, That's where I'm stuck at, getting started. See the page I have set up doesn't have any thing like this. That's why I wanted to add it. So I can add options and disable and enable things right from the admin page. As for doing the settings. I think I can do that. As for the template setup. I'm all so lost. I do know that I have to make a table in the mysql database DB Name : mapnet Table Name : templates -->ID -->template_name -->text The template name will hold the name of the template to load. The text is what holds the template as HTML code. sample template_name : header text: <table cellspacing="0" cellpadding="0" border="0" width="100%" bgcolor="$THEME[bordercolor]"> <tr> <td> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr class="category"> <td><strong><font color="yellow">HEADER</font></strong></td> </tr> <tr> <td bgcolor="black"> <font>HEADER</font> </td> </tr> </table> </td> </tr> </table> The above HTML using a HTML Table is just a sample. Now the problem is. Is how to load this in so that it can be displayed. Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160141 Share on other sites More sharing options...
trq Posted January 16, 2011 Share Posted January 16, 2011 Now the problem is. Is how to load this in so that it can be displayed. You can't store php in a database and have it executed. Not efficiently or securlly anyway. So, place holder like this... $THEME[bordercolor] would need to be replaced with something like {bordercolor}. All you need to then is store the template in the database just like anything else. When you retrieve it, you simply replace your placeholders with there data. eg; $bordercolor = '#ddd'; $sql = "SELECT template_data WHERE template_name = 'foo' LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); $template = str_replace('{bordercolor}', $bordercolor, $row['template_data']); echo $template; } } That's the basics of it. You might end up needing to use preg_replace as replacements become more complex. I'll say it again though. Templates & template engines are IMO a waste of resources. Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160142 Share on other sites More sharing options...
bigjoe11a Posted January 16, 2011 Author Share Posted January 16, 2011 You have me all so lost. Let me show you some thing, Ok. I have 2 web sites and both of then use templates from a mysql database. In my forums section. I was reading threw some of the code. and well it doesn't match what you have or any where near it. The function below is what loads the templates. Ok. keep reading. function loadtemplates() { global $db, $table_templates; $num = func_num_args(); if ($num < 1) { echo 'Not enough arguments given to loadtemplates() on line: '.__LINE__; return false; } else { $namesarray = array_unique(array_merge(func_get_args(), array('header', 'css', 'error', 'footer', 'footer_querynum', 'footer_phpsql', 'footer_totaltime', 'footer_load'))); $sql = "'".implode("', '", $namesarray)."'"; $query = $db->query("SELECT name, template FROM $table_templates WHERE name IN ($sql)"); while ($template = $db->fetch_array($query)) { templatecache(X_CACHE_PUT, $template['name'], $template['template']); } } } Now the code below gets added to the page you need to use the templates on. So lets say if I have an index.php and I needed the templates for the index.php it would look some thing like this loadtemplates( 'template_header', 'template_navbar', 'template_rightcolumn', 'template_content', 'template_footer' ); This I hope will give you a better idea then it has with me. I just don't under stand any of this. Then again I been a PHP coder for over 4 years and I think it's about I learn this. Now in a folder called include. there will be a file called header.php. This is used for ?, I don't know. That I don't get, I'm still studying it. I think it loads the CCS and any thing else. that may be required. Like I said I still trying to under stand it and that's not easy. Joe Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160149 Share on other sites More sharing options...
bigjoe11a Posted January 16, 2011 Author Share Posted January 16, 2011 I just wanted to find out what happen to every one. Just to let you know I'm still waiting. Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160326 Share on other sites More sharing options...
KevinM1 Posted January 17, 2011 Share Posted January 17, 2011 I think at a fundamental level your design is flawed. Like Thorpe and phpfreak said, CMS' don't tend to store their views in a db. Rather, they're saved as simple .php files in the filesystem itself. These view files are constructed in such a way to expect certain data, which they parse and display. Views are supposed to be very simple. This is slightly different than templating as the code used to display the data is pure PHP, so there's no text replacement necessary. In other words, you'd have something like: <?php include('somemodel.php'); // your data ?> <!doctype html> <html lang="en-us"> <head> <title>Example</title> </head> <body> <table> <?php foreach ($model->data as $value) { echo "<tr><td>$value</td></tr>"; } ?> </table> </body> </html> Keep in mind, this is a very simple and canned example. What you should do is take a look at how the pros do it. Learn some MVC frameworks (Code Igniter, Kohana, Zend Framework), or a CMS or two (Joomla) to see how it's actually done. Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160705 Share on other sites More sharing options...
bigjoe11a Posted January 17, 2011 Author Share Posted January 17, 2011 Thanks Night, Your not getting the idea. I'm looking into adding template system to the project that I'm working on how. See a Template can not be a PHP page. Ok, A template is all nothing but HTML with some CSS. Like using front page. You would use front page to create a form. Or a HTML page. Then you would insert that into a mysql database. and Then you would display that form when you needed it. This option is added in all types of forums Like XMB, SMF and many others too. I'm sorry there is no other way to explain this so you can under stand. If your run a forums section. In the Admin Section. There should be an option to create, edit and delete Templates. Try looking at that if you have that option Joe Quote Link to comment https://forums.phpfreaks.com/topic/224578-cms-using-template-from-a-mysql-database/#findComment-1160824 Share on other sites More sharing options...
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.