Welcome Guest, Not a member yet? Register   Sign In
App Display Problem
#1

[eluser]kenreynolds[/eluser]
I am new to CodeIgniter and have just recently run into my first real snag.

The other day I was experimenting with the calendar library. My controller file is simple, as seen below.

cal.php CONTROLLER FILE:

<?php

class Cal extends Controller {

function index()

$this->load->library('calendar');

$data['title'] = "My first CodeIgniter calendar!";
$data['cal'] = $this->calendar->generate();

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

?>

And here is my view file.

cal_view.php VIEW FILE:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;Calendar&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
<h3>&lt;?php echo $title ?&gt;</h3>
<p>&lt;?php echo $cal ?&gt;</p>
&lt;/body&gt;
&lt;/html&gt;

This worked perfectly the first time I tried it by displaying the $title and the calendar on the page in both Firefox and Safari.

The next day I tried to load the page in Firefox again and this time it displayed a blank page.

My url path is as follows: http://localhost:8888/CodeIgniter/index.php/cal

That is the same path that I used when the calendar displayed properly the first time.

Also, when I navigate to the root folder, http://localhost:8888/CodeIgniter, it does display the default CodeIgniter welcome.php page. It just won't display any other pages that I create.

I am running a local test server using MAMP on a MacBook Pro and my development environment is Dreamweaver CS3. I have gone as far as to completly uninstall and reinstall MAMP, as well as start fresh with a new CodeIgniter download. I have not altered any of the files, save for the base_url section in config/config.php. Everything else is default.

Does anyone have any ideas or suggestions?
#2

[eluser]Narkboy[/eluser]
Ok first up welcome to the forums!

Handy tip - wrap code blocks in "[ code ]" and "[ / code ]" (no spaces!) to have the rendered clearly!

So - first, your controller and view code is fine. Nothing there screams 'problem' and that's backed by the fact that it worked once.

If you can get the 'Welcome' page at the root, then CI is also working fine. However, the root is a specifc route, and everything else may be affected by a routing issue, or something else.

The easiest way to run down where the problem is is to run 'echo' statements inside the controller. Right after the function declaration, drop in:
Code:
echo 'Cal Controller Started!</br>';

Then check if that comes up.

If it does - add in more 'echo's further down to work out when everything stops.

If it doesn't, open up config.php and change 'log_threshold' to '4' - reload the page and check the log file to see what's going on. It's a great tool!

Get back if you still can't get it to go!

/B
#3

[eluser]kenreynolds[/eluser]
Thanks for the tips! I tried placing the echo statement directly after the function declaration and the page was still blank in both Safari and Firefox. I increased the log_threshold to 4, reloaded the page, and got 'No direct script access allowed'. I have pasted the contents of log-2011-01-23.php below.

Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?&gt;

DEBUG - 2011-01-23 15:47:20 --&gt; Config Class Initialized
DEBUG - 2011-01-23 15:47:20 --&gt; Hooks Class Initialized
DEBUG - 2011-01-23 15:47:20 --&gt; URI Class Initialized
DEBUG - 2011-01-23 15:47:20 --&gt; Router Class Initialized
DEBUG - 2011-01-23 15:47:20 --&gt; Output Class Initialized
DEBUG - 2011-01-23 15:47:20 --&gt; Input Class Initialized
DEBUG - 2011-01-23 15:47:20 --&gt; Global POST and COOKIE data sanitized
DEBUG - 2011-01-23 15:47:20 --&gt; Language Class Initialized
DEBUG - 2011-01-23 15:47:25 --&gt; Config Class Initialized
DEBUG - 2011-01-23 15:47:25 --&gt; Hooks Class Initialized
DEBUG - 2011-01-23 15:47:25 --&gt; URI Class Initialized
DEBUG - 2011-01-23 15:47:25 --&gt; Router Class Initialized
DEBUG - 2011-01-23 15:47:25 --&gt; Output Class Initialized
DEBUG - 2011-01-23 15:47:25 --&gt; Input Class Initialized
DEBUG - 2011-01-23 15:47:25 --&gt; Global POST and COOKIE data sanitized
DEBUG - 2011-01-23 15:47:25 --&gt; Language Class Initialized
DEBUG - 2011-01-23 15:47:47 --&gt; Config Class Initialized
DEBUG - 2011-01-23 15:47:47 --&gt; Hooks Class Initialized
DEBUG - 2011-01-23 15:47:47 --&gt; URI Class Initialized
DEBUG - 2011-01-23 15:47:47 --&gt; Router Class Initialized
DEBUG - 2011-01-23 15:47:47 --&gt; Output Class Initialized
DEBUG - 2011-01-23 15:47:47 --&gt; Input Class Initialized
DEBUG - 2011-01-23 15:47:47 --&gt; Global POST and COOKIE data sanitized
DEBUG - 2011-01-23 15:47:47 --&gt; Language Class Initialized
#4

[eluser]kenreynolds[/eluser]
Did a little further troubleshooting. I copied some PHP code for a registration form and tried to view the file in a browser and again got a blank page. The code for the registration form is stored in a completely separate folder from CodeIgniter in htdocs. Next, I created a simple hello world file to test and it displayed in my browser without any issue. The code for that file is below.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;Testing PHP&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;?php

echo "Hello, world";

?&gt;

&lt;/body&gt;
&lt;/html&gt;

Any ideas or suggestions? I can include the code from the registration form, if needed.
#5

[eluser]kenreynolds[/eluser]
Please ignore my previous reply. It turns out that I had a couple of syntax errors in the registration form file.

Concerning my original issue in this thread, I finally checked the php_error log file for the cal.php file mentioned in my original post in this thread, and got the following after trying to view cal.php in my browser:

===== Sunday, January 23, 2011 10:43:37 PM US/Central =====
[23-Jan-2011 22:44:00] PHP Parse error: syntax error, unexpected T_VARIABLE, expecting ';' or '{' in /Applications/MAMP/htdocs/CodeIgniter/application/controllers/cal.php on line 7

And, just to clarify, I am navigating to http://localhost:8888/CodeIgniter/index.php/cal to view the file.

Again, the contents of cal.php is pasted below.

cal.php CONTROLLER FILE

Code:
&lt;?php

class Cal extends Controller {

    function index()
                
        $this->load->library('calendar');

        $data['title'] = "My first CodeIgniter calendar!";
        $data['cal'] = $this->calendar->generate();
        
        $this->load->view('cal_view', $data);
}

?&gt;
#6

[eluser]InsiteFX[/eluser]
Your also missing the Class Constructor, unless you left it out in code.

InsiteFX
#7

[eluser]kenreynolds[/eluser]
I did leave the class constructor out on purpose, not realizing that it is required. Regardless, I did not have any problems displaying the page without it when it worked the first time.

I placed the constructor inside my function, as required, and tried displaying the page again, but it still won't display in any browser.

Here is the updated code:

Code:
&lt;?php

class Cal extends Controller {

    function index()
    
        parent::Controller();
                
        $this->load->library('calendar');

        $data['title'] = "My first CodeIgniter calendar!";
        $data['cal'] = $this->calendar->generate();
        
        $this->load->view('cal_view', $data);
}

?&gt;
#8

[eluser]kenreynolds[/eluser]
Also, I checked the php_error.log after inserting the class constructor and testing again, and got the same error:

===== Monday, January 24, 2011 6:32:29 AM US/Central =====
[24-Jan-2011 06:32:46] PHP Parse error: syntax error, unexpected T_STRING, expecting ';' or '{' in /Applications/MAMP/htdocs/CodeIgniter/application/controllers/cal.php on line 7
#9

[eluser]InsiteFX[/eluser]
Try this.

Code:
&lt;?php

class Cal extends Controller {

    function Cal()
    {
        parent::Controller();
    }

    function index()
    {
        $this->load->library('calendar');

        $data['title'] = "My first CodeIgniter calendar!";
        $data['cal'] = $this->calendar->generate();

        $this->load->vars($data);
        $this->load->view('cal_view');
    }

InsiteFX
#10

[eluser]kenreynolds[/eluser]
Still no luck. Getting the same error message in php_error.log, but on line 20 now:

===== Monday, January 24, 2011 7:02:11 AM US/Central =====
[24-Jan-2011 07:02:16] PHP Parse error: syntax error, unexpected ';', expecting T_FUNCTION in /Applications/MAMP/htdocs/CodeIgniter/application/controllers/cal.php on line 20




Theme © iAndrew 2016 - Forum software by © MyBB