p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 (http://p2p.wrox.com/forumdisplay.php?f=152)
-   -   chapter 13 - MVC (http://p2p.wrox.com/showthread.php?t=26164)

omarosa February 27th, 2005 06:48 PM

chapter 13 - MVC
 
Has anyone gotten the chapter 13 (Model, View, Controller) example working with the code available for download? I downloaded the code and have been testing the search, but it's not working when you enter input that violates the constraints. I've been trying to figure out how to make it work, but I haven't gotten it yet. I've narrowed it down some, but I don't completely understand all the code at this point.

Unfortunately, it seems like other people have been having issues with errors elsewhere throughout the book. This is the first code example I've actually tried from the book. So far, it's been an interesting read, but I wish it'd WORK :(

I'm running IIS 5.1 with PHP 5.0.3 on Windows XP Pro.

Thanks.

omarosa February 28th, 2005 06:26 PM

Well...... after about 3 hours of debugging (which nearly drove me insane), I found the problem is simply a TYPO in constraint.phpm.

Code:

  function GetConstraintType() {
    return($this->_intContraintType);
  }



should be

Code:

  function GetConstraintType() {
    return($this->_intConstraintType);
  }



I'm going to attempt to submit it to the errata section. Hopefully wrox gives a crap.


hillechien March 5th, 2005 03:46 PM

Thanks a million! You saved me hours...
Quote:

quote:Originally posted by omarosa
 Well...... after about 3 hours of debugging (which nearly drove me insane), I found the problem is simply a TYPO in constraint.phpm.

Code:

function GetConstraintType() {
    return($this->_intContraintType);
}

should be

Code:

function GetConstraintType() {
    return($this->_intConstraintType);
}

I'm going to attempt to submit it to the errata section. Hopefully wrox gives a crap.


Hillechien

omarosa March 11th, 2005 01:22 PM

I noticed when you add a few more constraints than what they have in the example, then it doesn't work. It returns back to the original page, but without the error messages. I've been going through this forever trying to figure out where the problem is. Anyone else know? Or have a working example and code they could show?


omarosa March 12th, 2005 08:45 PM

OK, I think the problem is that the cookie is getting too big. I logged the value of the phprqcOriginalRequestObject cookie, and it is set only if I 1) add less constraints with more POST variables, or I 2) use more constraints but use a smaller number of POST variables. Great.

I thought cookie values are just supposed to be truncated, but whatever. I admit I don't know much about them, but... argh.

reconman March 24th, 2005 06:58 PM

I'd like to second hillechien's thanks. Once I prepended searchresults.php with my local path to search.php everything worked as described in the book.

I have the following reservations about the code:

1. The amount of commenting for complex code, particularly in an educational setting, is atrocious.

2. Page 263 states that "There is no provision in the example for displaying YOUR SEARCH PRODUCED NO RESULTS message. However, the implementation of such a message would be relatively straightforward." If it is so easy to implement, why not complete the code and eliminate the confusion caused by getting "empty" results back? One of the major criticisms of this book is that it was difficult to determine if you were dealing with a lack of understanding of the example code or true bugs. That is not an ideal learning experience.

I have read the other comments about this book at the forum and they are generally negative. I like the structure and the selection of "professional" topics. I wish that the implementation had been more professional. There is a huge need for a book such as this and I am not sure that there are decent alternatives currently (anybody have one?). I would rather that Wrox not be defensive about the current edition and simply come up with a plan to resolve the deficiencies. The most obvious is to list the errata on-line. Maybe Wrox feels that the amount of errata would kill sales of the current edition. That might be the good news for all concerned, including Wrox. I don't know why they would wish to damage their reputation by implying that the book in its current state represents acceptable Wrox quality.


omarosa March 24th, 2005 08:32 PM

A note on the last issue I was having with not being able to add more constraints -- I'm temporarily just creating a new request object and testing the constraints for every few constraints I add. This is probably fine for verifying a few things, but I have a couple pages with big forms that it will probably hurt. It's fine with a couple users doing it, but with a substantial amount of traffic, I dunno... I'm still not sure why the problem is occurring.


omarosa April 6th, 2005 05:45 PM

Hmm.... got it to work.

I'm not sure why it wouldn't write the cookie, but I tried using gzcompress/gzuncompress before/after writing the cookie and now it works. You can add as many constraints now and only call TestConstraints() once. Creating additional new requests and calling TestConstraints() was not actually doing what I expected, and was screwing up some other things as well.

I based my code off this example code from http://us3.php.net/manual/en/function.serialize.php :

Code:

<?php
$data[qwerty] = "blah";
$data[1][a] = "1aa";
$data[2][b] = "2bb";
$data[3][c] = ";;;;;;";
$data[name][first] = "Bob";
$data[name][last] = "Jones";
$data[val] = "This is a real long test string, to see how well the compression works!";

//To Serialise Call :
$string = gzcompress(serialize($data), 9);
setcookie("my_var", $string, time()+60*60*24*60, '/');
//print "String: $string\n<br>"; //uncomment to see serialized array

//To Unserialize Call
if (isset($_COOKIE[my_var])) {
  $array = unserialize(gzuncompress($_COOKIE[my_var]));

  echo "<pre>";
  print_r($array);
  echo "</pre>";
}
?>

Essentially, the only changes are (in request.phpm):

in __construct(...)
Code:

$origObj = unserialize(gzuncompress($cookieVal));
in TestConstraints()
Code:

$strSerialization = gzcompress(serialize($objToSerialize), 9);
HTH.



ajit_kunte April 26th, 2005 09:26 AM

can any one help me??????

can't find error parse error.... unexpected $ at end of prog.


Mr_ZLO March 24th, 2009 07:45 AM

it's bug?

I want testing is valid email, and...

Code:

$objConstraint = new constraint(CT_MUSTMATCHREGEXP, "/^[^@\s<&>]+@([-a-z0-9]+\.)+[a-z]{2,}$/i");
$this->request->AddConstraint("reg_email", VERB_METHOD_GET, $objConstraint);

Notice: unserialize() [function.unserialize]

incorrect "\"


All times are GMT -4. The time now is 06:23 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.