Log in

View Full Version : Pagination Help..


FounderSim
02-27-2016, 10:58 PM
I am having trouble getting the pagination class to work in class_profile.php

I have the following code:


$total = $mysidia->db->select(DUMMY_TEXT")->rowCount();

if($total > 0)
{


$pagination = new Pagination($total, 10, "profile/view/{$mysidia->input->get("user")}");
$pagination->setPage($mysidia->input->get("page"));
///query loop result
$stmt = $mysidia->db->select("dummy_table", array("fieldID"), "DUMMY_QUERY ORDER BY fieldID LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}");
$document->addLangvar($pagination->showPage());
}




It shows the text:
http://www.afangame.com/dirty/pagination.png
It navigates the to the page; url = www.dummyurl.com/profile/view/siminator/page-5

I can't fetch page #5 for some reason =0... Any ideas.

FounderSim
02-29-2016, 03:36 PM
Nobody has any ideas?

Kyttias
02-29-2016, 08:57 PM
I don't know how to use the pagination class, sorry. =/ I'd love to have it work on the profiles, too. I ended up using an iframe and I hate my solution.

FounderSim
03-01-2016, 08:53 PM
It seems like the problem lies in the class_input.php file

In class_userprofile.php I got this line


$mysidia->input->get("page")


In the class_input.php file I got this:


/**
* The get method, returns a user input var stored in Input::$get property.
* @param String $key
* @access public
* @return Object
*/
public function get($key = ""){
echo $key;
if(empty($key) and $this->get instanceof HashMap)
{
return $this->get;
}
else
{
echo ' = ' . $this->get->get(new String($key)) . "<BR>";
return $this->get->get(new String($key));
}
}



Output:

frontcontroller = index
appcontroller = profile
user = siminator
frontcontroller = index
appcontroller = profile
appcontroller = profile
appcontroller = profile
frontcontroller = index
appcontroller = profile
user = siminator
user = siminator
user = siminator
user = siminator
user = siminator
user = siminator
user = siminator
user = siminator
user = siminator
page =
user = siminator
frontcontroller = index
appcontroller = profile


@Hall of Famer

Page is always blank... I must be missing something.

FounderSim
03-02-2016, 09:21 PM
I guess I am going to try a little work-a-round. Going to add a line or two to mod-rewrite.

Will keep ya'll posted especially you @kyttias

FounderSim
03-03-2016, 09:33 PM
I came up with a workable solution without I-frames or mod rewritting. Not much code needed. Here it is for profile pages:

The first three lines are just incase a user has a name with "page-" in it. It would totally screw up the script.

$strz = $mysidia->path->getTempRoot() . "profile/view/{$mysidia->input->get("user")}/";
$lenn = strlen($strz);

if(strpos($_SERVER['REQUEST_URI'] ,"page-") == $lenn)
{

$newStr = str_replace($strz . "page-", "", $_SERVER['REQUEST_URI']);
$pageNum = str_replace("/", "", $newStr);
die($pageNum); //shows page #

}

Kyttias
03-04-2016, 01:19 AM
Hmm... so what are all the steps we need to go through?

It'd be awesome if you could post your findings as an actual mod! :usedusedused:

FounderSim
03-05-2016, 02:10 AM
Here's an explanation:

In myadopts.php the pagination class uses this to show "pagination"


$total = $mysidia->db->select("owned_adoptables", array("aid"), "aid {$commandIn} AND owner = '{$mysidia->user->username}'")->rowCount();


$pagination = new Pagination($total, 10, "myadopts");
$pagination->setPage($mysidia->input->get("page")); //Sets CURRENT PAGE


The error lyes in $mysidia->input->get("page") when used in the userprofile pages, it doesn't work at all. It is always blank.

class input get method used in pagination.

I edited styling. Debugging shown in Post #4.

/**
* The get method, returns a user input var stored in Input::$get property.
* @param String $key
* @access public
* @return Object
*/
public function get($key = ""){
if(empty($key) and $this->get instanceof HashMap)
{
return $this->get;
}
else
{
return $this->get->get(new String($key));
}
}


So using the pagination class wasn't a complete waist. The pagination class is fine, its fetching the page # from $_GET[] that was the issue.

In the class_userprofile.php, I duplicated what the FULL URL should look like without page #'s.

$strz = $mysidia->path->getTempRoot() . "profile/view/{$mysidia->input->get("user")}/"; //duplicated URL, no page #

stored length of duplicated URL
$lenn = strlen($strz);

I then checked if page- is next available characters in URL.
if(strpos($_SERVER['REQUEST_URI'] ,"page-") == $lenn)

If page- is the next available characters in URL. I strip out everything but the # by replacing my duplicated URL and "page-" in the REAL URL with nothing.


$newStr = str_replace($strz . "page-", "", $_SERVER['REQUEST_URI']);


Since the pagination class is perfectly OK and it was the class INPUT method get, I just plugged my stripped page # from URL into the pagination class to tell the class what page # I was on.


$pagination->setPage($newStr);



In USE:

$newStr = "";
$strz = $mysidia->path->getTempRoot() . "profile/view/{$mysidia->input->get("user")}/";
$lenn = strlen($strz);

if(strpos($_SERVER['REQUEST_URI'] ,"page-") == $lenn)
{
$newStr = str_replace($strz . "page-", "", $_SERVER['REQUEST_URI']);
}

//use pagination class. set URL. SET PAGE its on. Show pagination navigation.
$pagination = new Pagination($total, 10, "profile/view/{$mysidia->input->get("user")}");

$pagination->setPage($newStr);

$document->addLangvar($pagination->showPage());

Kyttias
03-05-2016, 10:17 AM
Where should this code go inside what file? I'm still not clear on how to use this information to paginate the user pets on the profile. :desudesudesu:

FounderSim
03-05-2016, 11:08 AM
Where should this code go inside what file? I'm still not clear on how to use this information to paginate the user pets on the profile. :desudesudesu:

It will go inside class_userprofile.php somewhere. I modified the file heavily so not sure what the original file looks like anymore. =}