Ajax Pagination

Hi

I'm sorry if this has been asked before, did a search, couldn't find anything.

I want to create a list of users with pagination, but don't want to reload the page for navigating between each page of users. How would I go about creating an ajax pagination system?

Would I need to load a partially rendered page into the contain page that contains the pagination links and list, and write the JQuery to reload the page via ajax when a pagination link is clicked by the user.

Thanks

Chris

Yes, you need to attach some jquery code to the pagination links so that clicking them may trigger an ajax request whose response is used to replace the specified content block.

Thanks, shouldn’t be a problem :)

I am having a secondary issue with AR relations.

I am gettting a Invalid argument supplied for foreach() when applying my relation

ER Diagram



User


----


user_id ------------


user_name          |


....               |


                   | member_id FK to user_id PK


GroupMember        |


------------       |


member_id >---------


group_id


The tables are set up as InnoDB and have the foreign key relationships declared.

GroupMembers model



...


public function relations() {


	return array(


		'member' => array(self::BELONGS_TO, 'User', 'member_id'),


	);


}


...


Now I try to find all members of a group relating to their user account, e.g



$memberList = GroupMembers::model() -> with('member') -> findAll();


I get a Invalid argument supplied for foreach() internal server error. Which is weird as I am not even parsing the result into a foreach loop yet.

I am a little clueless as to what I'm doing wrong, as far as I can tell I have followed the documentation correctly and even tried to replicate the blog demo code with no success.

Chris

Does the table have primary key? What is the detailed error info?

The user table has a primary key, and GroupMember table does not, as you can have many groups and many users, it's just a link table holding foreign keys, assigning users to groups.

Here is the debug:



PHP Error


Description





Invalid argument supplied for foreach()


Source File





/home/sites/chris-reeves.com/public_html/yiiBase/framework/db/ar/CActiveFinder.php(507)





00495:     {


00496:         // determine the primary key value


00497:         if(is_string($this->_pkAlias))  // single key


00498:         {


00499:             if(!isset($row[$this->_pkAlias]))    // no matching related objects


00500:                 return null;


00501:             else


00502:                 $pk=$row[$this->_pkAlias];


00503:         }


00504:         else // is_array, composite key


00505:         {


00506:             $pk=array();


00507: foreach($this->_pkAlias as $name=>$alias)


00508:             {


00509:                 if(!isset($row[$alias]))    // no matching related objects


00510:                     return null;


00511:                 else


00512:                     $pk[$name]=$row[$alias];


00513:             }


00514:             $pk=serialize($pk);


00515:         }


00516: 


00517:         // retrieve or populate the record according to the primary key value


00518:         if(isset($this->records[$pk]))


00519:             $record=$this->records[$pk];





Stack Trace





#0 /home/sites/chris-reeves.com/public_html/yiiBase/framework/db/ar/CActiveFinder.php(485): CJoinElement->populateRecord()


#1 /home/sites/chris-reeves.com/public_html/yiiBase/framework/db/ar/CActiveFinder.php(333): CJoinElement->runQuery()


#2 /home/sites/chris-reeves.com/public_html/yiiBase/framework/db/ar/CActiveFinder.php(93): CJoinElement->find()


#3 /home/sites/chris-reeves.com/public_html/yiiBase/protected/controllers/actions/admin/AjaxMemberListAction.php(11): CActiveFinder->findAll()


#4 /home/sites/chris-reeves.com/public_html/yiiBase/framework/web/CController.php(265): AjaxMemberListAction->run()


#5 /home/sites/chris-reeves.com/public_html/yiiBase/framework/web/CController.php(243): AdminController->runAction()


#6 /home/sites/chris-reeves.com/public_html/yiiBase/framework/web/CController.php(225): AdminController->runActionWithFilters()


#7 /home/sites/chris-reeves.com/public_html/yiiBase/framework/web/CWebApplication.php(335): AdminController->run()


#8 /home/sites/chris-reeves.com/public_html/yiiBase/framework/web/CWebApplication.php(123): CWebApplication->runController()


#9 /home/sites/chris-reeves.com/public_html/yiiBase/framework/base/CApplication.php(170): CWebApplication->processRequest()


#10 /home/sites/chris-reeves.com/public_html/yiiBase/index.php(29): CWebApplication->run()


It needs to. A PK is used to uniquely identify a row in a table. You can have composite PK in your case which consists of user id and group id.

Ah, I see, that you :)