Tips and Tricks (FAQ)

In this page you can find some useful code snippets to help you thru some common operations with P4A.
One of our beloved users wrote some p4a tips in spanish, check them out!

Newbie FAQ

If you are just getting started with P4A, here are some suggestions to help you get up and running faster:

  • Put the p4a directory in your web server’s document root (avoids potential path issues you don’t need to deal with now).
  • Build your first apps in /p4a/applications (avoids potential path issues you don’t need to deal with now).
  • Read through all of the tutorials and sample apps to see how things work. Cruise

through the docs.

  • Don’t make copies of files (i.e., poor man’s version control) within the hierarchy (causes redeclared class errors).
  • Use all lowercase for database table names (camelCase could produce missing variable

errors).

  • Understand that objects are stored in the session.
  • Get Firefox Web Developer toolbar so you can quickly remove session cookies.
  • Participate in the forum!

Cannot instantiate non-existent class...

If you receive this error probably you’re using aliases in your apache configuration, P4A can work with aliases but cannot autodetect paths, thus if you are simply testing P4A please install it under your document_root without aliases.

If you want to do advanced tests, please open the “index.php” of your application and define the following constants at the beginning of the file

define('P4A_ROOT_PATH', '/fabrizio/p4a'); //the path to the framework root
define('P4A_THEME_DIR', '/home/fabrizio/public_html/themes/default'); //the absolute dir of the selected theme
define('P4A_ICONS_DIR', '/home/fabrizio/public_html/icons/default'); //the absolute dir of the selected icons themes

Cannot redeclare class...

On startup, all of the application’s files in objects/masks are read. If you make a copy of a file as a backup, or copy to make a new class and do not change the name of the class, you will get a class redeclare error.

How can I handle Radio button (or combo box) values using Array Source?

$values = array(); 
$values[] = array("id" => "id1", "desc" => "desc 1");
$values[] = array("id" => "id2", "desc" => "desc 2");
$values[] = array("id" => "id3", "desc" => "desc 3");
 
$array_source =& $this->build("p4a_array_source", "array_source"); 
$array_source->load($values); 
$array_source->setPk("id"); 
 
$field->setType("radio"); // or "select"
$field->setSource($array_source); 
$field->setSourceDescriptionField("id"); // optional, should be detected automatically
$field->setSourceValueField("desc"); // optional, should be detected automatically

How can I install new PEAR packages or 3rd party PHP software?

P4A has “libraries” concept, you have 3 levels of “libraries” in P4A:

  • system libraries (private): p4a_installation_dir/p4a/libraries
  • framework wide libraries: p4a_installation_dir/libraries
  • project wide libraries: project_dir/libraries

You should not touch system libraries, extract your package and copy files in the chosen libraries directory. After that you could simply do a require ‘filename.php’;, all libraries dir will automatically loaded in your include path.

I'm inside a mask and I need some data from another mask, how do I do it?

$p4a =& p4a::singleton();
$p4a->masks->the_mask_you_want->the_object_you_want

the_mask_you_want needs to be already instanced before you access it, otherwise you’ll get a PHP error.

P4A says "This Query returned an error", how can I get more details?

put this line

define("P4A_EXTENDED_ERRORS", true);

in your application’s index.php

Some useful PHP config you should include in your htaccess

php_value magic_quotes_gpc 0
php_value mbstring.func_overload 1
php_value mbstring.internal_encoding UTF-8
php_value session.use_trans_sid 0
 
tips-and-tricks.txt · Last modified: 2007/01/05 04:11 by 151.92.176.3
 
Creative Commons License Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki