modular php development using codeigniter bonfire
DESCRIPTION
An overview of the Bonfire library for CodeIgniter and how it allows you to build robust modular applicationsTRANSCRIPT
![Page 1: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/1.jpg)
Modular PHP dev using CodeIgniter Bonfire
Fairfield County PHP Meetup
![Page 2: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/2.jpg)
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)
![Page 3: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/3.jpg)
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
![Page 4: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/4.jpg)
Modular Development
Taking HUGE monolithic applications
and breaking them into manageable pieces
![Page 5: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/5.jpg)
Modular Development
"How the heck do we do that?"
![Page 6: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/6.jpg)
Model, View, Controller
Controllershandle requests
Modelsrepresent data
Viewspresent information to the user
![Page 7: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/7.jpg)
CodeIgniterCodeIgniter
• 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
![Page 8: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/8.jpg)
CodeIgniterCodeIgniter
• 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
![Page 9: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/9.jpg)
CodeIgniterCodeIgniter
Application Flowchart
![Page 10: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/10.jpg)
Hierarchical Model, View, Controller
HMVC Triadscall on and use other MVC triads to accomplish goals of the application
![Page 11: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/11.jpg)
CodeIgniter Bonfire
![Page 12: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/12.jpg)
CodeIgniterBonfire Basics
• 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
![Page 13: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/13.jpg)
CodeIgniterBonfire Basics
• 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
![Page 14: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/14.jpg)
CodeIgniterBonfire Basics
• 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
![Page 15: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/15.jpg)
CodeIgniterFunctional Highlights
• 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
![Page 16: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/16.jpg)
CodeIgniterFunctional HighlightsThemes 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
![Page 17: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/17.jpg)
CodeIgniterFunctional HighlightsThemes and Templates – ExamplesTemplate::set('current_url', current_url());
Template::set_message('The comments selected were successfully deleted.', 'success');
Template::set_view('comments/index');
Template::render();
![Page 18: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/18.jpg)
CodeIgniterFunctional HighlightsMigrations• 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
![Page 19: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/19.jpg)
CodeIgniterFunctional Highlights
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");
}
![Page 20: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/20.jpg)
CodeIgniterFunctional HighlightsAssets 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('thread_id'=>$thread_id), true),'inline');
![Page 21: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/21.jpg)
CodeIgniterFunctional HighlightsModular Everything
• All core Dashboard features are modules• Users• Activities• Migrations• Permissions• Roles• Settings• Sysinfo
• Translate Tool• Module Builder• Logos• Emailer• UI• Updater• Database
![Page 22: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/22.jpg)
CodeIgniterFunctional Highlights
Easy Install
Two step installLike Wordpress
![Page 23: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/23.jpg)
CodeIgniterBonfire Team
Lonnie EzellProject Founder
Sean Downey
Shawn Crigger
Nuno CostaBen EvansIcehawgand many more on Github.com
![Page 24: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/24.jpg)
Anatomy of a Bonfire Module
![Page 25: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/25.jpg)
CodeIgniterGeneral Structure
• 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.
![Page 26: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/26.jpg)
CodeIgniterGeneral Structure• 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
![Page 27: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/27.jpg)
CodeIgniterNaming Conventions
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
![Page 28: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/28.jpg)
CodeIgniterNaming Conventions
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.
![Page 29: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/29.jpg)
CodeIgniterNaming Conventions
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
![Page 30: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/30.jpg)
CodeIgniterConfig
• 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
![Page 31: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/31.jpg)
CodeIgniterControllers
• Contains all controllers used by the modules
• Should extend one of the four main Bonfire controller types:o Base_Controllero Front_Controllero Authenticated_Controllero Admin_Controller
![Page 32: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/32.jpg)
CodeIgniterViews
• 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
![Page 33: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/33.jpg)
CodeIgniterMisc
• 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
![Page 34: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/34.jpg)
Practical Example
![Page 35: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/35.jpg)
Q & A
![Page 36: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/36.jpg)
Resources
![Page 37: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/37.jpg)
CodeIgniterResources
• Bonfire Learning Centerhttp://www. http://cibonfire.com/docs/guides/
• Github Repositoryhttps://github.com/ci-bonfire/Bonfire
![Page 38: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/38.jpg)
CodeIgniterResources
• Tutorials on MVC, HMVC, CodeIgniterat http://net.tutsplus.com/
See MVC for Noobs, CodeIgniter from Scratch, HMVC: an Introduction and Application
• OOWP For Developers Tutorialshttp://www.aeoliandigital.com/archives/category/oowp
![Page 39: Modular PHP Development using CodeIgniter Bonfire](https://reader033.vdocuments.us/reader033/viewer/2022061112/5457eaaaaf795998788b52b4/html5/thumbnails/39.jpg)
CodeIgniterResources
Example Modules:
• News: https://github.com/jfox015/Bonfire-News
• Comments:https://github.com/jfox015/Bonfire-Comments