Website development with PyroCMS

104 39 0
Website development with PyroCMS

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

www.it-ebooks.info Website Development with PyroCMS Quickly and efficiently develop and deploy impressive websites with PyroCMS Zachary Vineyard BIRMINGHAM - MUMBAI www.it-ebooks.info Website Development with PyroCMS Copyright © 2013 Packt Publishing All rights reserved No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews Every effort has been made in the preparation of this book to ensure the accuracy of the information presented However, the information contained in this book is sold without warranty, either express or implied Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals However, Packt Publishing cannot guarantee the accuracy of this information First published: October 2013 Production Reference: 1081013 Published by Packt Publishing Ltd Livery Place 35 Livery Street Birmingham B3 2PB, UK ISBN 978-1-78328-223-4 www.packtpub.com Cover Image by Aniket Sawant (aniket_sawant_photography@hotmail.com) www.it-ebooks.info Credits Author Project Coordinator Zachary Vineyard Esha Thakker Proofreader Reviewers Samantha Lyon Stephen Coogan Kefeng Deng Indexer Tejal Soni Acquisition Editor Amarabha Banerjee Commissioning Editor Mohammed Fahad Technical Editor Production Coordinator Aparna Bhagat Cover Work Aparna Bhagat Faisal Siddiqui www.it-ebooks.info About the Author Zachary Vineyard is a web developer that specializes in frontend web design, content management, and application development He's been building websites with PHP for the last 10 years He lives in Meridian, Idaho, with his wife and twin girls This book would not exist without the support of my wife, Dana I am blessed to have such a loving spouse and companion www.it-ebooks.info About the Reviewers Stephen Coogan is a frontend Web Developer with many years of experience living in Dublin, Ireland When he's not neck-deep in code, he can usually be found engrossed in this month's latest videogame released He is also the developer behind Promethean Gaming (http://www.prometheangaming.ie/) where he occasionally writes articles, too He also loves talking to people about the latest and greatest in web technologies, and is more than happy enough for people to reach out to him at: hello@coog.ie Kefeng Deng is an IT professional with over years of work experiences in IT industry in various stages, including both Java-based and PHP-based He is currently working for the University of Auckland as a Software Engineer, and mostly focuses on web application development using Groovy and Spring technologies More details about him are available at http://www.linkedin.com/in/dengkefeng www.it-ebooks.info www.PacktPub.com Support files, eBooks, discount offers and more You might want to visit www.PacktPub.com for support files and downloads related to your book Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub com and as a print book customer, you are entitled to a discount on the eBook copy Get in touch with us at service@packtpub.com for more details At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks TM http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library Here, you can access, read and search across Packt's entire library of books.  Why Subscribe? • Fully searchable across every book published by Packt • Copy and paste, print and bookmark content • On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books Simply use your login credentials for immediate access www.it-ebooks.info Table of Contents Preface 1 Chapter 1: Installing PyroCMS Getting started CodeIgniter 6 HTTP web server MySQL 7 PHP 7 GD2 7 cURL 8 Downloading PyroCMS The difference between the Community and Professional versions of PyroCMS 9 PyroStreams 10 The installer 10 Troubleshooting installation 14 Summary 15 Chapter 2: The Control Panel 17 Control panel access 17 The dashboard 19 Layout and navigation 19 Content 20 Structure 20 Data 21 Users 21 Settings 22 Add-ons 22 Profile 23 www.it-ebooks.info Table of Contents Choosing a default language 23 Summary 24 Chapter 3: Creating Pages and Page Types 25 Chapter 4: Plugin and Module Add-ons 35 Pages 25 The Pages module 26 How to create a basic page 27 Page Details tab 28 Page Content tab 28 Meta Data tab 28 CSS and Script tabs 29 Options tab 29 Save the page 29 Page types 29 Create a new page type 30 Add custom page type fields 31 Create a new page with custom data 33 Summary 34 Plugins 35 Tags 35 How to create a plugin 36 Modules 38 Folder structure 38 How to create a module 39 The info() method The install() method The uninstall() method The upgrade() method The help() method Putting it together 40 41 43 43 43 44 Add a controller 46 Plugins and widgets in modules 47 Summary 48 Chapter 5: Creating a PyroCMS Theme Folder structure Getting started Creating a theme.php file Theme options Building the theme options form Theme layouts [ ii ] www.it-ebooks.info 49 49 50 50 51 53 53 Table of Contents Tags explained 54 Basic tag 54 Tag attributes 54 Using tags in tag attributes 55 Tag pairs 55 Tag conditionals 56 Tags in templates 56 Layouts versus page types 57 Theme partials 57 Multiple layouts 58 Mobile layouts 59 Module view overloading 60 Summary 60 Chapter 6: Using PyroCMS Streams 61 How to get Streams 61 Creating a stream 62 Creating fields 63 Assigning fields 64 Ordering fields 65 Default columns (fields) 65 The backend input form 66 Displaying your data 67 Streams plugin 67 Common variables 67 Entry looping 68 The loop cycle 68 Filter by date 68 Other parameters 69 How to use the "where" parameter 70 Nested variables 70 Pagination 70 Stream data entry form 71 How to build the form 71 Custom success and error messages 73 Form assets 73 E-mail notifications 73 Summary 74 [ iii ] www.it-ebooks.info Chapter {{ template:metadata }} {{ theme:favicon file="favicon.png" }} {{ theme:css file="style.css" }} {{ theme:js file="site.js" }} {{ theme:image file="logo.jpg" alt="Your Logo" }} {{ navigation:links group="header" }} {{ template:title }} {{ template:body }} Make sure you take note, as seen in the first few lines of the preceding code example, of how tags power your ability to include layout assets, like CSS and JavaScript In this code, our assets include a favicon, a CSS file, a JavaScript file, and a logo image For our website, this basic layout will be the framework for all page content Once you have your default layout file created, you can start using it in the system Brief review of tags The use of tags in layout files, WYSIWYGs, and other inputs is ubiquitous in PyroCMS It is good to have an in-depth knowledge of how tags work They allow you to use advanced logic, with a special syntax, right inside your layouts and so on Tag features include use of attributes, attribute stacking, tag pairs (opening and closing tags similar to XML), and tag conditionals, as seen in the following example: {{ if user:logged_in }}

You are logged in.

{{ else }}

You are not logged in.

{{ endif }} [ 79 ] www.it-ebooks.info Building a Website with PyroCMS There are, of course, a number of other ways you can use tags in PyroCMS, but this covers the basics If you want to learn more about tags and other advanced tag syntax, you can find more in the PyroCMS documentation at http://www.pyrocms com/documentation Adding theme partials To make out theme layout more efficient, we're going to make use of theme partials Partials are partial layout files in PyroCMS, and they allow you to break layouts into reusable sections These sections can then be loaded by different layout files This keeps you from typing the same code (header, footer and so on.) into multiple layout files In the most basic way, we can break our layout into partial files, header.html, default.html, and footer.html Create each of these files in your theme folder, adding the header.html and the footer.html files into the respective partials directory You can then include those partial files into your default layout file by using a tag shown as follows: {{ theme:partial name="partialname" }} Now that we are making use of partials, the following is an example of what each of our layout files should include: • Our header.html file, found at addons/shared_addons/themes/[mytheme-name]/views/partials/, should contain the following chunk of code formerly found in our default layout file: {{ template:title }} {{ template:metadata }} {{ theme:favicon file="favicon.png" }} {{ theme:css file="style.css" }} {{ theme:js file="site.js" }} {{ theme:image file="logo.jpg" alt="Your Happy Logo" }} {{ navigation:links group="header" }} [ 80 ] www.it-ebooks.info Chapter • Our default.html file, found at [your-theme]/views/layouts/default.html should now contain the following code: {{ theme:partial name="header" }} {{ template:title }} {{ template:body }} {{ theme:partial name="footer" }} • Our footer.html file, found at addons/shared_addons/themes/[mytheme-name]/views/partials/, should now contain the following code formerly found in the default layout file: See how, when using partials, all the necessary files get included into the default layout file? This is a common way to introduce efficiencies into your template code so that, as a developer, you save time, which is what PyroCMS is all about Now that we have our basic theme put together, we can add content to our website You can this by using the Pages module in the system (in the control panel) Two things we'll add our website, beyond basic page content, are a contact form and stream data Adding a contact form A contact form is a basic feature of many, many websites This feature comes built into PyroCMS, and can be added to any page in the system simply because it is a plugin tag you add to your website The tag that creates this form is more complicated than most tags, but it makes simple work out of building and validating a contact form The following tag is a simple example of a tag that generates a contact form: {{ contact:form name = "text|required" email = "text|required|valid_email" subject = "dropdown|required|hello=Howdy| support=Support Ticket" message = "textarea|required" attachment = "file|jpg|png|zip" }} [ 81 ] www.it-ebooks.info Building a Website with PyroCMS {{ name }} {{ email }} {{ subject }} {{ message }} {{ attachment }} {{ /contact:form }} This contact form generates five input fields for a user These inputs are name, email, subject, message, and attachment Each parameter on this form tag can take a pipe-delimited set of values For most inputs, this pipe-delimited value follows a specific format This first value in the delimited string is, for example, the name of the input field The second delimited value determines whether or not the form input should be required for the user The third delimited value can either be an extension of validation rules or another set of delimited values that determine the options included in a dropdown The subject field, for example, will be output as a dropdown of values that include Howdy and Support Ticket These forms follow the form validation patterns used by CodeIgniter If you are unfamiliar with how forms get validated by CodeIgniter, you can refer CodeIgniter's User Guide for form validation documentation at http://ellislab.com/codeigniter/user-guide/ libraries/form_validation.html Adding stream data to your website We covered streams in the previous chapter of this book Building upon our efforts there, we are going to reuse the employees stream we built in that chapter That stream is a directory of people's names and phone numbers, one that can be output to a website To build that stream, we used the Streams module that comes built into the professional version of PyroCMS If you didn't follow the steps put together in Chapter 6, Using PyroCMS Streams, then you'll want to create a new stream of data called employees in PyroCMS using the Streams module We're going to take that stream, embed it into a page so that it can be seen by a user Then, taking it a step further, we're going to build a details page for a single stream entry This type of interaction, as I'm sure you know, is very common among websites First, let's take a look at the stream tag that's going to loop through our employee entries and output the values from our database, shown as follows: {{ streams:cycle stream="employees" limit="5" }} {{ entries }}

{{ name }}

{{ /entries }} {{ /streams:cycle }} [ 82 ] www.it-ebooks.info Chapter This code acts exactly like a for loop in PHP, looping over our data You can add this streams tag to any page you create using the Pages module In the case of this specific example, let's create a page called Employees that will list all of the employee entries in the stream: We'll modify our stream tag a little bit by adding a link around the name variable, so that each record in the stream links to the single, detailed stream entry Later, we'll embed the code for that single entry on a nested page The code we'll need for our details page is very similar to the code we put on the base employees page, but it uses a URL value and the id parameter to limit the data returned to the user, shown as follows: {{ streams:cycle stream="employees" limit="5" }} {{ entries }}

{{ name }}

{{ /entries }} {{ /streams:cycle }} As part of the details page, you can display the phone number we've entered for each entry in the employees stream, as shown in the following code sample We'll take the following code and add it to a page that is nested underneath our base employee page in the Pages module: {{ streams:cycle stream="employees" id="[segment_3]" limit="1" }} {{ entries }} {{ name }}

{{ phone }}

{{ /entries }} {{ /streams:cycle }} [ 83 ] www.it-ebooks.info Building a Website with PyroCMS If however, you try to get these pages to connect without doing one more step, you'll see that is doesn't work You'll be given a "404 page not found" error To get all of our URLs to line up correctly, we're going to define a custom URL route in PyroCMS that will make this common/details page setup work, which will then appear as shown in the following screenshot: Defining a custom route Building a custom route in PyroCMS is quite easy to In a way, though, adding this route to the system is modifying core code that could be wiped out with future updates to the system, so take care of these routes The file where you'll add your custom route is located within your PyroCMS project files, shown as follows: system/cms/config/routes.php To accommodate the employee/detail page we have created, you need to add the following route to your routes.php file: $route['employees/detail/(:any)'] = 'pages/view/employees/detail'; This route essentially makes the ID number that appears in your link to the details page, the parameter with which we can make a query against the database Once you have this route installed, you should be able to link from an employee record in your stream to a detailed employee record page [ 84 ] www.it-ebooks.info Chapter Summary What I've shown you in the last few pages of this book are the essential steps to getting a website running using PyroCMS We covered getting the system installed, creating a theme, and using streams to help power database driven content on your website What I hope you've learned is that it doesn't take much effort to start building a smart website on PyroCMS Because of its ability to leverage programming patterns, an easy-to-use PHP framework, and wicked fast theme development workflow, PyroCMS, as I hope you've seen, is an extremely well-outfitted system that's ready to be used on any website project [ 85 ] www.it-ebooks.info www.it-ebooks.info Index A add-ons option, control panel 22 admin controllers 46 assets, stream data entry form 73 B backend input form 66 basic tag 54 C CodeIgniter about 6, 37 URL, for info common variables, Streams plugin 67 contact form about 81 adding 81, 82 content management systems content option, control panel 20 controllers adding, to modules 46, 47 control panel modules add-ons 22 content 20 data 21 profile 23 settings 22 structure 20 users 21 control panel, PyroCMS accessing 17, 18 dashboard 19 default language, selecting 23 layout 19 navigation 19 CSS tab, page creation form 29 cURL about URL custom data page, creating with 33, 34 custom error message, stream data entry form 73 custom page type fields creating 31-33 custom route defining 84 custom success message, stream data entry form 73 custom theme creating 76, 77 D dashboard 19 data displaying 67 data option, control panel 21 data stream module 61 date filter, Streams plugin 68 default columns for streams 65 default language selecting 23 details.php file code 44, 46 Drupal DRY protocol 56 www.it-ebooks.info E e-mail notifications, stream data entry form 73 entry looping, Streams plugin 68 F features, modules 38 fields assigning, to streams 64 creating, for streams 63, 64 ordering, on streams 65 folder structure, modules 38 folder structure, themes 49, 76 modules about 38 controller, adding to 46, 47 creating, in PyroCMS 39 features 38 folder structure 38 module view overloading 60 multiple layouts for tags, in templates 58 MySQL about URL, for info N namespaceing nested variables, Streams plugin 70 G GD2 GitHub PyroCMS, downloading from O H P help() method 43 HTTP web server 6, page about 25 creating, in PyroCMS 27 creating, with custom data 33, 34 Page Content tab, page creation form 28 page creation form CSS tab 29 Meta Data tab 28 Options tab 29 Page Content tab 28 Page Details tab 28 Script tab 29 Page Details tab, page creation form 28 Pages module 26 page tree 26 page types about 25, 29, 61 creating 30, 31 custom page type fields, adding 31-33 page, creating with custom data 33, 34 versus layouts 57 pagination feature, Streams plugin 70 Options tab, page creation form 29 I index() method 47 info() method 40, 41 install() method 41, 42 L layout file creating 78, 79 layouts displaying, for mobile 59 versus page types 57 Lex parser tags 31, 35, 56 loop cycle, Streams plugin 68 M Meta Data tab, page creation form 28 mobile layouts 59 Model-View-Controller (MVC) [ 88 ] www.it-ebooks.info parameters, Streams plugin about 69 date_by 69 day 69 disable 69 exclude 69 exclude_called 69 include 69 include_by 69 limit 69 month 69 namespace 69 no_results 69 offset 69 order_by 69 partial 69 show_past 69 show_upcoming 69 sort 69 stream 69 where 69, 70 year 69 PHP PHP 5.2 plugin.php file 36 plugins about 35 building, for PyroCMS 36, 37 in modules 47 tags 35 URL, for documentation 38 prerequisite methods, PHP class help() method 43 info() method 40, 41 install() method 41, 42 uninstall() method 43 upgrade() method 43 profile option, control panel 23 public controllers 46 PyroCMS about Community version, features Community version versus Professional version 10 control panel 17 downloading downloading, from GitHub installation 75 installation process, troubleshooting 14 modules, creating 39 page, creating 27 platform support 6, plugins, building 36, 37 Professional version, features 10 software requisites 5, URL, for downloading URL, for forums 14, 76 URL, for installation guide 14 PyroCMS installer about 5, 10 steps 11-14 PyroStreams 61 PyroStreams module 10 S Script tab, page creation form 29 settings option, control panel 22 software requisites, PyroCMS about CodeIgniter cURL GD2 HTTP web server 6, MySQL PHP stream data adding, to website 82, 83 stream data entry form about 71 assets 73 building 71, 72 custom error message 73 custom success message 73 e-mail notifications 73 streams about 61 creating 62, 63 fields, assigning to 64 fields, creating for 63, 64 fields, ordering on 65 Streams module about 61 obtaining 61 [ 89 ] www.it-ebooks.info URL, for purchasing from PyroCMS add-on store 61 Streams plugin about 67 common variables 67 date filter, adding 68 entry looping 68 loop cycle 68 nested variables 70 pagination feature 70 parameters 69 structure option, control panel 20 T tag attributes about 54 tags, using 55 tag conditionals 56 tag pairs 55 tags about 35 basic tag 54 in templates 56, 57 review 79 tag attributes 54 tag conditionals 56 tag pairs 55 using, in tag attributes 55 theme layouts 53 theme options form building 53 theme partials about 57, 58 adding 80, 81 theme.php file about 50, 77 creating 50, 51 themes about 50 folder structure 49, 76 themes options 51, 52 Typo3 U uninstall() method 43 upgrade() method 43 users option, control panel 21 W website stream data, adding to 82, 83 where parameter using, in stream tags 70 widgets in modules 47 WordPress 5, 35 [ 90 ] www.it-ebooks.info Thank you for buying Website Development with PyroCMS About Packt Publishing Packt, pronounced 'packed', published its first book }Mastering phpMyAdmin for Effective MySQL Management} in April 2004 and subsequently continued to specialize in publishing highly focused books on specific technologies and solutions Our books and publications share the experiences of your fellow IT professionals in adapting and customizing today's systems, applications, and frameworks Our solution based books give you the knowledge and power to customize the software and technologies you're using to get the job done Packt books are more specific and less general than the IT books you have seen in the past Our unique business model allows us to bring you more focused information, giving you more of what you need to know, and less of what you don't Packt is a modern, yet unique publishing company, which focuses on producing quality, cutting-edge books for communities of developers, administrators, and newbies alike For more information, please visit our website: www.packtpub.com About Packt Open Source In 2010, Packt launched two new brands, Packt Open Source and Packt Enterprise, in order to continue its focus on specialization This book is part of the Packt Open Source brand, home to books published on software built around Open Source licences, and offering information to anybody from advanced developers to budding web designers The Open Source brand also runs Packt's Open Source Royalty Scheme, by which Packt gives a royalty to each Open Source project about whose software a book is sold Writing for Packt We welcome all inquiries from people who are interested in authoring Book proposals should be sent to author@packtpub.com If your book idea is still at an early stage and you would like to discuss it first before writing a formal book proposal, contact us; one of our commissioning editors will get in touch with you We're not just looking for published authors; if you have strong technical skills but no writing experience, our experienced editors can help you develop a writing career, or simply get some additional reward for your expertise www.it-ebooks.info Joomla! E-Commerce with VirtueMart ISBN: 978-1-84719-674-3 Paperback: 476 pages Build feature-rich online stores with Joomla! 1.0/1.5 and VirtueMart 1.1.x Build your own e-commerce web site from scratch by adding features step-by-step to an example e-commerce web site Configure the shop, build product catalogues, configure user registration settings for VirtueMart to take orders from around the world Manage customers, orders, and a variety of currencies to provide the best customer service Building Websites with Joomla! 1.5 ISBN:978-1-847195-30-2 Paperback: 384 pages The best-selling Joomla! tutorial guide updated for the final release Learn Joomla! 1.5 features Install and customize Joomla! 1.5 Configure Joomla! administration Create your own Joomla! templates Extend Joomla! with new components, modules, and plug-ins Please check www.PacktPub.com for information on our titles www.it-ebooks.info Joomla! VirtueMart 1.1 Theme and Template Design ISBN: 978-1-849514-54-5 Paperback: 384 pages Give a unique look and feel to your VirtueMart e-commerce store Thorough discussion of template structure, available fields, and customization possibilities More than 50 real-world exercises that can be directly adapted to your store A comprehensive reference to all templates in the VirtueMart default theme including usage of each template and all available fields Integrate with existing Joomla! plugins and JavaScript frameworks Building E-commerce Sites with Drupal Commerce Cookbook ISBN: 978-1-782161-22-6 Paperback: 206 pages Over 50 recipes to help you build engaging, responsive E-commerce sites with Drupal Commerce Learn how to build attractive eCommerce sites with Drupal Commerce Customise your Drupal Commerce store for maximum impact Reviewed by the creators of Drupal Commerce: The CommerceGuys Please check www.PacktPub.com for information on our titles www.it-ebooks.info .. .Website Development with PyroCMS Quickly and efficiently develop and deploy impressive websites with PyroCMS Zachary Vineyard BIRMINGHAM - MUMBAI www.it-ebooks.info Website Development with PyroCMS. .. management, and application development He's been building websites with PHP for the last 10 years He lives in Meridian, Idaho, with his wife and twin girls This book would not exist without the support... layouts Chapter 6, Using PyroCMS Streams, teaches you how to create and use streams of data in PyroCMS using the PyroStreams module Chapter 7, Building a Website with PyroCMS, shows you how to

Ngày đăng: 12/03/2019, 16:09

Mục lục

    The difference between the Community and Professional versions of PyroCMS

    Chapter 2: The Control Panel

    Choosing a default language

    Chapter 3: Creating Pages and Page Types

    How to create a basic page

    CSS and Script tabs

    Create a new page type

    Add custom page type fields

    Create a new page with custom data

    Chapter 4: Plugin and Module Add-ons

Tài liệu cùng người dùng

Tài liệu liên quan