This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

phamvuduycuong15027
phamvuduycuong15027

I want to call a function which I was create in Model, into List - Partial. So is there have anyway to call function like this? Thanks

Crazymodder
Crazymodder

Hi phamvuduycuong15027,

That sounds not the right way. You want to call a function to get some data? Than please call your function from controller and pass the data to your view/partial. If you want to make a POST Request a controller has to respond to this. In Controller method surly you can call a method in your model. If you dont like the page reload please check http://octobercms.com/docs/cms/ajax for ajax Calls.

Regards Crazymodder

philipptempel
philipptempel

Even though you shouldn't be doing that, as @Crazymodder said, since views should only contain view logic (the most should actually be if``s,for```s and stuff like that) you can call any model function in your view just as you want.

Imagine a model has a method convertToBar and that model is in the view with name foo you can do {% set bar = foo.convertToBar %} works with or without the parentheses.

But again, views should only contain view logic, every data processing and preparing should be done in our controller or model.

Last updated

phamvuduycuong15027
phamvuduycuong15027

@Crazymodder and @philipptempel thank you guys!

hamza.berjamy22350
hamza.berjamy22350

any solution for this problem.. I have the same problem, i want to call a member function in my view.. Help please

1-5 of 5

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.