Hey everybody. I'm trying to create a content management system. I've made one before but it wasn't themable... I guess you could say? Meaning you couldn't make different themes for it it. The new content management system I'm making now, I want it to be able to do that but I don't have a clue on how to go about this so I basically just am wondering what all I should learn about PHP to be able to do this? I've looked at other CMS's and I notice in the main index.php it's including a file. For instance, I looked at this one CMS called Concrete5. The index file is <?php require('concrete/dispatcher.php'); Code (markup): What does the dispatcher.php file mostly do? Also another CMS I checked called CMSimple, they use this on their index.php file: <?php include('./cmsimple/cms.php'); ?> Code (markup): So they all do the same thing pretty much.. I'm just wondering what all goes on in that file that's being included... I've looked but it's just huge. This may be a stupid question but I just don't really have a clue on what I should do or learn.
Those file will do whatever the person wants them to do, the names they have is preference ..as in, you could name them anything you want. So say you have a HTML page that will require('say_hello.php') and then your HTML page calls that, and in the say_hello.php if you have echo "Hello" ; Then you see whatever is in the say_hello.php file is being called. It could also be a function or a whole lot of functions and etc. It can be whatever you want it to be. The reason they require it is so that they can probably use it again.. for example they might have 10 other website pages that want to call say_hello.php , and rather than writing the code 10 more times, they have it in a seperate file that gets called to each page. In PHP , many times you'll write a really cool set of functions and you can save it and use it as like a plug-in. So then when youre making a new site, you can use all the basics functions you already created ..it speeds everything up AND you know exactly what it does from using it before. Make your scripts, make them labeled example // This line does such and such. Make your scripts flexible so that you can move stuff around and add stuff in. Some basics examples are for things such as entire login and registry systems, shopping carts/ e-commerce, Forms, etc Pretty much for everything .. a decent PHP programmer will have a library of code where they can pull out scripts for anything and everything and hook them into any website. Thats why you should make your code labeled so that you will know what the heck you wrote it for when you wrote it. (think 3 to 5 years later when you had some idea that worked great ..but that much time later yorue staring at it wondering = "wtf was this for?!"
Hi, As someone with a lot of experience in creating CMS systems, the best hint I can give you this this: Take no notice of what others are doing. Every CMS is unique. The best thing you could ever do to learn how to make a CMS system is simply experimenting with different things. To make a CMS ready for skins, you should use templates. I mentioned this in another thread, but Smarty is perfect for doing so. It allows you to keep everything separate from the PHP code.
I tried smarty but I was so confused by it... I'll try it again though and see what I can do with it...
Smarty's actually very simple to install, as I'll show you now: First, you need to upload the Smarty files. I always put my Smarty files in a classes directory. I assign classes to a constant, and of course the file types. require_once classes . 'Smarty.class' . php; PHP: We must then activate the class, like so: // -> Activate the class. $Template = new Smarty ( ); // -> Set the required directories. $Template -> template_dir = templates . 'blocks'; $Template -> compile_dir = templates . 'templates_c'; $Template -> cache_dir = templates . 'cache'; $Template -> config_dir = templates . 'configs'; PHP: Create a constant for a /template/ directory. Inside the template folder, create a blocks, templates_c, cache and configs directory. Your templates go into the "blocks" directory, within separate template blocks. In order to keep everything neat, you should create constants for every template block. For my header and footer template, I create a folder structure like this: templates -> blocks -> overall -> overall_header.tpl templates -> blocks -> overall -> overall_footer.tpl Assign a constant (such as blocks_overall) to the /overall/ directory, rather than hardcoding the name. Before I send a template, I might want to assign a variable. If, for example, I want to assign the web address of a particular website to Smarty, I'd do this: $Template -> assign ( 'Site', 'http://' . $_SERVER [ 'HTTP_HOST' ] ); PHP: With my setup, when searching for a template, Smarty automatically starts from the blocks directory. If for example I wanted to call the overall_header.tpl template, I'd do this: $Template -> display ( blocks_overall . 'overall_header' . tpl ); PHP: Lastly, if I want to echo my website variable on the overall_header.tpl (this isn't what I'd do with the file, but for illustration purposes...), I'd do this: Hello, you're visiting {$Site}! Code (markup): I hope that helps you.
Thanks for helping me CodeSpire but that doesn't help me at all. I don't know what you mean by "Create a constant for a /template/ directory. Inside the template folder, create a blocks, templates_c, cache and configs directory."
This is how you create a constant. It's sort of like a variable, but with no $, and it can't be unset once it's set. define ( 'root', './' ); // + Root folder. define ( 'templates', root . 'template/' ); // + Template folder PHP: Hopefully that'll help.
Well I know what a constant is but I just don't know where I'm supposed to do all this that you're saying. What do you mean by "I always put my Smarty files in a classes directory. "
Often times you'll only see 1 line in the index.php for security puprposes. Those scripts usually have the option to have all other php files outside of the webroot. The index.php file simply handles all incoming requests and then dispatches them to the correct method. It also allows you to execute common functionality before and/or after a specific method.
When you download Smarty, you'll get a bunch of files in the zip, right? These are what go in a classes directory.
Codespire, How do you feel about Drupal CMS? I've been working on it for about a year now, have the background of a linux admin who can throw around php snippets. I find this CMS is very elastic but a bitch to teach endusers on.
Personally I'm not a fan, that being one of the reasons. I prefer to write a CMS from scratch for a client. There are hundreds of different uses for Drupal. Even my local train company uses it for selling tickets. O_O It's more than most people need really, even though it's good enough from the point of view of the developer. That's not what the end user is paying for, though.