Welcome Guest, Not a member yet? Register   Sign In
Execute controller from view
#11

[eluser]schnoodles[/eluser]
The methods you have there should be in a model so for example you have the main controller say

Code:
class Profile extends Controller { function index() { } }

If you want to add stuff like

$this->load->controller(’blogs/lastPosts’, $params)

That should DEFFINITELY go into a model so you can just do

Code:
class Profile extends Controller {
  function index() {
    $data['blogs'] = $this->BlogModel->lastPosts();
    $data['profile'] = $this->ProfileModel->getProfileData();
    $this->load->view('profile',$data);
  }
}

This seperates the DB calls from the controller likes it meant to.
#12

[eluser]wiredesignz[/eluser]
Or the View can call the Model directly.
#13

[eluser]Base Willy[/eluser]
Oh, guys, thank you very much and excuse me for beign unreasonableSmile I just didn't consider the models and this is just what I need. The more i use CI the more i love it Smile
#14

[eluser]llbbl[/eluser]
Checkout the userguide on models.

http://ellislab.com/codeigniter/user-gui...odels.html

But you could also use it as a library.

http://ellislab.com/codeigniter/user-gui...aries.html
#15

[eluser]esra[/eluser]
[quote author="abmcr" date="1193948361"]A question similar: it is possible to call a function of a controller into a function of another controller? For example


function temp(){
?????? how to
$data=$this->function_of_another_controller($parameters);

Thank You[/quote]

The above is possible with the Modular Separation extensions by Zacharias.

Many are handling the multiple controller issue using view fragments which have a dedicated helper. The controller and model code reside in the helper. The helper is loaded in a base controller and all other controllers are extended from the base controller. The view fragments which are loaded by the controller call the helper functions as needed. To access data from a helper, you need to create an instance of the CI super object. Note that this issue is a MVC 2 (Sun Model 2) problem and not a SmallTalk MVC (MVC 1) problem. For anyone who wants to do this, Coolfactor's proposed View library for CodeIgniter is a good solution for loading multiple view fragments in a master view (template). Note this this solution results in poor encapsulation. There are numerous threads on the forums discussing the problem with few solutions.

Someone above mentioned that the controller was not a mediator which is true. There are two popular architectural design patterns for handling nested controllers--PAC (Presentation-Abstraction-Control and HMVC (Hierarchial-Model-View-Controller). PAC uses the Mediator design pattern to control any number of nested controllers. HMVC uses the Chain of Responsibility design pattern to nest any number of controllers. These patterns are popular in the Java world. The only implementation of a framework based on HMVC for PHP is the abandoned Claw framework (available on Tigris or phpclasses.org). I have yet to see an open source version of a PAC based framework for PHP. Both PAC and HMVC result in much better encapsulation than MVC.
#16

[eluser]Unknown[/eluser]
this is an interesting post. thanks for sharing

simulation rachat de credit
#17

[eluser]garymardell[/eluser]
The person who was looking about calling one controller from another may be interested in http://codeigniter.com/wiki/Wick/ although you shouldn't ever have to really.
#18

[eluser]sumanchalki[/eluser]
HMVC has been implemented in Codeigniter here...
http://codeigniter.com/wiki/Modular_Extensions_-_HMVC/
#19

[eluser]Gilles_T[/eluser]
I'm developing a dashboard where i want to put panels in a window. Searching google for "codeigniter controller call from view" I got this thread which is exactly addressing my request.

Since this thread was opened quite some time ago, are there new way from CI standpoint to do this. I quite liked the Ajax proposal. Would you consider it be a reasonable alternative to HMVC ?
#20

[eluser]rogierb[/eluser]
HMVC and AJAX are two very different approaches. You cannot compare them.
In your case I'm guessing you have a dashboard with a widget like approach. I have something similar and used both HMVC and ajax depending on the widget. Some have both like a widget module with a MVC structure and in the view a 'reload' AJAX function.

In short, the easy way is using (Jquery) AJAX to load something in your dashboard. Just note that is you have a lot of ajax calls your page might be a bit slow to build.

Depending on how big your app is going to be you might want to think about HMVC.

Edit: typos!




Theme © iAndrew 2016 - Forum software by © MyBB