Solved

Troubleshooting CodeIgniter

Posted on 2013-01-07
8
374 Views
Last Modified: 2013-01-08
I'm trying to understand some CodeIgniter code that has landed my lap and I'm a bit frustrated by not being able to echo out variables for troubleshooting.  That is, echoes in the controller classes don't seem to work, so I can't see what variables are being handled. Admittedly I'm new to CodeIgniter and haven't gone  though the entire manual yet (though I did look for a troubleshooting section and didn't find one).  I ordered a couple of Amazon books tonight, but they're no help until they get here.

I wonder if someone out there might have some CodeIgniter experience and be able to say a few words about how you troubleshoot CodeIgniter projects. The framework seems well thought out so I have to believe there's some help built in that I just don't know about.

Thanks for any info.
Steve
0
Comment
Question by:steva
  • 4
  • 3
8 Comments
 
LVL 30

Expert Comment

by:Marco Gasi
ID: 38753740
You can't echo variables from within a controller. You can create a test view which ou pas data to and then you print out them on screen.

if in your controller you have something like

  public function Hello($name)
  {
    $data['base'] = $this->base;
    $data['css'] = $this->css;
    $data['mytitle'] = 'Welcome to this site';
    $data['mytext'] = "Hello, ". ucfirst($name) "!";
    $this->load->view('hello', $data);
  } 

Open in new window

You can replace the standard view with a test view where you only print out $data to check if they are correct:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>Web test Site</title>
<base href= <?php echo $base; ?>>
<link rel="stylesheet" type="text/css" href="<?php echo "$base/$css";?>">
</head>
<body>
<?php 
echo $mytitle . "<br />"; 
echo $mytext . "<br />"; 
?> 
</body>
</html>

Open in new window


If you post hewree some code we can help better.

Cheers
0
 
LVL 26

Assisted Solution

by:EddieShipman
EddieShipman earned 50 total points
ID: 38755092
I just write my variables out to a file and then examine:
$fp = fopen("/var/tmp/".__CLASS__.".txt", 'a');
fwrite($fp, $variable_to_record . "\n");
fclose($fp);

Open in new window

0
 

Author Comment

by:steva
ID: 38755267
Marqus, Thanks.  That helps.  

I appreciate your offering to look at some code.

Here's the beginning of an editor.php file that creates an editor class, that's giving me some trouble:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Editor extends CI_Controller {
	
	/* Constructor */
	
	public function __construct()
	{
		parent::__construct();
		$this->load->helper(array('fgimages','language'));
		
		if (is_allowed() === FALSE)
		{
			exit;
		}
		
		$this->config->load('uploader_settings', TRUE);
	}

Open in new window

I see from the online manual that the helper "array" seems to use the first parameter as key into the array named by the second parameter and return the value there.  But there's no "language" array that I can find in the code.  And where is the value found transferred to?  It gets "loaded" but into what?

Also, the line
                  if (is_allowed() === FALSE)
is a bit puzzling.  is_allowed() doesn't seem to be a PHP construct and it doesn't show up in the online index of the CodeIgniter books I ordered from Amazon.

Thanks for your help.
Steve
0
 

Author Comment

by:steva
ID: 38755310
Eddie,

Thanks for that tip. I keep expecting, though,  to find a whole bag of troubleshooting tools built into CodeIgniter.  I guess not.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 30

Expert Comment

by:Marco Gasi
ID: 38755886
Hi.

$this->load->helper(array('fgimages','language'));
This laine loads two helpers: fgimages and language. The second one resides in system/helpers and it's a standard CI helper. The first one seems to be a custom helper and you could find it, if it is not in system/helpers folder, within application/helpers folder.

I'm sure is_allowed is a function of fgimages helper which checks if the image type is allowed against an array mayby in the config file or in the fgimages_helper itself.

If you dont find fgimages helper in the folders I mentioned above, look around through your directory tree.

Cheers
0
 
LVL 30

Accepted Solution

by:
Marco Gasi earned 450 total points
ID: 38755976
For debugging purposes, you have to choose a log threshold in file application/config/config.php. This is what you should find in your config.php file:
|--------------------------------------------------------------------------
|
| If you have enabled error logging, you can set an error threshold to
| determine what gets logged. Threshold options are:
| You can enable error logging by setting a threshold over zero. The
| threshold determines what gets logged. Threshold options are:
|
|	0 = Disables logging, Error logging TURNED OFF
|	1 = Error Messages (including PHP errors)
|	2 = Debug Messages
|	3 = Informational Messages
|	4 = All Messages
|
| For a live site you'll usually only enable Errors (1) to be logged otherwise
| your log files will fill up very fast.
|
*/
$config['log_threshold'] = 0;

Open in new window


The output file will be in application/logs folder but you can set another path in config.php:

/*
|--------------------------------------------------------------------------
| Error Logging Directory Path
|--------------------------------------------------------------------------
|
| Leave this BLANK unless you would like to set something other than the default
| application/logs/ folder. Use a full server path with trailing slash.
|
*/
$config['log_path'] = '';

Open in new window


Hope this helps.

I don't know which book have you about CI: I'm now reading "CodeIgniter for Rapid PHP Application Development" by David Upton: it speaks about CI 1.7 so not all is right but it seems to be a good manual. Anyway you can find some info here: http://ellislab.com/codeigniter/user-guide/general/errors.html

Cheers
0
 

Author Comment

by:steva
ID: 38757126
Marqus,

Yes, I found "language_helper.php" in the system/helpers directory and "fbimages_helper.php" was in application/helpers. " is_allowed.php"  was a file in the project folder, at the same level as ci, which just returns true, for now.

One of the books I ordered ("CodeIgniter for Rapic PHP Application Development") came today, so I'll jump off into that now.  

Thanks for all your help.

Steve
0
 
LVL 30

Expert Comment

by:Marco Gasi
ID: 38757834
Thanks for points and best of luck with your project.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now