Welcome Guest, Not a member yet? Register   Sign In
Calling a model from a view?
#6

[eluser]bretticus[/eluser]
Why bother putting that code in the view at all? The point of the view is to abstract as much business logic away from it as possible. Yes, you have to put a textual representation in the view, but I see no reason why you can't pass the computed value to the view as a single variable?


Yes, it's a good idea to abstract this to a model (by the way, a model has essentially the same accessibility as a controller in CI. In other words, controller and models have pretty much the same access to database resources, etc.) But, this is probably something that won't be called often and probably doesn't rely too much on the rest of the framework for functionality. Thus, it probably fits the library paradigm better.

Try something like:


Code:
<?php
// controller
function the_page()
        $random = "sddkldksdklds";
        $password = "password";

        $this->load->model('Encrypt');
        $data['secure'] = $this->Encrypt->passwordencrypt($random, $password);
        
}
?>

Code:
<html>
    <head>

    </head>
    <body>
        <?=$secure?>
    </body>
</html>


Messages In This Thread
Calling a model from a view? - by El Forum - 03-13-2010, 10:20 PM
Calling a model from a view? - by El Forum - 03-13-2010, 10:21 PM
Calling a model from a view? - by El Forum - 03-13-2010, 10:26 PM
Calling a model from a view? - by El Forum - 03-13-2010, 10:28 PM
Calling a model from a view? - by El Forum - 03-13-2010, 10:57 PM
Calling a model from a view? - by El Forum - 03-14-2010, 01:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB