Modular PHP Development using CodeIgniter Bonfire
Upcoming SlideShare
Loading in...5
×
 

Modular PHP Development using CodeIgniter Bonfire

on

  • 14,581 views

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

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

Statistics

Views

Total Views
14,581
Views on SlideShare
14,574
Embed Views
7

Actions

Likes
7
Downloads
155
Comments
7

3 Embeds 7

https://twitter.com 3
https://si0.twimg.com 2
http://twitter.com 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…

  • $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';
    }
    Are you sure you want to
    Your message goes here
    Processing…
  • 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;
    }
    }
    Are you sure you want to
    Your message goes here
    Processing…
  • 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;
    }
    }
    Are you sure you want to
    Your message goes here
    Processing…
  • 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;
    }
    }
    Are you sure you want to
    Your message goes here
    Processing…
  • 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;
    }
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Modular PHP Development using CodeIgniter Bonfire Modular PHP Development using CodeIgniter Bonfire Presentation Transcript

  • 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 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 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 present informationrepresent data to the user
  • 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
  • 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
  • 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-built Administrative Dashboard• Rich user authentication workflow• Variety of site admin tools and utilities
  • 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
  • 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
  • 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
  • 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
  • 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();
  • 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
  • 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");}
  • 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);
  • 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
  • Functional HighlightsCodeIgniterEasy InstallTwo step installLike Wordpress
  • Bonfire TeamCodeIgniter Lonnie Ezell Nuno Costa Project Founder Ben Evans Icehawg Sean Downey and many more on Github.com Shawn Crigger
  • Anatomy of aBonfire Module
  • 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.
  • 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 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
  • 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.
  • 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
  • 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
  • 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
  • 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
  • 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
  • PracticalExample
  • 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