Welcome Guest, Not a member yet? Register   Sign In
Call function from "views"
#11

[eluser]Thorpe Obazee[/eluser]
you can call model methods from views like in the controller as per MVC.

Code:
$this->yourmodel->get_the_settings('name');

I don't think you can do that with a controller.
#12

[eluser]Mareshal[/eluser]
I tried that before reading your post. Thank you anyway.

In a model I wrote the function I needed, then $this->load->model('md'); echo $this->md->my_f("something");

echo because my_f has a return at end.

thank you
#13

[eluser]n0xie[/eluser]
[quote author="Mareshal" date="1245419071"]Ok, my mistake.

"I want to pass some post variables to the controller FROM view file without putting them into url or sessions." sorry.
[/quote]
You mean you want to read the $_POST array from your controller?

You can use
Code:
$this->input->post('field');
#14

[eluser]Thorpe Obazee[/eluser]
[quote author="Mareshal" date="1245419650"]I tried that before reading your post. Thank you anyway.

In a model I wrote the function I needed, then $this->load->model('md'); echo $this->md->my_f("something");

echo because my_f has a return at end.

thank you[/quote]

no problem Tongue
#15

[eluser]Mareshal[/eluser]
problem was solved with a model.

Edit: I think wasn't solved. Something is not working:

I have in my model this:
Code:
<?php

class Dates extends Model{
    
    function Dates(){
        
        parent::Model();
        
    }
    
    function diff($date1 , $date2){
        
        $result = 0;
        
        if( $date1 >= $date2 )
            
            $result = $date1 - $date2;
            
        else
        
            $result = $date2 - $date1;
            
        return $result;
        
    }
    
}

?>

and in views/main_index.php I have this:
Code:
$this->load->model('dates');

echo $this->dates->diff("12", "23");

and doesn't want to work.

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_Loader::$dates

Filename: views/main_index.php

Line Number: 6

Fatal error: Call to a member function diff() on a non-object in E:\xampp\htdocs\em\system\application\views\main_index.php on line 6

In my controller if I write the last code is working, but in views...
#16

[eluser]Mareshal[/eluser]
Oh dear, my mistake again. Models can't be loaded in views, I think. So I loaded my model in controller constructor, and now is working.




Theme © iAndrew 2016 - Forum software by © MyBB