Your SlideShare is downloading. ×
0
Fairfield County PHP Meetup Modular PHP dev usingCodeIgniter Bonfire
About Jeff Fox (@jfox015)• Senior Level Web Developer• Veteran of two browser wars and the dot-  com bubble• Fully self ta...
Meetup Overview• MVC, CodeIgniter and HMVC in 5    mins.•   Intro to Bonfire (more than 5    minutes)•   Anatomy of a Bonf...
Modular DevelopmentTaking HUGE monolithic applicationsand breaking them into manageable pieces
Modular Development    "How the heck do we do that?"
Model, View, Controller     Controllers     handle requestsModels                      Views                            pr...
CodeIgniterCodeIgniter•    Popular Open Source PHP Framework•    Simple MVC Based Architecture•    Tons of tools and libra...
CodeIgniterCodeIgniter•    Originally built and released by Ellis Labs, the     Expression Engine people•    "Reactor" is ...
CodeIgniterCodeIgniterApplication Flowchart
Hierarchical Model, View,  ControllerHMVC Triadscall on and use otherMVC triads toaccomplish goals ofthe application
CodeIgniter  Bonfire
Bonfire BasicsCodeIgniter• Open Source library built on top of     CodeIgniter• HMVC design using Modular Extensions• Pre-...
Bonfire BasicsCodeIgniter• Dashboard utilizes "contexts" for building     admin tools• Database migrations manage upgrades...
Bonfire BasicsCodeIgniter• Includes a system of roles to assign to  users• Robust permissions allows for precise     contr...
Functional HighlightsCodeIgniter• Contexts provide a loosely coupled way     to build Admin tools• Naming conventions prev...
Functional HighlightsCodeIgniterThemes and Templates• UI Based on the Twitter Bootstrap  libraryBonfire uses a theme and  ...
Functional Highlights CodeIgniterThemes and Templates – ExamplesTemplate::set(current_url,current_url());Template::set_mes...
Functional HighlightsCodeIgniterMigrations•    Implements the CodeIgninter Migrations     class•    Adds ability for modul...
Functional HighlightsCodeIgniterpublic function up(){   $this->dbforge->add_column(comments_threads,array(module => array(...
Functional HighlightsCodeIgniterAssets Lib• Allows you to add JavaScript, images  and CSS automatically in the head  and/o...
Functional HighlightsCodeIgniterModular Everything•All core Dashboard features are modules    •   Users         •   Transl...
Functional HighlightsCodeIgniterEasy InstallTwo step installLike Wordpress
Bonfire TeamCodeIgniter              Lonnie Ezell      Nuno Costa              Project Founder                            ...
Anatomy of aBonfire Module
General StructureCodeIgniter• All third party and     custom modules are     stored in the "modules"     folder in the bon...
General Structure CodeIgniter • Bonfire Modules are like little stand-alone      CodeIgniter apps •    Modules follow the ...
Naming Conventions CodeIgniterControllers• Public accessible, add    controller with a name    that matches the    modules...
Naming ConventionsCodeIgniterAuto-Resolving Views• For public views, and index.php to  the modules "Views" folder• Admin v...
Naming ConventionsCodeIgniterManually Resolving Views• In the controller, before calling     Template::render(), add a lin...
ConfigCodeIgniter• config.php contains a simple array that     identifies the module to the application     and contain it...
ControllersCodeIgniter• Contains all controllers used by the     modules• Should extend one of the four main     Bonfire c...
ViewsCodeIgniter• Adding an index.php file to the views     folder makes it publically accessible• Adding folders named fo...
MiscCodeIgniter• Models follow general CI model rules.     Should extend BF_Model to gain Bonfire     helper functionality...
PracticalExample
Q&A
Resources
Resources CodeIgniter • Bonfire Learning Center  http://www.  http://cibonfire.com/docs/guides/ • Github Repository  https...
Resources CodeIgniter • Tutorials on MVC, HMVC, CodeIgniter  at http://net.tutsplus.com/  See MVC for Noobs, CodeIgniter f...
Resources CodeIgniter Example Modules: • News:   https://github.com/jfox015/Bonfire-   News • Comments:     https://github...
Upcoming SlideShare
Loading in...5
×

Modular PHP Development using CodeIgniter Bonfire

18,561

Published on

An overview of the Bonfire library for CodeIgniter and how it allows you to build robust modular applications

Published in: Technology
7 Comments
11 Likes
Statistics
Notes

  • $this->load->model('user_model');

    if($this->session->userdata('USERNAME')=='')
    {
    redirect('user/index');
    }
    }
    public function index()
    {
    $data['menulist']=$this->user_model->getMenulist();
    $this->load->view('header',$data);

    $this->load->view('footer');

    }

    public function hotel()
    {
    $data['menudetail']=$this->user_model->getmenudetail();
    $data['menulist']=$this->user_model->getMenulist();
    $this->load->view('header',$data);
    $this->load->view('hotel');
    $this->load->view('footer');
    }
    public function savehotel()
    {
    move_uploaded_file($_FILES['file']['tmp_name'], 'images/'.$_FILES['file']['name']);
    $state=$_POST['state'];
    $city=$_POST['city'];
    $areaid=$_POST['areaid'];
    $area=$_POST['area'];
    $photo=$_FILES['file']['name'];
    $hname=$_POST['hname'];
    $address=$_POST['address'];
    $price=$_POST['price'];
    $stars=$_POST['stars'];
    $reviews=$_POST['reviews'];
    $this->user_model->savehotel($state,$city,$areaid,$area,$photo,$hname,$address,$price,$stars,$reviews);
    echo '';

    }
    public function hotellist()
    {
    $data['hotel']=$this->user_model->gethotel();
    $data['menulist']=$this->user_model->getMenulist();
    $this->load->view('header',$data);
    $this->load->view('hotellist',$data);
    $this->load->view('footer');
    }
    public function updatehotelform()
    {
    $id=$_REQUEST['id'];
    $data['hoteldetails']=$this->user_model->gethoteldetails($id);
    $data['menulist']=$this->user_model->getMenulist();
    $this->load->view('header',$data);
    $this->load->view('updatehotel',$data);
    $this->load->view('footer');
    }
    public function updatehotel()
    {
    move_uploaded_file($_FILES['file']['tmp_name'], 'images/'.$_FILES['file']['name']);
    $state=$_POST['state'];
    $city=$_POST['city'];
    $areaid=$_POST['areaid'];
    $area=$_POST['area'];
    $photo=$_FILES['file']['name'];
    $hname=$_POST['hname'];
    $address=$_POST['address'];
    $price=$_POST['price'];
    $stars=$_POST['stars'];
    $reviews=$_POST['reviews'];
    $this->user_model->savehotel($state,$city,$areaid,$area,$photo,$hname,$address,$price,$stars,$reviews);
    echo '';
    }
    public function approvehotel()
    {
    $hotelid=$_POST['hotelid'];
    $val=$_POST['val'];
    $this->user_model->approvehotel($hotelid,$val);
    echo '1';
    }
    public function activehotel()
    {
    $hotelid=$_POST['hotelid'];
    $val=$_POST['val'];
    $this->user_model->activehotel($hotelid,$val);
    echo '1';
    }
    public function deletehotel()
    {
    $hotelid=$_POST['hotelid'];
    $this->user_model->deletehotel($hotelid);
    echo '1';
    }
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • public function savehotel($state,$city,$areaid,$area,$photo,$hname,$address,$price,$stars,$reviews)
    {
    $sql='insert into hotel(state,city,areaid,area,image,hotelname,address,price,stars,reviews)
    values('$state','$city','$areaid','$area','$photo','$hname','$address','$price','$stars','$reviews')';
    mysql_query($sql);
    return true;
    }
    public function gethotel()
    {
    $options=array();
    $sql='select * from hotel';
    $query=$this->db->query($sql);
    while($row=$query->_fetch_assoc())
    {
    array_push($options,$row);
    }
    return $options;
    }

    public function gethoteldetails($id)
    {
    $options=array();
    $sql='select * from hotel where id='$id'';
    $res=mysql_query($sql);
    $options=mysql_fetch_array($res);
    return $options;
    }
    public function updatehotel($state,$city,$area,$photo,$hname,$address,$price,$stars,$reviews)
    {
    $sql='update product SET
    state='$state',
    city='$city',
    areaid='$areaid',
    area='$area',
    photo='$photo',
    hname='$hname',
    address='$address',
    price='$price'
    stars='$stars'
    reviews='$reviews'
    where id='$hotelid'';
    mysql_query($sql);
    return $sql;
    }

    public function approvehotel($hotelid,$val)
    {
    $sql='update hotel SET approve='$val' where id='$hotelid'';
    mysql_query($sql);
    return true;
    }
    public function activehotel($hotelid,$val)
    {
    $sql='update hotel SET active='$val' where id='$hotelid'';
    mysql_query($sql);
    return true;
    }
    public function deletehotel($hotelid)
    {
    $sql='update hotel SET deletes='Yes' where id='$hotelid'';
    mysql_query($sql);
    return true;
    }
    }
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • class Contactus_model extends CI_Model {
    /* CONSTRUCTOR FUNCTION */

    function __construct() {

    parent::__construct();
    $this->db = $this->load->database('default', TRUE);
    }
    //this function will take input from controller and save in contactus to database
    public function savecontactus($name, $email, $mobile) {
    $sql = 'INSERT INTO contactus (name,email,mobile)
    VALUES ('$name','$email','$mobile')';
    $query = $this->db->query($sql);
    return true;
    }
    public function getuserlist() {
    $option=array();
    $sql='SELECT * FROM contactus ORDER BY id DESC';
    $query=$this->db->query($sql);
    while($row=$query->_fetch_assoc())
    {
    array_push($option,$row);
    }
    return $option;
    }
    }
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • public function savehotel($state,$city,$areaid,$area,$photo,$hname,$address,$price,$stars,$reviews)
    {
    $sql='insert into hotel(state,city,areaid,area,image,hotelname,address,price,stars,reviews)
    values('$state','$city','$areaid','$area','$photo','$hname','$address','$price','$stars','$reviews')';
    mysql_query($sql);
    return true;
    }
    public function gethotel()
    {
    $options=array();
    $sql='select * from hotel';
    $query=$this->db->query($sql);
    while($row=$query->_fetch_assoc())
    {
    array_push($options,$row);
    }
    return $options;
    }

    public function gethoteldetails($id)
    {
    $options=array();
    $sql='select * from hotel where id='$id'';
    $res=mysql_query($sql);
    $options=mysql_fetch_array($res);
    return $options;
    }
    public function updatehotel($state,$city,$area,$photo,$hname,$address,$price,$stars,$reviews)
    {
    $sql='update product SET
    state='$state',
    city='$city',
    areaid='$areaid',
    area='$area',
    photo='$photo',
    hname='$hname',
    address='$address',
    price='$price'
    stars='$stars'
    reviews='$reviews'
    where id='$hotelid'';
    mysql_query($sql);
    return $sql;
    }

    public function approvehotel($hotelid,$val)
    {
    $sql='update hotel SET approve='$val' where id='$hotelid'';
    mysql_query($sql);
    return true;
    }
    public function activehotel($hotelid,$val)
    {
    $sql='update hotel SET active='$val' where id='$hotelid'';
    mysql_query($sql);
    return true;
    }
    public function deletehotel($hotelid)
    {
    $sql='update hotel SET deletes='Yes' where id='$hotelid'';
    mysql_query($sql);
    return true;
    }
    }
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • class User_model extends CI_Model {
    /* CONSTRUCTOR FUNCTION */

    function __construct() {

    parent::__construct();
    $this->db = $this->load->database('default', TRUE);
    }
    //this function will take input from controller and save in contactus to database

    public function logincheck($email,$password) {
    $sql = 'select * from employe where email='$email' AND password='$password'';
    $res=mysql_query($sql);
    $numrow=mysql_num_rows($res);
    if($numrow>0)
    {
    $row=mysql_fetch_array($res);
    $userdata=array('USERNAME'=>$row['name'],'EMAIL'=>$row['email'],'ID'=>$row['id'],'ROLEID'=>$row['role']);
    $this->session->set_userdata($userdata);
    return true;
    }else{
    return false;
    }
    }
    public function logout() {
    $userdata=array('USERNAME'=>'','EMAIL'=>'','ID'=>'','ROLEID'=>'');
    $this->session->set_userdata($userdata);
    $this->session->set_flashdata('msg', '
    Thank you for your interest will get back to you soon !');
    return true;
    }
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
18,561
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
218
Comments
7
Likes
11
Embeds 0
No embeds

No notes for slide

Transcript of "Modular PHP Development using CodeIgniter Bonfire"

  1. 1. Fairfield County PHP Meetup Modular PHP dev usingCodeIgniter Bonfire
  2. 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. 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. 4. Modular DevelopmentTaking HUGE monolithic applicationsand breaking them into manageable pieces
  5. 5. Modular Development "How the heck do we do that?"
  6. 6. Model, View, Controller Controllers handle requestsModels Views present informationrepresent data to the user
  7. 7. 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
  8. 8. 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
  9. 9. CodeIgniterCodeIgniterApplication Flowchart
  10. 10. Hierarchical Model, View, ControllerHMVC Triadscall on and use otherMVC triads toaccomplish goals ofthe application
  11. 11. CodeIgniter Bonfire
  12. 12. Bonfire BasicsCodeIgniter• 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
  13. 13. Bonfire BasicsCodeIgniter• 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
  14. 14. Bonfire BasicsCodeIgniter• 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
  15. 15. Functional HighlightsCodeIgniter• 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
  16. 16. Functional HighlightsCodeIgniterThemes 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
  17. 17. Functional Highlights CodeIgniterThemes and Templates – ExamplesTemplate::set(current_url,current_url());Template::set_message(The commentsselected were successfully deleted.,success);Template::set_view(comments/index);Template::render();
  18. 18. Functional HighlightsCodeIgniterMigrations• 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. 19. Functional HighlightsCodeIgniterpublic 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");}
  20. 20. Functional HighlightsCodeIgniterAssets Lib• Allows you to add JavaScript, images and CSS automatically in the head and/or footer of the siteAssets::add_js($this->load->view(thread_view_js,array(thread_id=>$thread_id), true),inline);
  21. 21. Functional HighlightsCodeIgniterModular Everything•All core Dashboard features are modules • Users • Translate Tool • Activities • Module Builder • Migrations • Logos • Permissions • Emailer • Roles • UI • Settings • Updater • Sysinfo • Database
  22. 22. Functional HighlightsCodeIgniterEasy InstallTwo step installLike Wordpress
  23. 23. Bonfire TeamCodeIgniter Lonnie Ezell Nuno Costa Project Founder Ben Evans Icehawg Sean Downey and many more on Github.com Shawn Crigger
  24. 24. Anatomy of aBonfire Module
  25. 25. General StructureCodeIgniter• 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.
  26. 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. 27. Naming Conventions CodeIgniterControllers• 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. 28. Naming ConventionsCodeIgniterAuto-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. 29. Naming ConventionsCodeIgniterManually 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
  30. 30. ConfigCodeIgniter• config.php contains a simple array that identifies the module to the application and contain its 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. 31. ControllersCodeIgniter• 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
  32. 32. ViewsCodeIgniter• 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 theyre organized outside context rules or how theyre called
  33. 33. MiscCodeIgniter• 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
  34. 34. PracticalExample
  35. 35. Q&A
  36. 36. Resources
  37. 37. Resources CodeIgniter • Bonfire Learning Center http://www. http://cibonfire.com/docs/guides/ • Github Repository https://github.com/ci- bonfire/Bonfire
  38. 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. 39. Resources CodeIgniter Example Modules: • News: https://github.com/jfox015/Bonfire- News • Comments: https://github.com/jfox015/Bonfire- Comments
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×