KEMBAR78
Modular PHP Development using CodeIgniter Bonfire | PPTX
Fairfield County PHP Meetup




 Modular PHP dev using
CodeIgniter Bonfire
About Jeff Fox (@jfox015)
• Senior Level Web Developer
• Veteran of two browser wars and the dot-
  com bubble

• Fully self taught
• Studied Art and Music Production
• Baseball enthusiast (ney fanatic)
Meetup Overview
• MVC, CodeIgniter and HMVC in 5
    mins.
•   Intro to Bonfire (more than 5
    minutes)
•   Anatomy of a Bonfire Module
•   Practical Example
•   Q&A
Modular Development

Taking HUGE monolithic applications




and breaking them into manageable pieces
Modular Development

    "How the heck do we do that?"
Model, View, Controller




     Controllers
     handle requests




Models                      Views
                            present information
represent data
                            to the user
CodeIgniter
CodeIgniter



•    Popular Open Source PHP Framework

•    Simple MVC Based Architecture

•    Tons of tools and libraries to utilize in site
     development workflow

•    Flexible View system

•    Known for performance and documentation
CodeIgniter
CodeIgniter



•    Originally built and released by Ellis Labs, the
     Expression Engine people

•    "Reactor" is the community driven build and
     release initiative

•    Core team of developers oversee active
     development and releases

•    One of the "big three" PHP Frameworks
CodeIgniter
CodeIgniter




Application Flowchart
Hierarchical Model, View,
  Controller

HMVC Triads
call on and use other
MVC triads to
accomplish goals of
the application
CodeIgniter
  Bonfire
Bonfire Basics
CodeIgniter



• Open Source library built on top of
     CodeIgniter

• HMVC design using Modular Extensions
• Pre-built Administrative Dashboard
• Rich user authentication workflow
• Variety of site admin tools and utilities
Bonfire Basics
CodeIgniter



• Dashboard utilizes "contexts" for building
     admin tools

• Database migrations manage upgrades
     and fallbacks

• Custom Model class with built in SQL
     helper functionality

• Several classes of abstract controllers
Bonfire Basics
CodeIgniter



• Includes a system of roles to assign to
  users
• Robust permissions allows for precise
     control over site privileges and user
     access
•    Standard system for storing and
     accessing site settings
•    Includes a Module Builder wizard to
     generate fully compatible new modules
Functional Highlights
CodeIgniter



• Contexts provide a loosely coupled way
     to build Admin tools

• Naming conventions prevent hard coding
     menus

• Each module can have its own admin
     tools and still stay loosely coupled
Functional Highlights
CodeIgniter


Themes and Templates
• UI Based on the Twitter Bootstrap
  libraryBonfire uses a theme and
  template system for views
• Numerous helper functions are
  available to send data to view
  classes, select themes, manually set
  views, set messaging and render the
  content
Functional Highlights
 CodeIgniter


Themes and Templates – Examples
Template::set('current_url',
current_url());

Template::set_message('The comments
selected were successfully deleted.',
'success');

Template::set_view('comments/index');

Template::render();
Functional Highlights
CodeIgniter


Migrations
•    Implements the CodeIgninter Migrations
     class

•    Adds ability for modules to use migrations

•    Auto loading of new migrations on app
     startup (configuable via settings)

•    Can use DBforge or Codeigniter Database
     Class and SQL
Functional Highlights
CodeIgniter



public function up()
{
   $this->dbforge-
>add_column('comments_threads',
array('module' => array('type'=>
'VARCHAR','constraint'   => 255,'default'
      => ''));
}
public function down()
{
   $this->dbforge-
>drop_column("comments_threads","module");
}
Functional Highlights
CodeIgniter


Assets Lib
• Allows you to add JavaScript, images
  and CSS automatically in the head
  and/or footer of the site

Assets::add_js($this->load-
>view('thread_view_js',array('th
read_id'=>$thread_id), true),'in
line');
Functional Highlights
CodeIgniter


Modular Everything
•All core Dashboard features are
 modules
    •   Users         •   Translate Tool
    •   Activities    •   Module Builder
    •   Migrations    •   Logos
    •   Permissions   •   Emailer
    •   Roles         •   UI
    •   Settings      •   Updater
    •   Sysinfo       •   Database
Functional Highlights
CodeIgniter



Easy Install

Two step install
Like Wordpress
Bonfire Team
CodeIgniter




              Lonnie Ezell      Nuno Costa
              Project Founder
                                Ben Evans
                                Icehawg
              Sean Downey and many more on
                                Github.com

              Shawn Crigger
Anatomy of a
Bonfire Module
General Structure
CodeIgniter




• All third party and
     custom modules are
     stored in the "modules"
     folder in the bonfire
     directory.
•    Core modules live in
     the "core_modules"
     folder in the
     application directory.
General Structure
 CodeIgniter


 • Bonfire Modules are like little stand-alone
      CodeIgniter apps

 •    Modules follow the context naming convention
      system to allow access to their controllers
      throughout the site

 •    Can be 100% standalone or work with other
      modules

 •    Optimally can be dropped into other apps
Naming Conventions
 CodeIgniter



Controllers
• Public accessible, add
    controller with a name
    that matches the
    modules folder name
•   Admin Dashboard (Also
    called the Springboard)
    Controllers, add a
    controller that matches
    the context name
Naming Conventions
CodeIgniter




Auto-Resolving Views

• For public views, and index.php to
  the modules "Views" folder
• Admin views, add a folder for the
     matching context in the "Views"
     folder with an index.php file in it.
Naming Conventions
CodeIgniter




Manually Resolving Views
• In the controller, before calling
     Template::render(), add a line to set
     the view using
     Template::set_view('view');
•    Any view from any loaded module
     can be used simply by specifying the
     module path and view name
Config
CodeIgniter




• config.php contains a simple array that
     identifies the module to the application
     and contain it's meta information

• Config folder may contain other files used
     to store information about the app

• Custom routes.php files can be used to
     add additional levels of URL->controller
     routing
Controllers
CodeIgniter




• Contains all controllers used by the
     modules

• Should extend one of the four main
     Bonfire controller types:
      o Base_Controller
      o Front_Controller
      o Authenticated_Controller
      o Admin_Controller
Views
CodeIgniter



• Adding an index.php file to the views
     folder makes it publically accessible

• Adding folders named for supported
     admin contexts with index.php files makes
     them accessible from admin menus

• No limit to number of view files there can
     be, how they're organized outside context
     rules or how they're called
Misc
CodeIgniter



• Models follow general CI model rules.
     Should extend BF_Model to gain Bonfire
     helper functionality.

• Migrations are used to install DB support
     and handle changes

• Language files support translations
• Can add helpers, libraries and assets as
     well
Practical
Example
Q&A
Resources
Resources
 CodeIgniter

 • Bonfire Learning Center
  http://www.
  http://cibonfire.com/docs/guides/

 • Github Repository
  https://github.com/ci-
  bonfire/Bonfire
Resources
 CodeIgniter

 • Tutorials on MVC, HMVC, CodeIgniter
  at http://net.tutsplus.com/

  See MVC for Noobs, CodeIgniter from Scratch,
  HMVC: an Introduction and Application

 • OOWP For Developers Tutorials
  http://www.aeoliandigital.com/archi
  ves/category/oowp
Resources
 CodeIgniter

 Example Modules:
 • News:
   https://github.com/jfox015/Bonfire-
   News

 • Comments:
     https://github.com/jfox015/Bonfire-
     Comments

Modular PHP Development using CodeIgniter Bonfire

  • 1.
    Fairfield County PHPMeetup Modular PHP dev using CodeIgniter Bonfire
  • 2.
    About Jeff Fox(@jfox015) • Senior Level Web Developer • Veteran of two browser wars and the dot- com bubble • Fully self taught • Studied Art and Music Production • Baseball enthusiast (ney fanatic)
  • 3.
    Meetup Overview • MVC,CodeIgniter and HMVC in 5 mins. • Intro to Bonfire (more than 5 minutes) • Anatomy of a Bonfire Module • Practical Example • Q&A
  • 4.
    Modular Development Taking HUGEmonolithic applications and breaking them into manageable pieces
  • 5.
    Modular Development "How the heck do we do that?"
  • 6.
    Model, View, Controller Controllers handle requests Models Views present information represent data to the user
  • 7.
    CodeIgniter CodeIgniter • Popular Open Source PHP Framework • Simple MVC Based Architecture • Tons of tools and libraries to utilize in site development workflow • Flexible View system • Known for performance and documentation
  • 8.
    CodeIgniter CodeIgniter • Originally built and released by Ellis Labs, the Expression Engine people • "Reactor" is the community driven build and release initiative • Core team of developers oversee active development and releases • One of the "big three" PHP Frameworks
  • 9.
  • 10.
    Hierarchical Model, View, Controller HMVC Triads call on and use other MVC triads to accomplish goals of the application
  • 11.
  • 12.
    Bonfire Basics CodeIgniter • OpenSource library built on top of CodeIgniter • HMVC design using Modular Extensions • Pre-built Administrative Dashboard • Rich user authentication workflow • Variety of site admin tools and utilities
  • 13.
    Bonfire Basics CodeIgniter • Dashboardutilizes "contexts" for building admin tools • Database migrations manage upgrades and fallbacks • Custom Model class with built in SQL helper functionality • Several classes of abstract controllers
  • 14.
    Bonfire Basics CodeIgniter • Includesa system of roles to assign to users • Robust permissions allows for precise control over site privileges and user access • Standard system for storing and accessing site settings • Includes a Module Builder wizard to generate fully compatible new modules
  • 15.
    Functional Highlights CodeIgniter • Contextsprovide a loosely coupled way to build Admin tools • Naming conventions prevent hard coding menus • Each module can have its own admin tools and still stay loosely coupled
  • 16.
    Functional Highlights CodeIgniter Themes andTemplates • UI Based on the Twitter Bootstrap libraryBonfire uses a theme and template system for views • Numerous helper functions are available to send data to view classes, select themes, manually set views, set messaging and render the content
  • 17.
    Functional Highlights CodeIgniter Themesand Templates – Examples Template::set('current_url', current_url()); Template::set_message('The comments selected were successfully deleted.', 'success'); Template::set_view('comments/index'); Template::render();
  • 18.
    Functional Highlights CodeIgniter Migrations • Implements the CodeIgninter Migrations class • Adds ability for modules to use migrations • Auto loading of new migrations on app startup (configuable via settings) • Can use DBforge or Codeigniter Database Class and SQL
  • 19.
    Functional Highlights CodeIgniter public functionup() { $this->dbforge- >add_column('comments_threads', array('module' => array('type'=> 'VARCHAR','constraint' => 255,'default' => '')); } public function down() { $this->dbforge- >drop_column("comments_threads","module"); }
  • 20.
    Functional Highlights CodeIgniter Assets Lib •Allows you to add JavaScript, images and CSS automatically in the head and/or footer of the site Assets::add_js($this->load- >view('thread_view_js',array('th read_id'=>$thread_id), true),'in line');
  • 21.
    Functional Highlights CodeIgniter Modular Everything •Allcore Dashboard features are modules • Users • Translate Tool • Activities • Module Builder • Migrations • Logos • Permissions • Emailer • Roles • UI • Settings • Updater • Sysinfo • Database
  • 22.
  • 23.
    Bonfire Team CodeIgniter Lonnie Ezell Nuno Costa Project Founder Ben Evans Icehawg Sean Downey and many more on Github.com Shawn Crigger
  • 24.
  • 25.
    General Structure CodeIgniter • Allthird party and custom modules are stored in the "modules" folder in the bonfire directory. • Core modules live in the "core_modules" folder in the application directory.
  • 26.
    General Structure CodeIgniter • Bonfire Modules are like little stand-alone CodeIgniter apps • Modules follow the context naming convention system to allow access to their controllers throughout the site • Can be 100% standalone or work with other modules • Optimally can be dropped into other apps
  • 27.
    Naming Conventions CodeIgniter Controllers •Public accessible, add controller with a name that matches the modules folder name • Admin Dashboard (Also called the Springboard) Controllers, add a controller that matches the context name
  • 28.
    Naming Conventions CodeIgniter Auto-Resolving Views •For public views, and index.php to the modules "Views" folder • Admin views, add a folder for the matching context in the "Views" folder with an index.php file in it.
  • 29.
    Naming Conventions CodeIgniter Manually ResolvingViews • In the controller, before calling Template::render(), add a line to set the view using Template::set_view('view'); • Any view from any loaded module can be used simply by specifying the module path and view name
  • 30.
    Config CodeIgniter • config.php containsa simple array that identifies the module to the application and contain it's meta information • Config folder may contain other files used to store information about the app • Custom routes.php files can be used to add additional levels of URL->controller routing
  • 31.
    Controllers CodeIgniter • Contains allcontrollers used by the modules • Should extend one of the four main Bonfire controller types: o Base_Controller o Front_Controller o Authenticated_Controller o Admin_Controller
  • 32.
    Views CodeIgniter • Adding anindex.php file to the views folder makes it publically accessible • Adding folders named for supported admin contexts with index.php files makes them accessible from admin menus • No limit to number of view files there can be, how they're organized outside context rules or how they're called
  • 33.
    Misc CodeIgniter • Models followgeneral CI model rules. Should extend BF_Model to gain Bonfire helper functionality. • Migrations are used to install DB support and handle changes • Language files support translations • Can add helpers, libraries and assets as well
  • 34.
  • 35.
  • 36.
  • 37.
    Resources CodeIgniter •Bonfire Learning Center http://www. http://cibonfire.com/docs/guides/ • Github Repository https://github.com/ci- bonfire/Bonfire
  • 38.
    Resources CodeIgniter •Tutorials on MVC, HMVC, CodeIgniter at http://net.tutsplus.com/ See MVC for Noobs, CodeIgniter from Scratch, HMVC: an Introduction and Application • OOWP For Developers Tutorials http://www.aeoliandigital.com/archi ves/category/oowp
  • 39.
    Resources CodeIgniter ExampleModules: • News: https://github.com/jfox015/Bonfire- News • Comments: https://github.com/jfox015/Bonfire- Comments