[fw-general] Zend Form Error Decorators

2009-06-22 Thread kwylez

I have my current form setup to use a table layout without any issues except
for when I try to apply my Error decorators.

Before the form is submitted the form should look like:

tr
  td id=email-label
label for=email class=formLabel required1. Your Email
Address*/label
  /td
  td class=formInput
input type=text name=email id=email value= requiredSuffix=*
size=30
div class=hintWe guarantee we won't spam you/div
  /td
/tr
.


if an error needs to be displayed then the error message should display
underneath it's corresponding form element, which it does.  My problem is
that if I apply my custom error decorator, if there isn't an error message
then I get double tr tags around the elements:

form id=signup enctype=application/x-www-form-urlencoded action=
method=posttable
trtrtd id=email-labellabel for=email class=formLabel
required1. Your Email Address*/label/td
td class=formInput
input type=text name=email id=email value= requiredSuffix=*
size=30
div class=hintWe guarantee we won't spam you/div/td/tr/tr
trtrtd id=pass-labellabel for=pass class=formLabel required2.
Choose Password*/label/td
td class=formInput
input type=password name=pass id=pass value= requiredSuffix=*
size=30
div class=hintMinimum of 8 characters/div/td/tr/tr
trtrtd id=password_confirm-labellabel for=password_confirm
class=formLabel required3. Verify Password*/label/td

td class=formInput
input type=password name=password_confirm id=password_confirm
value= requiredSuffix=* size=30/td/tr/tr
trtrtd id=username-labellabel for=username class=formLabel
required4. Choose Username*/label/td
td class=formInput
input type=text name=username id=username value= requiredSuffix=*
size=30/td/tr/tr

// standard element decorator
  protected $_standardElementDecorator = array(
'ViewHelper',
array('Description', array('escape' = false, 'tag' = 'div')),
array(array('data' = 'HtmlTag'), array('tag' = 'td', 'class' =
'formInput')),
array('Label', array('tag' = 'td', 'class' = 'formLabel')),
array(array('row' = 'HtmlTag'), array('tag' = 'tr')),
array('HtmlTagError', array('tag'='tr'))
  );

//HtmlTagError
?php

require_once 'Zend/Form/Decorator/HtmlTag.php';

class Site_Form_Decorator_HtmlTagError extends Zend_Form_Decorator_HtmlTag {

  public function render($content) {

// Get element contained by decorator
$element = $this-getElement();

// Get view object
$view= $element-getView();

if (null === $view) {
  return parent::render($content);
}

$errCount = 0;

// If not a single element, get elements and all associated error
messages
if (method_exists($element, 'getElements')) {
  $elements = $element-getElements();
  foreach ($elements as $el) {
if ($el-getMessages()) {
  // Count errors
  $errCount++;
  $errors[] = $el-getMessages();
}
  }
} else {
  // If single element, get error messages
  $errors = $element-getMessages();
}

if (0 == $errCount  empty($errors)) {
  return parent::render($content);
}

// Add error class to HtmlTag tag.
// Use array merge to ensure that existing options are persisted
$options = $this-getOptions();

if (array_key_exists('class', $options)) {
  $options['class'] = $options['class'] . ' error';
} else {
  $options['class'] = 'error';
}

$this-setOptions($options);

// Set up the FormErrors view helper
$displayErrors = new Zend_View_Helper_FormErrors();
$displayErrors-setView($view);
$displayErrors-setElementStart('td class=error colspan=2')
  -setElementSeparator(br/\n)
  -setElementEnd(/td\n);

// If only one field has errors
if (0 == $errCount) {
  $html= $displayErrors-formErrors($errors);
  $content .= $html;
} else {
  // If more than one field has errors (usually a display group)
  $html = '';
  foreach ($errors as $error) {
$html .= $displayErrors-formErrors($error);
  }
  $content .= $html;
  // Append generic error message to content
  //$content .= 'p class=errorThis is a required field/p';
}

// Render HtmlTag decorator
return parent::render($content);
  }
}


Any suggestions?
-- 
View this message in context: 
http://www.nabble.com/Zend-Form-Error-Decorators-tp24158654p24158654.html
Sent from the Zend Framework mailing list archive at Nabble.com.



[fw-general] Override escape value for certain subform elements

2009-03-02 Thread kwylez

How do I override the 'escape' value for a given element inside of a subForm?

Is this correct?
   
$this-getSubForm('shiptoaddress')-getElement('country')-addDecorator('Errors')-setOption('escape',false);

-- 
View this message in context: 
http://www.nabble.com/Override-escape-value-for-certain-subform-elements-tp22293199p22293199.html
Sent from the Zend Framework mailing list archive at Nabble.com.



[fw-general] Zend Http Client Adapter Socket Error with Zend RSS

2008-11-25 Thread kwylez

I am getting the following error when I try to consume any RSS feed.  Below
is the code I am using (from the manual)

?php
ini_set('display_errors', 1);

require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();

print function_exists('stream_context_create') ? true : false; //prints
true

// Fetch the latest Slashdot headlines
try {
$slashdotRss =
Zend_Feed::import('http://rss.slashdot.org/Slashdot/slashdot');
} catch (Zend_Feed_Exception $e) {
// feed import failed
echo Exception caught importing feed: {$e-getMessage()}\n;
exit;
} catch (Zend_Http_Client_Adapter_Exception $zhcae) {
print $zhcae-getMessage();
exit;
}

// Exception  that is thrown
Unable to Connect to tcp://rss.slashdot.org:80. Error #-1077097640: 
-- 
View this message in context: 
http://www.nabble.com/Zend-Http-Client-Adapter-Socket-Error-with-Zend-RSS-tp20689403p20689403.html
Sent from the Zend Framework mailing list archive at Nabble.com.



Re: [fw-general] Session DB Save Handler Lifetime Override

2008-11-13 Thread kwylez

Goran

You are the man!

I had gotten close today, but your post was the insight that I needed.

That worked PERFECTLY.


Goran Juric wrote:
 
 
 
 kwylez wrote:
 
 Everything works great at this point.  I can start my sessions (user
 login) and see the information in the database.  My question is how do I
 get the session lifetime to change from the default, 1440 seconds, to the
 remember_me_seconds, 2592000.
 
 
 Zend_Session::rememberMe($sessionLifetime);
 $saveHandler = Zend_Session::getSaveHandler();
 $saveHandler-setLifetime($sessionLifetime)
 -setOverrideLifetime(true);
 
 Regards,
 
 Goran Juric
 http://gogs.info/
 

-- 
View this message in context: 
http://www.nabble.com/Session-DB-Save-Handler-Lifetime-Override-tp20444102p20488565.html
Sent from the Zend Framework mailing list archive at Nabble.com.



[fw-general] Session DB Save Handler Lifetime Override

2008-11-11 Thread kwylez

In a global config file I have setup my zend session options:

!-- config snippet --
session
  params
save_path/var/www/zend_sessions//save_path
!-- Remember session for one month --
remember_me_seconds2592000/remember_me_seconds
  /params
/session

!-- end config snippet --


/**
 * Set the Zend session options (global config)
 */
Zend_Session::setOptions($globalConfig-session-params-toArray());

In my bootstrap I am passing my zend session db information to the session
handler:

/**
 * Zend Session handling will be turned over to the database instead of
the file
 * system.
 *
   * NOTE: this config is also passed to Zend_Db_Table so anything specific
   * to the table can be put in the config as well
   */
$sessionConfig = array(
'name'  = 'sjcrh_session', //table name as per
Zend_Db_Table
'primary'   = array(
'session_id',   //the sessionID given by php
'save_path',//session.save_path 
'name' //session name
),
'primaryAssignment' = array( //you must tell the save handler which
columns you
  //are using as the primary key. ORDER
IS IMPORTANT
'sessionId',  //first column of the primary key is of
the sessionID
'sessionSavePath',//second column of the primary key is the
save path
'sessionName'//third column of the primary key is the
session name
),
'modifiedColumn'= 'modified', //time the session should
expire
'dataColumn'= 'session_data', //serialized data
'lifetimeColumn'= 'lifetime', //end of life for a specific
record
);

/**
 * Tell Zend_Session to use your Save Handler
 */
Zend_Session::setSaveHandler(new
Zend_Session_SaveHandler_DbTable($sessionConfig));


Everything works great at this point.  I can start my sessions (user login)
and see the information in the database.  My question is how do I get the
session lifetime to change from the default, 1440 seconds, to the
remember_me_seconds, 2592000.

In my login script I check to see if a user as selected the remember me
checkbox so their session TTL is extended.

I have tried a variety of ways, but when I query the lifetime column it
still remains 1440.

-Cory
-- 
View this message in context: 
http://www.nabble.com/Session-DB-Save-Handler-Lifetime-Override-tp20444102p20444102.html
Sent from the Zend Framework mailing list archive at Nabble.com.



[fw-general] Lucene Crawler Not Adding to Index

2008-08-11 Thread kwylez

I am working from the crawler example code found here:
http://www.google.com/url?sa=tct=rescd=1url=http%3A%2F%2Fwww.zend.com%2Ftopics%2FImprove-your-PHP-Applications-Search-Capabilities-with-Lucene.pdfei=y2qgSIiJHpHovAWBn9z-BQusg=AFQjCNHBU8vre59KVlgn0fV2O3h6B6bKMwsig2=QTi5S9NULQDB4t30admvFQ

For some reason the contents from the page aren't being indexed.  In my log
files everything stops at: Before add document

None of the log messages after are showing up.

Is there something that I am missing:

code

public function crawlerAction() {

$this-_helper-viewRenderer-setNoRender();

$this-_logger-info(Crawler initialized);

/**
 * Setup Zend_Http_Client
 */
$client = new Zend_Http_Client();
$client-setConfig(array('timeout' = 30));

$indexpath = $this-_globalConfig-lucene-index;

try {

$this-_index = Zend_Search_Lucene::open($indexpath);

$this-_logger-info(Opened existing index in 
{$indexpath});

} catch (Zend_Search_Lucene_Exception $e) {
  try {

$index = Zend_Search_Lucene::create($indexpath);
$this-_logger-info(Created new index in {$indexpath} 
);

/**
 * If both fail,give up and show errormessage
 */
  } catch (Zend_Search_Lucene_Exception $e) {

$this-_logger-err(Failed opening or creating index in
{$indexpath});
$this-_logger-err($e-getMessage());

print Unable to open or create 
index:{$e-getMessage()};
exit(1);
  }
}

/**
 * Setup the targets array
 */
$targets = array($this-_globalConfig-lucene-url);

$this-_logger-info(Target count: . count($targets));

/**
 * Start iterating
 */
for ($i = 0; $i  count($targets); $i++) {

  /**
 * Fetch content with HTTPClient
 */
$client-setUri($targets[$i]);

$response = $client-request();

  if ($response-isSuccessful()) {

$body = $response-getBody();

$this-_logger-info(Fetched .strlen($body). bytes from
{$targets[$i]});

$body_checksum = md5($body);

$this-_logger-info(Body checksum {$body_checksum});

$this-_logger-info(Index: .Zend_Debug::dump($this-_index, ,
false));

$hits = $this-_index-find('url:'.$targets[$i]);

$this-_logger-info(Hits: .count($hits));

$matched = false;

foreach ($hits as $hit){

$this-_logger-info(Hit md5 {$hit-md5} : checksum
{$body_checksum});

if ($hit-md5 == $body_checksum) {

if ($matched == true) {
  
$index-delete($hit-id);
  $matched = true;
}

} else {

$this-_logger-info({$targets[$i]} is out of date and 
needs
reindexing);
$index-delete($hit);
}

if ($matched){

$this-_logger-info($targets[$i]. is uptodate, 
skipping);
  continue;
}
}

/**
 * Create document
 */
$doc = Zend_Search_Lucene_Document_Html::loadHTML($body);

$this-_logger-info(Url {$targets[$i]});

$doc-addField(Zend_Search_Lucene_Field::UnIndexed('url',
$targets[$i]));
$doc-addField(Zend_Search_Lucene_Field::UnIndexed('md5',
$body_checksum));

$this-_logger-info(Before add document);

/**
 * Index
 */
$this-_index-addDocument($doc);

$this-_logger-info(After added the doc);

$this-_logger-info(Indexed {$targets[$i]});

/**
 * Fetch new links
 */
$links = $doc-getLinks();

$this-_logger-info(Get links.Zend_Debug::dump($links));

foreach($links as $link){

if (strpos($link,
$this-_globalConfig-lucene-index)(!in_array($link, $targets))) {
 $targets[] = $link;
}
}

  } else {
$this-_logger-warn(Requesting {$url} returned HTTP
{$response-getStatus()});
  }
}

$this-_logger-info(Iterated over .count($targets).documents);
$this-_logger-info(Optimizing index...);


[fw-general] htaccess problem - routing requests

2007-08-27 Thread kwylez

I have the following directory structure for my Hello World ZendFramework
MVC app.

/(www directory)
  zf-tutorial/
application/
controllers/
  FooController.php
  IndexController.php
models/
views/
  scripts/
foo/
  bar.phtml
index/
  index.phtml
  add.phtml
index.php
.htaccess (Contents - RewriteEngine on RewriteRule
!\.(js|ico|gif|jpg|png|css)$ index.php)

If I navigate to: http://my-site.com/zf-tutorial then I see the results from
the index controller and action

However if I navigate to: http://my-site.com/zf-tutorial/foo/bar then I get
a 404 error.  It seems that the .htaccess file is not rerouting like it
should.  Is there something that I am missing?

Thanks,
Cory


-- 
View this message in context: 
http://www.nabble.com/htaccess-problem---routing-requests-tf4336762s16154.html#a12352645
Sent from the Zend Framework mailing list archive at Nabble.com.