• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to call controller from view without form submission ?

Quote:Thanks for reply. Is there any way to do like i have my leftsidebar_contolle,leftsidebar _model and leftsidebar _view so i can load them once and use in application. like other controller,model,views we use.

This does not feel right but you could do it with MVC but I think that would be overkill.

If I were doing this, I would create a template library. The library could call by default your model methods for filling in whatever data you need for the left, right, top, bottom or whatever nav bars or blocks you wanted. Then render the page appropriately using the default views needed to construct the page, and then render whatever view you actually need for the page. Using setters you can set the page view in your controller then render the page by calling the relevant method in the library. If you ever need to change the sidebar or topbar you just change your template library. Once it is all working though, your controller just collects the page data you need, sets the view you want and calls the template render function. It can be as complex or simple as you want.

Here is a very simple example from a simple site I built needing data in a similar way,

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

Template_library {
// set some page_data defaults
public $page_data = array();
  public function 
$this->CI =& get_instance();

  public function 
// render a page
    // get books for header nav
$this->page_data['books'] = $this->CI->book_model->get_books();
// get data types for page usage
$this->page_data['data_types'] = $this->CI->data_model->get_data_types();
// render view
  public function 
set_page_data($name$data NULL
$this->page_data[$name] = $data;

And associated controller method just for example usage
PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');

Dashboard extends CI_Controller {
    public function 
// setting template data

// breadcrumb
$breadcrumb = array(
'link' => 'dashboard''link_text' => 'Home''link_active' => TRUE),

// getting some data for the page

// render page

Edited down for example. Please don't mock poor coding :-)

Hope that helps,


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.