Now that we have a basic framework (see Part 1 and Part 2 of this series), we can start thinking about integrating the design with a PHP framework. Now, we'll focus on the front-end design, including how to easily "skin" our new framework.
How it all fits together
Step 1: What is needed for our framework front-end design
Main content area, we call it
#content
One or two columns of content are not as important as
#content
Some tabular data.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>{pagetitle}</title> <meta name="description" content="{metadesc}" /> <meta name="keywords" content="{metakey}" /> <style type="text/css" title="Default page style" media="screen"><!--@import "skins/fmwk/style.css";--></style> <link rel="icon" href="favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> </head> <body>
You can change the document type to match, you can even define it in the settings of every website created using the framework, and being able to change the document type is also useful
lang
. It can be useful to define the stylesheet as a setting as well, which we will cover in a future tutorial.
Additionally, meta description and meta key attributes can be hard-coded into the skin of every website you create, but it is wise to
provide a different set of descriptions and keywords for each pageto prevent Broken pages appear in Google's supplemental index. The {pagetitle} placeholder will be used to insert the title of the current page into the template.
<div id="wrapper"> <div id="header"> </div> <div id="content"> </div><!--/content--> <div id="column"> </div><!--/column--> <div id="footer"> </div><!--/footer--> </div><!--/wrapper--> </body> </html>
Step 2: Basic Content
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>{pagetitle}</title> <meta name="description" content="{metadesc}" /> <meta name="keywords" content="{metakey}" /> <style type="text/css" title="Default page style" media="screen"><!--@import "skins/fmwk/style.css";--></style> <link rel="icon" href="favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> </head> <body> <div id="wrapper"> <div id="header"> <h2><a href="#" title="Website name">Website name</a></h2> </div> <div id="content"> <h1>{pagetitle}</h1> <img class="photo" src="photo.jpg" alt="Photo test" /> <p> Lorem ipsum dolor sit amet, <strong>consectetuer adipiscing elit</strong>. Quisque urna augue, fringilla quis, pulvinar non, feugiat in, pede. Curabitur vitae pede. Cras vehicula varius tellus. Sed consequat, enim tristique euismod volutpat, <em>tellus magna aliquet risus</em>, id aliquet eros metus at purus. </p> <h2>Secondary heading</h2> <p> Aliquam dictum, nibh eget <a href="#" title="Test link">ullamcorper condimentum</a>, magna turpis placerat pede, tempor facilisis tortor urna commodo turpis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Cras luctus cursus velit. Nullam imperdiet turpis. </p> <h3>Tertiary heading</h3> <table> <tr> <th>Heading</th> <td>Data</td> </tr> <tr> <th>Heading</th> <td>Data</td> </tr> </table> <p> <img src="image.jpg" alt="Generic image" /> Cras a eros eget lorem fermentum malesuada. Phasellus condimentum libero vel lacus. Donec lectus nisl, adipiscing malesuada, sodales tincidunt, sagittis vitae, lacus. Proin nec pede. Maecenas adipiscing adipiscing risus. </p> </div><!--/content--> <div id="column"> <ul> <li>List item</li> <li>List item</li> <li>List item</li> </ul> <ol> <li>List item</li> <li>List item</li> <li>List item</li> <li>List item</li> </ol> </div><!--/column--> <div id="footer"> <p> © Website name, 2008. </p> </div><!--/footer--> </div><!--/wrapper--> </body> </html>
Now the content is ready for some simple styling.
Step 3: Basic Style
body, * { margin: 0; padding 0; }
We'll spend some time styling the body element and making sure links in the document are highlighted appropriately:
body { background: #FFF; color: #000; font-family: "helvetica", "arial", "verdana", sans-serif; font-size: 62.5%; } a, a:active, a:link { color: #1A64AC; text-decoration: underline; } a:visited { color: #0D2F4F; }
Next, we'll center our design in #wrapper divs and assign each div a faint border so we can see them when styling.
#wrapper { margin: 0 auto; width: 950px; } <br /> #wrapper, #header, #content, #column, #footer { border: 1px #DDD solid; }
While the CSS above does not centralize this design in Internet Explorer 6, the CSS has been kept basic for maximum flexibility. With a little more CSS, we almost have a complete
skeleton design for the front end of the framework - all that's left is some simple positioning:
#column, #content {
float: left;
font-size: 125%;
padding: 5px;
}
#column {
width: 200px;
}
#content {
margin-left 5px;
width: 725px;
}
#header, #footer {
clear: both;
}
#column img, #content img { border: 2px #DDD solid; float: left; margin: 0 5px 0 10px; } img.photo { background: #DDD; float: right !important; padding: 25px 2px; }
What we are left with at this stage is a simple website layout that we can use as the basis for a PHP framework front-end:
Of course, for extra flexibility it might be useful to allow 2 columns of content by default, which can be done by adding more XHTML and CSS.
Step 4: Template from XHTML
suitable for our PHP framework. To do this, we need to split the XHTML into three templates: header, main template, and footer. Due to the way the template system is structured, pages can be generated from any number of templates, but it is recommended to use at least header, footer and main templates, which means that, in general, we only need to copy and change if we want to create a structure slightly If there are different new pages, use the main template file. Header template for PHP framework (skins/default/templates/header.tpl.php)
part:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>{pagetitle}</title> <meta name="description" content="{metadesc}" /> <meta name="keywords" content="{metakey}" /> <style type="text/css" title="Default page style" media="screen"><!--@import "style.css";--></style> <link rel="icon" href="favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> </head> <body> <div id="wrapper"> <div id="header"> <h2><a href="#" title="Website name">Website name</a></h2> </div>
主模板应包括包含主要内容和列中任何内容的 div。我们现在可以为此内容插入占位符,而不是复制我们用来设置段落、有序列表和表格等元素样式的虚拟文本,占位符将根据内容所在的位置进行更新。
占位符内容是:
<div id="content"> <h1>{pagetitle}</h1> {maincontent} </div><!--/content--> <div id="column"> <!-- START rcolumn --> <h2>{btitle}</h2> {bcontent} <!-- END rcolumn --> </div><!--/column-->
最后,剩余的 XHTML 放入页脚文件中,该文件关闭 XHTML 文档和正文部分。我们通常使用它来在我们的网站上包含版权声明和“网页设计者”链接。
<div id="footer"> <p> © Website name, 2008. </p> </div><!--/footer--> </div><!--/wrapper--> </body> </html>
对于我们系列中 PHP 的中断表示歉意,但为我们的框架和使用它的应用程序构建皮肤格式的相关模板非常重要。 PHP5 框架开发系列中的第 4 部分将介绍基本的安全注意事项和基本的身份验证处理程序,然后我们将继续创建内容管理模型,并在第 5 部分中研究模型如何组合在一起。该系列中的内容:发送电子邮件、扩展我们的框架以及以创新的方式记录用户事件流。
The above is the detailed content of Building a PHP5 framework: Part 3. For more information, please follow other related articles on the PHP Chinese website!