CodeIgniter Forums

Full Version: Call a controller from a Model
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Alface[/eluser]
First I need to know, I know MVC.
I realy need to do it.

Code:
<?php
class Site extends Controller {
    function Site(){
        parent::Controller();
    }

    function say(){
             echo 'hello';
        }
}

Code:
<?php
class Something_model extends Model {

    public function __construct(){
        parent::Model();
    }
    
    function dolikecontroller(){
        // something to call 'say' function from controller
    }
}


There is no libary extention for do it?

Thanks

El Forum

[eluser]theshiftexchange[/eluser]
Whatever your trying to do - wouldnt it be easier making a library yourself, and then have both the controller and the model call that library? Thus achieving the same goal but in true MVC format?

El Forum

[eluser]danmontgomery[/eluser]
Code:
function dolikecontroller() {
    $CI =& get_instance();
    $CI->say();
}

El Forum

[eluser]Alface[/eluser]
Didn't worked.
I was tring to make a xajax aplication faster..

I solved it calling the same function with call xajax on controller

El Forum

[eluser]stuffradio[/eluser]
Woah woah woah, why are you trying to do that? Isn't that kind of backwards!?

El Forum

[eluser]Alface[/eluser]
[quote author="stuffradio" date="1272752731"]Woah woah woah, why are you trying to do that? Isn't that kind of backwards!?[/quote]

Because the Database access is done on controller (I'm using ORM)