Zoop guide needed

Hi all,

I was just wondering if the "cookbook" will ever be updated and is Zoop capable of handling images in a database I just picked this framework up and still consider myself quite new to PHP.

Also if anyone would kindly revise the CRUD(Create Read Update Delete) tutorial, I think it's title is from A to Zoop to include "SQL where" queries instead of retrieving all of them? I tried following or flow of code but I got confused at forms/table.php

I get this error:
you have modified a field that doesn't exist. Here is an echo of that field

stdClass Object
(
[listshow] => 0
)

as a workaround I just commented out $this->setupRequirements() and manually and had to manually add my own query instead. but for safety I made another getRecords..ok long story short if you could just update the cookbook to include more tutorials(like pagination, gallery demo) would be great.

All the best,
Rax

BTW I got this error after submitting:warning: Invalid argument supplied for foreach() in /usr/local/lib/drupal/5/sites/all/modules/wymeditor/wymeditor.module on line 138.

Images In Database

Zoop should already be able to handle images in a database. How are you trying to use database images?

jmorant@cloud9l... 16 Sep 2008

doing it the "hard" way

doing it the "hard way"

imageviewer.php

 error_reporting(E_ALL);
    // some basic sanity checks
    if(isset($_GET['id']) && is_numeric($_GET['id'])) {
        //connect to the db
        $link = mysql_connect("localhost", "username", "pass") or die("Could not connect: " . mysql_error());
 
        // select our database
        mysql_select_db("mydb") or die(mysql_error());
 
        // get the image from the db
        $sql = "SELECT thumbnail FROM gallery WHERE id=".$_GET['id']."";
 
 
        // the result of the query
        $result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
 
        // set the header for the image
        header("Content-type: image/jpeg");
        echo mysql_result($result, 0);
 
        // close the db link
        mysql_close($link);
    }
    else {
        echo 'Please use a real id number';
    }

some.tpl
<img src="http://myhost/SRIZooped/skeleton/objects/imageViewer.php?id=1" alt="db image"> <--not the most secure way?-->

how do you make queries for DB like "SELECT from some table where"

I also am getting these messages when I choose to clear my browser cache/cookies:

"Warning:  "mkdir() [<a href='function.mkdir'>function.mkdir</a>]: No such file or directory" in file \app\utils.php (on line 1135)"
 
\app\error.php  	49  	fetch_backtrace ()
\app\utils.php 	1135 	mkdir ("C:\xampp\htdocs\SRIZooped-blue/tmp/cache/forms/processed_table_info", 504)
\cache\zcache.php 	87 	mkdirr ("C:\xampp\htdocs\SRIZooped-blue/tmp/cache/forms/processed_table_info/")
\cache\zcache.php 	119 	zcache->zcache (<array>)
\cache\zcache.php 	159 	zcache->_getCacheObj (<array>)
\cache\zcache.php 	181 	zcache->cache ("content", <object>, <array>)
\forms\table.php 	268 	zcache->cacheData ("content", <object>, <array>)
 
Warning:  "fopen(C:\xampp\htdocs\SRIZooped-blue/tmp/cache/forms/processed_table_info/cache_b44d26dc49101cd7423a27b958952e58_9a0364b9e99bb480dd25e1f0284c8555) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory" in file C:\xampp\php\PEAR\Cache\Lite.php (on line 762)
 
backtrace:
 
\app\error.php  	49  	fetch_backtrace ()
C:\xampp\php\PEAR\Cache\Lite.php 	762 	fopen ("C:\xampp\htdocs\SRIZooped-blue/tmp/cache/forms/processed_table_info/cache_b44d26dc49101cd7423a27b958952e58_9a0364b9e99bb480dd25e1f0284c8555", "wb")

Seems like I need to change the strictness of Zoop's error reporting?

thanks finally someone replied :)

rax 19 Sep 2008

Image in DB

What you are doing looks mostly correct, but it seems like you are doing all the database work yourself using standard db methods. It might be easier if you use the DB component for Zoop so you don't waste any time setting up the connection yourself. You entire code can be changed to the below code for Zoop. Please note that in order for your database to have the proper information the thumbnail column must be of type blob and the binary that is in there must be have originally been a jpeg if you are going return a type image/jpeg. Also note that I added the wonderful Zoop function sql_escape_string to clean the value for GET.

//inludes.php
//Make sure you set the correct values in your app config/db.php file for your database
$zoop->addComponent('db');

$result = sql_fetch_one("SELECT thumbnail FROM gallery WHERE id=".sql_escape_string($_GET['id'])." LIMIT 1");
if(empty($result)) {
echo 'Please use a real id number';
} else {
header("Content-type: image/jpeg");
echo($result['thumbnail']);
}

jmorant@cloud9l... 22 Sep 2008

Also

I also notice you have a somepage.tpl at the end of your code indicating that you might be attempting to display a template file after you echo the image binary code. That should not be necessary since you have already called header and then echo which will return the image to the browser.

jmorant@cloud9l... 22 Sep 2008

zoop->addComponent('db')

...does not seem to work?

Call to undefined function sql_fetch_one() in C:\xampp\htdocs\SRIZooped-blue\objects\imageViewer.php on line 2

even though I already added $zoop->addComponent('db') to includes.php

also what is the tag to use when posting PHP code?

here's what my includes looklike:

include_once(dirname(__file__) . "/config.php");
 
include_once(zoop_dir . "/zoop.php");
 
require_once('zoop/forms/forms.php'); //dunno why I have to include the form class here if I don't I get form class not found...--rax
require_once('zoop/forms/forms2.php');
require_once("objects/phpMailer/class.phpmailer.php"); //for the email function used this instead as
//their seems  to be a problem with how PEAR and Zoop manage calls....
 
$zoop = &new zoop(dirname(__file__));
 
$zoop->addComponent('db');
$zoop->addComponent('gui');
$zoop->addComponent('guicontrol');
 $zoop->addComponent('forms');
// $zoop->addComponent('pdf');
// $zoop->addComponent('spell');
// $zoop->addComponent('userfiles');
// $zoop->addComponent('sequence');
$zoop->addComponent('mail');

imageViewer.php

	$result = sql_fetch_one("SELECT thumbnail FROM gallery WHERE id=".sql_escape_string($_GET['id'])." LIMIT 1");
 
		if(empty($result)) {
			echo 'Please use a real id number';
		} else {
			header("Content-type: image/jpeg");
			echo($result['thumbnail']);
		}

gallery.tpl
 
 
<img src="http://localhost/SRIZooped-blue/objects/imageViewer.php?id=1" alt="db image">
 
<!--<img src="{$BASE_HREF}/Gallery/showImage?id=1" alt="db image">-->";

am I missing something here? where can I see the value of {base_href}(so I could play tinker with it?)

thanks...

rax 23 Sep 2008

imageViewer.php

It looks like you are trying to call the imageViewer.php file directly which is ok if it includes the includes.php file. If the include is not provided in imageViewer.php, none of the Zoop db functions will have been defined. You may be better off at that point creating an imageViewer or gallery zone to make better use of the Zoop framework.

If you are getting missing function or class errors for DB functions inside of your zones the include issue you are seeing for forms may also be affecting your db include.

jmorant@cloud9l... 24 Sep 2008

while I am at it..

anyone know how to turn off the display of warning messeges in zoop? I tried the php.ini and define('show_warnings', 1) and I am still getting this message after I clear the browser cache and try to submit from a form:

Warning:  "mkdir() [<a href='function.mkdir'>function.mkdir</a>]: No such file or directory" in file \app\utils.php (on line 1135)
 
Warning:  "fopen(C:\xampp\htdocs\SRIZooped-blue/tmp/cache/forms/processed_table_info/cache_b44d26dc49101cd7423a27b958952e58_9a0364b9e99bb480dd25e1f0284c8555) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory" in file C:\xampp\php\PEAR\Cache\Lite.php (on line 762)
PHP Backtrace

I restarted apache every time I edited the ini btw....
**edit**
just found zoop/app/error.php
and just commented out the lines that display the back trace/errors.. a more logical suggestion offcourse is welcome. sorry guys if I post too much :p

rax 23 Sep 2008

Error reporting

The newest version of zoop(1.5) coming out this week respects the error_reporting setting from php.ini.

Older versions report any and all errors. When in app_status is test or live, then errors are logged, and the user is presented with a code that the developers can use to find the error in the log.

Another thing to consider is that most warnings are potential errors, and should be looked into. It looks like some kind of bug in caching is causing these warnings.

Unfortunately, the only way to avoid displaying warnings in the version of zoop you have is to modify app/error.php.

john 24 Sep 2008

works now

the your version of imageviewer now works. forgot to add this

 
  require_once('../includes.php'); //include db functionality<--did not add this
 
	$result = sql_fetch_one("SELECT thumbnail FROM gallery WHERE id=".sql_escape_string($_GET['id'])." LIMIT 1");
 
		if(empty($result)) {
			echo 'Please use a real id number';
		} else {
			header("Content-type: image/jpeg");
			echo($result['thumbnail']);
		}

I just thought that zoop automatically adds the db functionalities to ALL the php files but I think it only adds that to zones(?).

thanks again and as I have said I just commented/removed parts of zoop/app/error.php to temporarily fix the cache waring messages.

looking forward to the next release,
Rax

rax 25 Sep 2008

zone and page functions

I think we misunderstood you because were expecting something like:
zone_default.php:

class zone_default extends zone
{
    function pageSome($p)
    {
         $this->guiDisplay('some.tpl');
    }
 
    function pageImageViewer($p)
    {
        $id = (int)$p[1];
        $result = sql_fetch_one("SELECT thumbnail FROM gallery WHERE id=".sql_escape_string($id)." LIMIT 1");
        if(empty($result)) {
                echo 'Please use a real id number';
        } else {
                header("Content-type: image/jpeg");
                echo($result['thumbnail']);
        }
    }
}

some.tpl:

<img src="http://myhost/SRIZooped/skeleton/index.php/imageViewer/1" alt="db image">

This is more the zoop way of doing things. We use the front controller for most everything. There's nothing wrong with doing things the way you're doing them, but you lose a bit of the convenience that zoop is there for. We think the best way to do things is to put everything in zones.

john 25 Sep 2008

if it is not in a default

if it is not in a default but in a zone say 'foo' the url in some.tpl would be:

  <img src="http://localhost/SRIZooped-blue/foo/showImage/27" alt="db image2">

and in the foo zone would have a function called:

function showImage($inPath){
 
        $id = (int)$inPath[1];//not sure of the index of the //array but hopefully you get what I mean
 
        $result = sql_fetch_one("SELECT thumbnail FROM gallery WHERE id=".sql_escape_string($id)." LIMIT 1");
 
        if(empty($result)) {
                echo 'Please use a real id number';
        } else {
                header("Content-type: image/jpeg");
                echo($result['thumbnail']);
        }
 
 
}

I can't display the image.... (._.) does
MyZoneName/myFunc/arg1/arg2
means you are executing the "myfunc" from that zone? and to pass arguments just use $pageSend variables?

rax 26 Sep 2008

Zones and Page Functions

Below is the zone exactly as it should exist to access the image tag provided. Please note that for a function in a Zone to be accessed via an HTTP GET request it needs start with the word "page" then the function name. In your code the function cannot be automatically accessed because it does not start with "page". Zoop compares URLs to page and zone names in lower case so the URL can be capitalized in any way you wish.

<!-- HTML Excerpt for image tag -->
<img src="http://localhost/SRIZooped-blue/foo/showimage/27" alt="db image2">

//includes.php excerpt
//Add Zone Foo to Zoop
$zoop->addZone('foo');

//zone_foo.php
class zone_foo extends zone {
function pageShowImage($inPath){
 
        $id = (int)$inPath[1];//not sure of the index of the //array but hopefully you get what I mean
 
        $result = sql_fetch_one("SELECT thumbnail FROM gallery WHERE id=".sql_escape_string($id)." LIMIT 1");
 
        if(empty($result)) {
                echo 'Please use a real id number';
        } else {
                header("Content-type: image/jpeg");
                echo($result['thumbnail']);
        }
 
 
}
}

jmorant@cloud9l... 26 Sep 2008

Zoop way to display image implemented

Finally worked at first it didn't then I realized that the path was:

http://localhost/SRIZooped-blue/foo/showimage/27

instead of:

http://localhost/SRIZooped-blue/index.php/foo/ShowImage/27

it lacked the index.php...have not gotten around to fixing my .htaccess but that is neither here nor there.

12 messages...I apologize and thanks again. :)
Rax..

er..one very last question?
where is

{$BASE_HREF}

set?

rax 26 Sep 2008

{$BASE_HREF}

{$BASE_HREF} is set in zoop/app/globals.php. It's meant to be used as <base href="{$BASE_HREF}"> so that relative links work. If you are creating full urls for use in your html, you should use {$SCRIPT_URL}. If you want the current url, you should use {$VIRTUAL_URL}. {$BASE_HREF} differs based on whether you are using mod_rewrite or not, so is not ideal for building links with.

john 26 Sep 2008