call a action on view file

hi everybody,

i am struggling with a simple logical functionality here.

i want to know that how could we call a action in a view file like a cakephp’s requestaction method…so i can call any action in a view file and get a result of this action in this view file…

does any body can help me regarding this problem…

and i am pretty sure that there will be a definitely this kind of method will be available in yii…

but the problem is that…i could find this answer.that is why i am sharing my this problem with you pepole…

thanks in advance…

To make your confusion clear… here i am describing you.what exactly i want to do.

for eg :- My records are printing on a view file in a loop. but i want to show some additional information regarding to these records along with them.

that is why i want to call an action at run time in a loop which will fetch additional information of a particular record and print it on a view file.

we have a method with a name requestAction in cakephp…I hope same thing will be present in a Yii framwork also.

I can do this work on a view file with a sql execution. but i dont want to run any sql in a loop on a view file…since this is not an good approach of MVC architecture.

I hope you people will get my point now.

Any help would be appreciated. Thanks in advance…

I still don’t understand why would you call an action on every loop…

How about having a method inside the model… and calling it on every loop?

yeah i do agree with you…i know why we have a misunderstanding about a calling a action in view file…because as you told me that you haven’t work in cakephp.that is why this kind of misunderstanding is taking place between our views…

anyways its not a big deal… i hope you got my this point.so you can answer me this time.

As you are saying that having a method inside a model and call it in a loop…would you please elaborate me how could it will be possible in the term of syntex with yii…

i know that i don’t have a too much experience level same as you in developing fields. that is why i couldn’t get you point exactly in a once.

please reply me with my query…!!!

m waiting for a positive response from you.

thanks in advance.

It would be easier if you wrote a bit more about your data… for example what additional data you need and where are they - in the same model or in another model…

But

Let’s say you have a model Record

in the Record model you can create a new method like:




public additionalData()

{

   //do whatever you need to get the additional data

   //return the data in an array or whatever type you need

}



now in the view you are looking through all the records like




foreach($records as $record)

{

   //get additional data

   $additionalData = $record->additionalData();

}



The code is just a template… hope you understand the concept…

yes…here i am explaining a bit more about it…!!

let’s suppose i want to show post records from my post model…and i am using a Cpagination widget in my view for a listing…

Now i want to show some additional data like comments of each post,and related photographs of each post.which will come from different model…

so it is obvious that i will right a loop to print all records from post model…

now each post record have a unique key…on which basis i want to fetch regarding comments and photos from two different model.and want to display just below the post record…

this is what i want to do…but got confuse how could it will be possible…

i hope this time it is more clear to you…so you can answer me more clearly this time…

The idea is still the same… you just need the relations set… and call the appropriate model…

sorry but could you show me some proper syntex for a model,view and controller file…so i can get you point exactly… :(

Thanks mdomba,

i have done this work as you guided me…thanks for your advice… :)