Welcome Guest, Not a member yet? Register   Sign In
calling a public controller method from within a view
#1

[eluser]0x0b4dc0d3[/eluser]
I have searched high and low, and I cannot determine how to call a controller method from within a view. Is it possible? Is there a better solution?

Thanks in advance.
#2

[eluser]0x0b4dc0d3[/eluser]
Actually, I can see why this is not "MVC-compliant" and I should really just pass whatever data I need to the view from within the controller. Is that correct?
#3

[eluser]philm[/eluser]
[quote author="0x0b4dc0d3" date="1254516406"]Actually, I can see why this is not "MVC-compliant" and I should really just pass whatever data I need to the view from within the controller. Is that correct?[/quote]
Bingo! :-)
#4

[eluser]n0xie[/eluser]
[quote author="0x0b4dc0d3" date="1254516406"]Actually, I can see why this is not "MVC-compliant" and I should really just pass whatever data I need to the view from within the controller. Is that correct?[/quote]
The short answer: Yes.

The long and generally more advanced answer: what you ask for can be done with some adjustments. wiredesignz has written several enhancements to the CI framework which make this possible, either through modules or widgets although it might be a bit advanced for someone just trying to get his feet wet.
#5

[eluser]0x0b4dc0d3[/eluser]
Thanks for all the info.
#6

[eluser]bigtony[/eluser]
I agree will all the previous comments, but as an aside it's worth remembering that you can easily setup helpers with functions that do stuff useful for a view.

Here's an example:
Code:
/*
* Returns a formatted decimal value for viewing
*/
function format_decimal($value, $currency='£', $decimals=2) {
    return  $currency . number_format($value, $decimals);
}

Then in your view:
Code:
<p>The cost is &lt;?php format_decimal($some_value); ?&gt;, a great bargain!</p>
Which will produce something like "The cost is £1,234.56, a great bargain!"




Theme © iAndrew 2016 - Forum software by © MyBB