Jump to content

What is a solution?


jamesbrauman

Recommended Posts

Hey everyone!

I have a (very) limited knowledge of CMS's in general, and do not even know how this type of thing would work. What I am doing with my site at the moment is having the markup for each page in the PHP file, which works fine, except when I want to change some markup across all the pages.. it means I have to go through 100+ php files and find and change one or two lines or markup, which is very annoying. I thought I might invest the time to find a solution.

 

Due to the nature of my site however, the content is not static. I have a sidebar which lists the latest and highest rated content, and is generated through PHP which contacts my MYSQL database. This sidebar would need to be part of the CMS. Php for this looks kinda like this:

<?php
					$result = mysql_query("select jokedata.id as joke_id, jokedata.joketitle as joke_title, sum(ratings.rating) / count(ratings.rating) as average from jokedata inner join ratings on ratings.content_type = 'joke' and ratings.relative_id = jokedata.id group by jokedata.id order by average desc limit 5");
					for ($i = 1; $i <= 5; $i++) {
						$row = mysql_fetch_array($result);
						$current_id = $row['joke_id'];
						$current_title = $row['joke_title'];
						$current_title = html_entity_decode(ucwords(strtolower($current_title)));
						echo "<li>&#187;  <a href=\"http://www.funpunks.com/funny_jokes/viewjoke.php?id=$current_id\">$current_title</a></li>";
					}
				?>

I have about 5 of those blocks on my sidebar.

 

As well as this, the content on nearly every page is dynamically generated. I know that some CMS's work a little like this:

<?php
  $this_page = mytemplate->load();
  $content = "Lorem ipsum tota...";
  $this_page = mytemplate->insertcontent($this_page, $content);
  mytemplate->display($this_page);
?>

Or something along those lines. But my 'content' would need to be something like:

<?php
  $content = "
  <?php
  $result = mysql_query("SELECT * FROM jokedata");
  while ($row = mysql_fetch_array($result)) {
    ...
  }
  "
?>

Which doesnt make sense, because then the php would have to be executed twice.

 

So basically what I am asking is, what is a good solution to maintain CSS in one file, markup in another, and dynamically generated content in another?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/128656-what-is-a-solution/
Share on other sites

Huge question. But in a simple answer, I would say MVC.

 

The MVC design pattern is designed to keep your data (Model) seperate from your logic (Controller) and your output (View).

 

Maybe if you take a look at how some of the MVC frameworks around impliment there views you might get some ideas. Zend_View might get you started.

Link to comment
https://forums.phpfreaks.com/topic/128656-what-is-a-solution/#findComment-666797
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.