Welcome Guest, Not a member yet? Register   Sign In
Pagination suggestions?
#1

[eluser]gRoberts[/eluser]
hi all,

I've only been using CI for a little while, and I am currently rebuilding a site using it.

I've come across a problem where I can't use parameters on the index unless I call the index directly.

Basically I have this piece of code which works great on a url like http://example.com/controller/method/sort:asc/page:1

Code:
$segs = $this->uri->segment_array();
            
            $page = 1;
            $sort = 'asc';
            $view = 'thumb';
            $type = 'random';
            $maxPerPage = 5;
            
            foreach($segs as $seg) {
                $se = explode(':', $seg);
                if(count($se) > 1) {
                    switch(strtolower($se[0])) {
                        case 'page' :
                            $page = $se[1];
                        break;
                        case 'sort' :
                            $sort = $se[1];
                        break;
                        case 'view' :
                            $view = $se[1];
                        break;
                        case 'type' :
                            $type = $se[1];
                        break;
                    }
                }        
            }

Any suggestions without having the index in the url?

Cheers
#2

[eluser]gRoberts[/eluser]
I think I have found a solution already, but I need a way to be able to stop the parent::controller() from trying to load the non-existant method.

This is what I have in place.

Code:
function Categories() {
            
            parent::Controller();
            require BASEPATH . 'application/libraries/System.php';    
            $segs = $this->uri->segment_array();
            if(preg_match('/:/', $segs[1]) > 0) {
                $this->index();
                die();
            }
            
        }

But I assume parent::Controller() is throwing the 404 error before it can reach the rest of the code.

Any idea's?

Thanks
#3

[eluser]gRoberts[/eluser]
I should of RTFM.

Just for reference I used the _remap function, which allowed me to check whether the function being requested was actually a parameter.

Code:
function _remap($method) {            
            $segs = $this->uri->segment_array();
            switch($method) {
                case 'manage' :
                    $this->manage($segs[3]);
                break;
                case 'view' :
                    $this->view();
                break;
                case 'add' :
                    $this->add((isset($segs[3]) ? $segs[3] : 'search'));
                break;
                default:    
                    $this->index();                
                break;
            }
        }

Great heh!




Theme © iAndrew 2016 - Forum software by © MyBB