I have a button that toggles a db boolean between true/false in my list view. At current, the button links you to another action of the controller. That action changes the boolean, saves the model, and brings you back to the page you came from. However, this resets the list view pager back to page 1. When you’re going through thousands of records setting this boolean, having to go through a number of pages to get back to where you were has become quite annoying.
Is there a way of doing this inside the list view itself? Ideally, it would be nice for the button to call the boolean toggle action via AJAX, and then refresh the current page of the list view.
That is a solution that I had thought about as well, but on one of my pages I have more than one listview. Additionally, I don’t see a way of getting the current page number as a php variable so I can append it to the links in my listview partial view.
Yes, the url seems to be listviewID_page=$somepage, which was as far as I had gotten as well. However, aside from reading the pager manually in Firebug, I’m unsure how I can access the CPagination object associated with the dataProvider so I can determine within the listview partial view itself what page I’m on, and echo that to the appropriate links.
Something like:
<a href="index.php?r=boolswitch/toggle&page=<?php echo $thePageWeAreOn; ?>">Swap the boolean</a>
I just don’t know how to get $thePageWeAreOn. I tried:
But, I think I’m having a scope problem. $this, within the listview partial view, refers to the page controller, and not to the widget. So, that’s where I’m stuck currently.
For anyone who needs the answer to this, I’ve found a solution. $widget will return your CListView object within the partial view, which has an associated dataProvider. To get your page number, do this:
I had heard that Yii was young but hadn’t realized just how young; I figured I had overlooked something simple (I had), but am surprised that the community didn’t have the answer. Nevertheless, I am finding it mostly a joy to work with, and hope that it continues to grow.
Isn’t it better that you solved yourself the problem… it’s more rewarding in the end… and you get a better understanding of how Yii is working… and that’s just the kind of experince I’m tolking that you need to better understand it…