Welcome Guest, Not a member yet? Register   Sign In
CI pagination class question
#1

[eluser]i_am_using_ci[/eluser]
Hi, I want to use pagination class in my controller

I set:

$pagination_config = array(
'base_url' = base_url . '/controller/method/page/',
...
);

So my URLs looks like:
http://site.com/controller/method/page/
http://site.com/controller/method/page/20
http://site.com/controller/method/page/40

The question is:
How can I get page variable value from my URL?
#2

[eluser]Xelgen[/eluser]
Why not, to use just a parameter in your controller method?

Code:
function method($page="")
    {        
        echo "My current page is $page";
        }

Well yes, it's not exactly a page, but number of skipped elements, but it's what you've asked if I understood you right.
#3

[eluser]i_am_using_ci[/eluser]
[quote author="Xelgen" date="1232145223"]Why not, to use just a parameter in your controller method?

Code:
function method($page="")
    {        
        echo "My current page is $page";
        }

Well yes, it's not exactly a page, but number of skipped elements, but it's what you've asked if I understood you right.[/quote]

My $page is being set to 'page' this way.

But is there some way to have possibility of treating 'page/value' argument in URL as $page = 'value' php construction?

I need to determine page variable and it's value in my method.
#4

[eluser]Xelgen[/eluser]
[quote author="i_am_using_ci" date="1232145699"][quote author="Xelgen" date="1232145223"]Why not, to use just a parameter in your controller method?

Code:
function method($page="")
    {        
        echo "My current page is $page";
        }

Well yes, it's not exactly a page, but number of skipped elements, but it's what you've asked if I understood you right.[/quote]

My $page is being set to 'page' this way.

But is there some way to have possibility of treating 'page/value' argument in URL as $page = 'value' php construction?

I need to determine page variable and it's value in my method.[/quote]

Ah, my mistake.
Well you can use smth:

Code:
function method($action, $num="")
    {        
        if ($action=='page')
        {
            echo "We have a pagination request, and my current page is $num";
            // OR if you really want reasignign value to a new variable
            $page=$num;
        }
    }

The optimal way depends solely on your system's controller/URL architecture, so anything we can tell you here, are just examples.
#5

[eluser]ELRafael[/eluser]
you can use uri->segment(n) to get the variable from URL.

remmember to use uri_segment in the config array for pagination.

here the code runs smooth, no problem detected Tongue
#6

[eluser]i_am_using_ci[/eluser]
Okay, understood both Smile
Thank you..

Problem solved, but I have theoretical question:

If I have URL, for example: http://site.com/controller/method/param1...ction/post

Is there anyway to derermine which is key and where's it's val?
I mean If I dunno how much params I have (dynamic count) is there way to determine this?
#7

[eluser]ELRafael[/eluser]
Is really necessary so many params in the url?

Why you can't send this params in POST or another way? I don't think that GET method is the best in this case.

You can use something like this:
Code:
$segs = $this->uri->segment_array();

foreach ($segs as $segment)
{
    echo $segment;
    echo '<br />';
}
http://ellislab.com/codeigniter/user-gui...s/uri.html
#8

[eluser]i_am_using_ci[/eluser]
Okay, thanks, ELRafael! Smile




Theme © iAndrew 2016 - Forum software by © MyBB