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…
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.
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.
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…
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…