CodeIgniter Forums
Strange problem with $this->load->view - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Strange problem with $this->load->view (/thread-4472.html)

Pages: 1 2


Strange problem with $this->load->view - El Forum - 11-27-2007

[eluser]Dionysius[/eluser]
Hi to all!
Here my routes.php:
Code:
$route['articles/:num'] = "articles/index";
$route['articles/:num/:num'] = "articles/index";

$route['files/:num'] = "files/index";
$route['files/:num/:num'] = "files/index";

Here is my test site based on CI 1.5.4: http://z-nsk.ru/ci/

URL http://z-nsk.ru/ci/files/3 works good. It loads controller "files" which gets data from DB.
But http://z-nsk.ru/ci/articles/<number> doesn't work correctly - it redirects to home page. I have found that all code in "articles" controller works correctly till string
Code:
$this->load->view('articles', $data);
It redirects browser O_o
If I changes it to
Code:
echo "blah-blah";
$this->load->view('articles', $data);
it says
Quote:blah-blah
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/z-nsk.ru/httpdocs/ci/system/application/controllers/articles.php:64)

Filename: helpers/url_helper.php

Line Number: 455
I can't understand WHY? If I changes this piece of code to
Code:
$this->load->_ci_load(array('view' => 'articles', 'vars' => $this->load->_ci_object_to_array($data), 'return' => false));
it works good!

Can somebody explain this mysticism?

And else: URL http://z-nsk.ru/ci/articles/view/<number> doesn't work anyway.

And all of these problems didn't appear at localhost.

Info:
Server: CentOS, Apache 2.0.52, PHP 4.3.9
Localhost: Windows XP, Apache 1.3.33, PHP 5.1.6


Strange problem with $this-&gt;load-&gt;view - El Forum - 11-27-2007

[eluser]Dionysius[/eluser]
Well, I just have changed PHP on localhost to 4.4.2 from 5.1.6 and these troubles appeared.
Now I know, that this is a problem of PHP 4.


Strange problem with $this-&gt;load-&gt;view - El Forum - 11-28-2007

[eluser]Dionysius[/eluser]
If I change code of view() method to
Code:
echo "blah-blah";
//return $this->_ci_load(array('view' => $view, 'vars' => $this->_ci_object_to_array($vars), 'return' => $return));
it redirects to home page anyway. I can't understand why redirect() method is called.


Strange problem with $this-&gt;load-&gt;view - El Forum - 11-28-2007

[eluser]xwero[/eluser]
I'm guessing it has to do with the code in the view file where you use a url helper method. As you can see the error is generated from that file.


Strange problem with $this-&gt;load-&gt;view - El Forum - 11-28-2007

[eluser]Dionysius[/eluser]
But there are not redirect() calls in the view file articles.php. And I can change "articles" in $this->load->view() to "footer". footer.php has pure HTML. But result will be the same: redirecting to home page. Sad


Strange problem with $this-&gt;load-&gt;view - El Forum - 11-28-2007

[eluser]Dionysius[/eluser]
ups...


Strange problem with $this-&gt;load-&gt;view - El Forum - 11-28-2007

[eluser]Michael Wales[/eluser]
Then it has to do something with your routing or are you using caching?


Strange problem with $this-&gt;load-&gt;view - El Forum - 11-28-2007

[eluser]Dionysius[/eluser]
No, I don't use caching.


Strange problem with $this-&gt;load-&gt;view - El Forum - 11-28-2007

[eluser]Michael Wales[/eluser]
Paste your routing.


Strange problem with $this-&gt;load-&gt;view - El Forum - 11-28-2007

[eluser]Dionysius[/eluser]
[quote author="walesmd" date="1196294103"]Paste your routing.[/quote]
It is in my first post.
.htaccess
Quote:RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]