Please enable JavaScript.
Coggle requires JavaScript to display documents.
W20 - PHP Frameworks [18/26] working with DB (Views (Dynamic Data in View,…
W20 - PHP Frameworks [18/26] working with DB
CodeIgniter
enable developers to develop
much faster
by
providing rich set of libraries
for
commonly needed tasks
as well as
a simple interface
to access these libraries
CodeIgniter URLs
example.com/blog/
CodeIgniter will attempt to find controller named
*blog.php
and load it.
All controllers
extend
CI_Controller
.
In this example **index method" will be loaded as deafult
Controllers
example.com/index.php/products/sandals/123
This method will look for a method called products and pass on sandals and 123 as parameters
Views
Views
can never be called directly
, must be
loaded
by a controller
$this->load->view('name')
Dynamic Data in View
Adding Data
$data = array(
'title' => 'My Title',
'heading' => 'My Heading'
);
$this -> load -> view('name', $data);
Accessing Data
They are
accessed directly
<title><?php echo $title ?></title>
Models
example of controller loading model and serving view
class blog extends CI_Controller {
public function blogger(){
$this->load->model('blog_model');
$data['query'] = $this->blog_model->get first ten entry();
$this -> load -> view('blog', $data);
}
}
Auto-Loading
feature that permits
libraries, helpers and models
to be
initialised automatically
every time system runs
Routing
There is a
one-to-one
relationship between URL string and corresponding controller class/method
Routing allows to
remap this relationship
so that a
different class/method
can be called
examples
$rout['prduct/:num'] = 'catalog/product_lookup'
$route['product/(:any)'] = 'catalog/product_lookup'
$route['product'] = 'blogs'