Introduction to Codeigniter 1213899013763633 8

22
Introduction to CodeIgniter

description

ci

Transcript of Introduction to Codeigniter 1213899013763633 8

  • Introduction toCodeIgniter

  • Why use a framework?Web application frameworks provide basic building blocks needed by most applicationsDatabase connectionsBusiness logicForm handlingSeparation of concernsEasier testing (unit tests)

  • Framework Popularity 2013-2014

  • Framework Popularity 2015

  • What is CodeIgniter?CodeIgniter is a lightweight web application framework written in PHP that adopts the model-view-controller approach to development

  • Why use CodeIgniter?Feature richLightweight/RinganOpen sourceWell-supported by an active communityExcellent by example documentationEasy to configureSupports multiple databases

  • Why use CodeIgniter?In short, CodeIgniter is nice because it does what it needs to do and then gets out of the way.

  • *

  • Model-View-ControllerModel representation of the dataView rendering of the data suitable for interaction with the userController the traffic cop that passes model data to the views and vice versaThis separation of concerns allows for greater flexibility, reuse of code, and overall preservation of the developers sanity

  • ControllerA class containing one or more related methods (custom PHP functions)Typical uses:Request a set of data from the model by sending argumentsSend a payload of data to a view (web page)Receive a data payload from a viewApply business logic to make decisionsPass data to the model for inclusion in a database

  • ViewCode that displays information to the userViews can be:Web pages with PHP code snippets insertedWeb pages with forms to gather user inputOther output (CSV, PDF, etc.)

  • ModelA class containing one or more related methods (custom PHP functions)Typical uses:CreateReadUpdateDelete

  • CodeIgniter ClassesCIs built-in classes contain the basic functionality that are frequently used by web applicationsThe most-used classes are:DatabaseInputLoaderURIValidation

  • Database ClassGenerates queries using the Active Record PatternAutomatic escaping of input valuesProvides method chaining for easy query building$this->db->where(name,$name);

  • Input ClassPre-processes user input (prevents common cross-site scripting techniques)Provides access to user input and other data:Form fields (POST)CookiesServer variables$this->input->post(fieldname);

  • Loader ClassMakes various resources available:DatabasesViewsHelpersPlugins$this->load->view(viewname);

  • URI ClassProvides access to specific parts of the URI stringUseful for building RESTful URIs$this->uri->segment(n);

  • Validation ClassHelps validate user form inputRequired fieldsRequired string formatting (length, regexp)Enables success and failure messages on form submittalEnables re-population of form fields after form submittal

  • Other ClassesBenchmarkingCalendaringEmailEncryptionFile uploadingFTPHTML TableImage ManipulationLanguage (internationalization)OutputPaginationSessionTrackbackUnit testingXML-RPCZip encoding

  • Helpers and PluginsCodeIgniter comes with a wide array of helper functions that add convenience to applications and provide ease of reuse.$this->load->helper(helper_name);CodeIgniter also allows for the use of custom add-on functions called plugins.$this->load->plugin(plugin_name);

  • My First CI ApplicationUnzip CI zip file into application folder on web server[optional] For pretty URLs, add .htaccess file and enable mod_rewrite in ApacheConfigure database in CIs Write controller (or modify existing)Write view (or modify existing)Write model

  • Demo

    *