Welcome Guest, Not a member yet? Register   Sign In
Strange problem with $this->load->view
#11

[eluser]coolfactor[/eluser]
Please paste your entire Articles index() function.

Also, do you have *any* redirects in that controller, anywhere?
#12

[eluser]Dionysius[/eluser]
[quote author="coolfactor" date="1196329158"]Please paste your entire Articles index() function.

Also, do you have *any* redirects in that controller, anywhere?[/quote]

Code:
function index()
    {

        $sec_id = (int)$this->uri->segment(2);

        $start = (int)$this->uri->segment(3);

        if (!$sec_id) redirect('');

        $sec_type = (bool)$this->ArticlesModel->is_newstype($sec_id);

        if ($sec_type) {
            $this->load->library('pagination');


            $config['uri_segment'] = 3;
            $config['base_url']    = base_url() . 'articles/' . $sec_id;
            $query = $this->db->query('SELECT id FROM articles WHERE section_id = ' . $sec_id);
            $config['total_rows'] = $query->num_rows();
            $config['per_page'] = '10';
            $config['first_link'] = '<<';
            $config['last_link'] = '>>';

            $this->pagination->initialize($config);

            $data['links'] = $this->pagination->create_links();


            $data['articles'] = $this->ArticlesModel->get_articles($sec_id, $sec_type, $start, $config['per_page']);
        } else {

            $data['articles'] = $this->ArticlesModel->get_articles($sec_id, $sec_type);
        }


        if (!$data['articles']) redirect('');

        if (count($data['articles']) == 1) redirect('articles/view/' . $data['articles'][0]->id);

        $data['sec_type'] = $sec_type;
        $data['sec_id'] = $sec_id;

        $data['sections'] = $this->SectionsModel->get_all();

        foreach ($data['sections'] as $item) {
            if ($item->id == $sec_id) $data['title'] = $item->name;
        }

        $data['intro'] = $this->SectionsModel->get_intro($sec_id);

        $this->load->view('articles', $data);
    }

There are 3 redirect() calls. But they are not called when I go to URL articles/<number>
#13

[eluser]coolfactor[/eluser]
First off, the function itself should be written without making any assumptions about custom routes.

That means this line:
Code:
$sec_id = (int)$this->uri->segment(2);

...should be changed to:
Code:
$sec_id = (int)$this->uri->rsegment(3); // rewritten-segment

...or get the parameters from the function arguments:
Code:
function index($sec_id = 0, $start = 0) {

Both ways will isolate the custom routing from the function definition.

---

I suspect the problem is happening with this redirect:
Code:
if (!$data['articles']) redirect('');

Try adding this code before that line to see exactly what is in the $data array:
Code:
var_dump($data);
exit();

You might find that $data['articles'] is evaluating to FALSE for some reason.
#14

[eluser]Dionysius[/eluser]
[quote author="coolfactor" date="1196348953"]First off, the function itself should be written without making any assumptions about custom routes.

That means this line:
Code:
$sec_id = (int)$this->uri->segment(2);

...should be changed to:
Code:
$sec_id = (int)$this->uri->rsegment(3); // rewritten-segment

...or get the parameters from the function arguments:
Code:
function index($sec_id = 0, $start = 0) {

Both ways will isolate the custom routing from the function definition.

[/quote]
Done. But it didn't change anything.
[quote author="coolfactor" date="1196348953"]
I suspect the problem is happening with this redirect:
Code:
if (!$data['articles']) redirect('');
[/quote]
I did it yesterday. See this thread from the beginning. $data['articles'] is not empty when $sec_id == 1 or 2.
#15

[eluser]Dionysius[/eluser]
I found the problem! It was in method called 'view'. In PHP5 controller may has method with such name, but in PHP4 it has strange behaviour.




Theme © iAndrew 2016 - Forum software by © MyBB