Welcome Guest, Not a member yet? Register   Sign In
pagination part2 (help)
#1

[eluser]sasori[/eluser]
hi, I revised my code and now i am getting this error whenever I click the page 2 and so on
here's my controller class
Code:
function index($page = 0)
    {
      $this->load->library('table');
      $this->load->model('stock_model');
      $stocks = $this->stock_model->getStocks($page);
      if($stocks['query']->num_rows() > 0)
      {
        $table = array();
        $table[] = array("Price Percent_change",
                         "Company Name",
                         "Company Code",
                         "Volume");
        foreach($stocks['query']->result() as $row)
        {
          $table[] = array($row->pricepercent,
                           $row->compname,
                           $row->compcode,
                           $row->volume);
        }
        $data['stocks'] = $table;
      }
      $data['heading'] = "Stocks";
      $this->load->library('pagination');
      $config['base_url'] = 'http://myapp/welcome/stocks_view/';
      $config['total_rows'] = $stocks['total_rows'];
      $config['per_page'] = '5';
      $config['uri_segment'] = 3;
      $this->pagination->initialize($config);
      $data['base'] = $this->config->item('base_url');
      $data['css'] = $this->config->item('css');
      $data['title'] = "Stocks Page";
      $this->load->view('stocks_view',$data);
    }

and now here's my model class

Code:
class Stock_model extends Model
{

    function Stock_model()
    {
      parent::Model();
    }

    function getStocks($page)
    {
      $data = array();
      $this->db->limit(5,$page);
      $query = $this->db->get('stocks');
      $query2 = $this->db->get('stocks');
      $total_rows = $query2->num_rows();
      $data['query'] = $query;
      $data['total_rows'] = $total_rows;
      return $data;
    }
}

and here's my view

Code:
<?php

if(!empty($stocks))
{
    echo $this->table->generate($stocks);
}
echo "<br /><br />".$this->pagination->create_links();


?&gt;

the error was
Quote:A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\myapp\system\application\models\stock_model.php:2)

Filename: codeigniter/Common.php

Line Number: 360
Quote:404 Page Not Found

The page you requested was not found.
#2

[eluser]John Pantoja[/eluser]
probably got some whitespace at the top of your model class or so, don't know CI well enough yet put that seems to me a common error when you use header(). Could be something echoing out before and not being buffered or again a whitespace somewhere. Suggest a cut-n-paste in notepad++ with all characters on to double check.

--EDIT--

Or it could be in your view now that I think of it, make sure there is nothing above &lt;?php //just a thought
#3

[eluser]sasori[/eluser]
ok thanks, now i removed the white space from my model..one last problem now
is when i click the succeeding page links of the pagination,
i am getting a 404 page not found
this is the url that appears when I click the page "2" link
Code:
http://myapp/welcome/stocks_view/5
my route is set to "welcome" controller
and the base_url of the config file is $config['base_url'] = "http://myapp/"
and the base_url of the index() of my controller is $config['base_url'] = "http://myapp/welcome/stocks_view/"

I wonder what's going on ?
#4

[eluser]John Pantoja[/eluser]
As far as your 404, how are your routes? Using mod_rewrite by chance? Might need to add
Code:
$route['page/(:num)' = "controller/page/$1";
to your config/routes.php if I understand CI as well as I think (just starting)
#5

[eluser]sasori[/eluser]
that doesn't work Sad
my default controller i
Code:
$route['default_controller'] = "welcome";
#6

[eluser]John Pantoja[/eluser]
Sorry, I'm on the wifes netbook so I have a small screen, your $route and I'm not sure how the pagination writes the urls would be
Code:
$route['(:num)'] = "welcome/stock_view/$1";
but this is based on how the url is though, again I don't know this library enough.
#7

[eluser]sasori[/eluser]
yes it doesn't work
#8

[eluser]n0xie[/eluser]
Quote:and the base_url of the index() of my controller is $config[‘base_url’] = “http://myapp/welcome/stocks_view/”
What do you mean by this?

Your code only shows function index(). I don't see a function stocks_view().
#9

[eluser]John Pantoja[/eluser]
AH I see said the deaf man, I looked at the config lines, I would suggest you refactor and have a controler for pages so your url would be like
Code:
/page/:num
If I gather correctly it's bases off of
Code:
$config['base_url'] = 'http://myapp/welcome/stocks_view/';
$config['uri_segment'] = 3;
so I would change it to
Code:
$config['base_url'] = 'http://myapp/page/';
$config['uri_segment'] = 3; //not sure what this does consult user guide
or to something of that fact. You'll need a new controller and modify the route accordingly
#10

[eluser]John Pantoja[/eluser]
[quote author="n0xie" date="1264001823"]
Quote:and the base_url of the index() of my controller is $config[‘base_url’] = “http://myapp/welcome/stocks_view/”
What do you mean by this?

Your code only shows function index(). I don't see a function stocks_view().[/quote]

thought that was just my screen :red:




Theme © iAndrew 2016 - Forum software by © MyBB