Re: [fw-general] hooking into events and checking an ACL

2016-02-26 Thread David Mintz
I too am a relative n00b but I don't think that's the only problem with
this tutorial. For one thing, it's dated. You don't need to implement your
own Identity plugin because ZF2 already provides:
http://zf2.readthedocs.org/en/latest/modules/zend.mvc.plugins.html#zend-mvc-controller-plugins-identity.


As to Slavey's book: it's really good (
https://www.amazon.com/review/R38Z5NJEX0UP0R/ref=cm_cr_rdp_perm?ie=UTF8&ASIN=1492372218).
I also like http://www.masterzendframework.com/ and
https://samsonasik.wordpress.com/

On Wed, Feb 24, 2016 at 1:21 AM, Simon Walter  wrote:

> Hi all,
>
> I noticed that the HTTP response codes I get back are not the same as when
> running the stack via Apache. I noticed also a few other strange things
> such as content when I expected no content.
>
> It then lead me to inspect packets. What I found was that my protected
> areas were indeed accessible.
>
> The fault lies in the way I was redirecting users to the login page. I had
> followed this tutorial:
>
> http://p0l0.binware.org/index.php/2012/02/18/zend-framework-2-authentication-acl-using-eventmanager/
>
> I just want to caution others who may have done so and have copied this
> buggy code. I've left a comment on the page as well:
>
> http://p0l0.binware.org/index.php/2012/02/18/zend-framework-2-authentication-acl-using-eventmanager/#comment-91368
>
> Looking at Slavey's book, I see that much of what Marco has done in his
> tutorial is over engineered.
>
> I will chance a n00b guess that because the controller and action are not
> reset to something else, the original route is still followed even though a
> 302 is sent with a new location.
>
> I will refrain from drawing any more n00b conclusions and ask what you all
> think.
>
> Kind regards,
>
> Simon
>
> --
> List: fw-general@lists.zend.com
> Info: http://framework.zend.com/archives
> Unsubscribe: fw-general-unsubscr...@lists.zend.com
>
>
>


-- 
David Mintz
http://davidmintz.org/
Human needs before private profit:
http://socialequality.com/


Re: [fw-general] authentication and the EventManager: best place to test if user is logged in

2015-07-17 Thread David Mintz
Right now I am still considering all that -- what if any 3rd party modules
to use -- and just scribbling and learning my way around. Experience has
taught me that it's good to say "first I am just gonna play with this, then
try to do productive work" rather than "I am gonna learn x and y and z at
the same time I build this project."  It's tempting to roll my own for the
exercise (meaning, use ZF components directly), but BjyAuthorize also looks
really tempting.

On Fri, Jul 17, 2015 at 2:08 AM, Jeremiah Small  wrote:

> Maybe you want to roll your own as a practice exercise, but if not, I
> suggest you take a good look at BjyAuthorize. It's basically a module
> implementation of Acl.
> [...]
>



-- 
David Mintz
http://davidmintz.org/
Human needs before private profit:
http://socialequality.com/


[fw-general] authentication and the EventManager: best place to test if user is logged in

2015-07-16 Thread David Mintz
I am just getting started with ZF2 (now that people are talking about ZF3
(-: ) and wondering what the recommended practice is in the following case.
I have a module where I want to require the user be logged in to access any
controller/action under this module, otherwise redirect to a login page (in
another module).

I have experimented with attaching a listener to the 'dispatch' event in my
Module.php's onBootstrap method. Something like :

public function onBootstrap(MvcEvent $e)
{
   /* ...*/

   $eventManager->attach('dispatch', function() use ($e,
$authenticated) {

if (! $authenticated) {
$target = $e->getTarget();
if ($target instanceof
\Zend\Mvc\Controller\AbstractActionController) {
if ( 0 === strpos(get_class($target),'MyModule')) {
$target->redirect()->toRoute('login');
}
}
}

Is this basically the right approach? Or is there a better way to go at
this?

Thanks.

-- 
David Mintz
http://davidmintz.org/
Human needs before private profit:
http://socialequality.com/


Re: [fw-general] Zend Framework 2.0.0beta5 Released!

2012-07-20 Thread David Mintz
On Fri, Jul 6, 2012 at 3:49 PM, Matthew Weier O'Phinney wrote:

> - BC BREAK: REMOVES the following components:
> - Zend\Currency
> - Zend\Date
> - Zend\Locale
> - Zend\Measure
> - Zend\Translator
> - All filters, validators, and view helpers that relied on the
>   above.
>

just curious:  why has Zend_Date been removed?

Thanks.


-- 
David Mintz
http://davidmintz.org/
It still ain't over:
http:/healthcare-now.org/


Re: [fw-general] Re: Over-engineered Zend Form Decorators, help

2011-09-29 Thread David Mintz
On Thu, Sep 29, 2011 at 2:24 AM, David Muir  wrote:

> The way I handle forms is like this:
>
> 
>  
>renderLabel()?>
>renderViewHelper()?>
>  renderErrors()?>
>  
>  …etc…--
>

OMG! THANK YOU! It's reassuring to know that there are others out there who
have done the same thing I do. Decorators too painful for you? AVOID THEM!
You can still enjoy all the other many advantages of Zend_Form and move on
without clawing your eyeballs out.


David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


Re: [fw-general] Zend_Form: adding css class attrib to select option elements

2011-07-22 Thread David Mintz
On Fri, Jul 22, 2011 at 11:22 AM, Kaiuwe  wrote:

> Am 22.07.2011, 17:06 Uhr, schrieb David Mintz :
>
>
>  I noticed that $helper is a public property of Zend_Form_Element_Select,
>> so
>> rather than extending it, I have started working on a custom view helper
>> instead, whose method signature is the same as that of formSelect in
>> Zend_View_Helper_FormSelect.
>>
>> But the $options array that I am going to pass the
>> Zend_Form_Element_Select
>> constructor won't be like array( 1=> apple, 2 => spinach ), but rather
>> array( array(value=>1,label=>spinach, class=>vegetable ), ... )
>>
>> Any thoughts about this approach? I know that it's kind of crude to
>> deliberately abuse Zend_Form_Element_Select's constructor and then give it
>> a
>> custom view helper to make up for it, but it looks like it's gonna work.
>>
>
>
> Use CSS:
>
> option[label='Foo'] {
>background-color: red;
> }
>
> option[label='Bar'] {
>background-color: yellow;
> }
>
> Or look at the issue tracker: http://framework.zend.com/**
> issues/browse/ZF-3580 <http://framework.zend.com/issues/browse/ZF-3580>
>
>

Actually  I'm not concerned about CSS presentation at all. The 'class'
attribute would be strictly semantic, and make it easier to know how to
handle certain 'change' events with jQuery.

The proposal in the issue tracker, if I understand it correctly, presumes
you want all your options to have the same class -- which is less than
trivial to do in js. In my case... well I already explained it earlier.

-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


[fw-general] Zend_Form: adding css class attrib to select option elements

2011-07-22 Thread David Mintz
On Thu, Jul 21, 2011 at 5:19 PM, Bart McLeod  wrote:

> My wild guess is that you should override addMultiOptions in a custom
> select element so that you can add the class attribs.
> -Bart
>
> Op 21-07-11 21:49, David Mintz schreef:
>
>   From my googling I see that this has been asked, and there's no really
>> easy
>> answer, and none of the few answers I found work for my case.
>>
>> Basically, you have a label, a value and a category signified by the css
>> class.  I want the output to be something like
>>
>>apple
>>   spinach
>>   salmon
>>
>> And yes, I know there are option groups for organizing OPTION elements
>> into
>> a hierarchy, but I have my reasons for not wanting to go there.
>>
>> This will all come from a database. In high-level terms, how would you
>> suggest approaching this? What classes/methods would you look into
>> overriding?
>>
>> The purpose is to do fancy tricks using jQuery -- I need to detect the
>> "category" on the change event. I can think of ways of hacking around
>> this,
>> e.g., load a JSON data structure that maps ids to categories and refer to
>> that as needed. But... any other ideas?
>>
>

Thanks Bart.

I noticed that $helper is a public property of Zend_Form_Element_Select, so
rather than extending it, I have started working on a custom view helper
instead, whose method signature is the same as that of formSelect in
Zend_View_Helper_FormSelect.

But the $options array that I am going to pass the Zend_Form_Element_Select
constructor won't be like array( 1=> apple, 2 => spinach ), but rather
array( array(value=>1,label=>spinach, class=>vegetable ), ... )

Any thoughts about this approach? I know that it's kind of crude to
deliberately abuse Zend_Form_Element_Select's constructor and then give it a
custom view helper to make up for it, but it looks like it's gonna work.


-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


[fw-general] Zend_Form: adding css class attrib to select option elements

2011-07-21 Thread David Mintz
>From my googling I see that this has been asked, and there's no really easy
answer, and none of the few answers I found work for my case.

Basically, you have a label, a value and a category signified by the css
class.  I want the output to be something like

   apple
  spinach
  salmon

And yes, I know there are option groups for organizing OPTION elements into
a hierarchy, but I have my reasons for not wanting to go there.

This will all come from a database. In high-level terms, how would you
suggest approaching this? What classes/methods would you look into
overriding?

The purpose is to do fancy tricks using jQuery -- I need to detect the
"category" on the change event. I can think of ways of hacking around this,
e.g., load a JSON data structure that maps ids to categories and refer to
that as needed. But... any other ideas?

Thanks.

-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


Re: [fw-general] Re: How would you handle dynamic forms and validation?

2011-06-25 Thread David Mintz
On Sat, Jun 25, 2011 at 10:39 AM, Jurian Sluiman  wrote:

> On Friday 24 Jun 2011 16:30:18 David Mintz wrote:
> > On Thu, Jun 23, 2011 at 3:31 PM, James Ganong  >wrote:
> > Don't know if this is considered the best of practices, but sometimes in
> my
> > Zend_Form's init(), I examine the request parameters by going
> > Zend_Controller_Front::getInstance()->getRequest() and apply validation
> > logic depending on who they are and what they are trying to do.
> >
> > In your case it seems like you could add as many elements (and their
> > validators and filters) as you need and no more by doing something like
> > that.
>
> I'd rather override Zend_Form::isValid() in that case where for example,
> based
> on a checkbox a set of form elements becomes required:
>
> class MyForm extends Zend_Form
> {
>  public function isValid($data)
>  {
>if (isset($data['shipping']) && (bool) $data['shipping'] === true) {
>  $this->getElement('shipping-address')->setRequired();
>}
>return parent::isValid($data);
>  }
> }
>
> Then you keep you logic within the validation steps and not affecting the
> form
> instantiation.
>
>
I like that. But how about the scenario where you're creating 1 or more
elements client-side that did not exist when the form was first displayed.
Let's say it's a family membership form for a zoo and the parent's contact
data is required, but you want first name, last name, age for zero or more
children, and your form/javascript allows them to add new elements as
needed. What's the best practice for that?

-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


Re: [fw-general] Re: How would you handle dynamic forms and validation?

2011-06-24 Thread David Mintz
On Thu, Jun 23, 2011 at 3:31 PM, James Ganong wrote:

> I have taken the approach Sergey mentions on a few different forms. It is
> by
> far the easiest method. The only drawback is that you have to impose a max
> number of allowed dynamic fields. In most cases this is a good thing as you
> probably don't want to allow anyone to add 100+ of any field.
>
> An alternative is to pass the number of dynamic fields desired to the form
> object when it is created. This way you can still use the built in form
> validation. Then on the front end side, you would need to use javascript to
> clone the dynamic field when a button is clicked (ex: "add email"), or you
> would need to reload the page each time you need to add a field to recreate
> the form. This method is much trickier.
>
>

Don't know if this is considered the best of practices, but sometimes in my
Zend_Form's init(), I examine the request parameters by going
Zend_Controller_Front::getInstance()->getRequest() and apply validation
logic depending on who they are and what they are trying to do.

In your case it seems like you could add as many elements (and their
validators and filters) as you need and no more by doing something like
that.

-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


Re: [fw-general] Re: partialLoop helper with multiple data structures?

2011-05-06 Thread David Mintz
On Fri, May 6, 2011 at 4:31 AM, Wil Moore III wrote:

>
> David Mintz-3 wrote:
> >
> > Wondering if I can (or should try to) use a partialLoop in this scenario.
> >
> The following should work:
>
> foreach ($parents as $parent) {
>  if (isset($children[$parent->id]) {
>$this->partialLoop()->setObjectKey('child');
>echo $this->partialLoop('child.phtml', $children);
>  }
> }
>


Thanks.  I think that either this isn't quite the solution to my particular
problem, or else I don't get it, RTFM notwithstanding. I will keep
exercising my brain on it.

-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


[fw-general] partialLoop helper with multiple data structures?

2011-05-05 Thread David Mintz
Wondering if I can (or should try to) use a partialLoop in this scenario.

In my Zend_View, I have an array of data from a table, like so:

// parents
Array
(
[0] => stdClass Object
(
[id] => 73622
[datef] => Mon 18-Apr-2011
[timef] => 10:00
[type] => conference
[judge] => Berman
[language] => Spanish
[place] => 14A
)

[1] => stdClass Object
(
[id] => 73770
[datef] => Mon 18-Apr-2011
[timef] => 10:20
[type] => vsr hearing
[judge] => Patterson
[language] => Spanish
[place] => 24A
)

) etc

and a couple other arrays containing arrays of child records, like so:


// children
Array
(

 [73662] => Array
(
[0] => stdClass Object
(
[id] => 11159
[surnames] => Ogando
[given_names] => Diógenes
)

)

[73770] => Array
(
[0] => stdClass Object
(
[id] => 10404
[surnames] => Rodriguez
[given_names] => Jose Hernando
)

)
   // etc

)

My idea is to display this by iterating through the parents and checking for
the existence of children

foreach ($parents as $parent) {
   // print columns from parent, and...
if (array_key_exists($parent->id, $children) {
  // display $children[$parent->id]
}
}


and I am wondering if it's possible to use a partialLoop helper for this,
since it seems that the partialLoop helper needs all its data to be passed
in the single $model argument. My sense is that the partialLoop is not
suited to this type of scenario and I am better off with a simple partial
and looping with foreach.

btw I realize I can loop through the parent objects and pre-stuff them with
data from the corresponding children, and then pass that to the partialLoop,
but that seems to defeat the purpose. I also considered doing this in the
model class itself, but it seems inefficient to loop through the whole thing
twice -- once to load up the data structure and then again in the view to
display it.

Any thoughts?

-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


Re: [fw-general] Re: Noob Questions. Please help.

2011-04-12 Thread David Mintz
On Tue, Apr 12, 2011 at 12:56 PM, lordali  wrote:

> Thanks for the explanations.
>
> Actually I have 4+ years of web development experience in ASP.NET. I am
> new
> to PHP and trying to learn it. I am looking for MVC framework to reduce
> learning curve and save development time. Heared about Zend and wanted try
> it.
>
> Is there any sample application with CRUD functionality which I can use to
> learn Zend framework?
>
>
http://framework.zend.com/manual/en/learning.quickstart.html might be
helpful.

-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


Re: [fw-general] the blank screen (no error information)

2011-03-31 Thread David Mintz
On Wed, Mar 30, 2011 at 5:23 PM, Matthew Weier O'Phinney
wrote:

> -- David Mintz  wrote
> (on Wednesday, 30 March 2011, 04:53 PM -0400):
> > On Wed, Mar 30, 2011 at 3:58 PM, Matthew Weier O'Phinney
> > wrote:
> >
> > > -- David Mintz  wrote
> > > (on Wednesday, 30 March 2011, 03:41 PM -0400):
> > > > 2011/3/30 Iñigo Aldama 
> > > > > see the last comment in this page
> > > > > http://php.net/manual/en/errorfunc.configuration.php
> > > > >
> > > > I was over there reading up earlier today (-: That doesn't help me
> > > because I
> > > > already have display_errors set to On in my php.ini. The settings in
> > > > application.ini are redundant, maybe I should have mentioned. And as
> I
> > > did
> > > > mention, I do get error information -- e.g., parse errors -- when I
> > > execute
> > > > non-ZF php files.
> > >
> > > Make sure your error reporting is set to most strict: (E_ALL |
> E_STRICT)
> > > If it isn't, display_errors may not show anything.
> > >
> > >
> > >
> > On my knees in gratitude, I thank you. In my naivete I though E_STRICT
> *was*
> > the most strict so that's where it was set. RTFM.
>
> Yeah, it's pretty unintuitive. The reason is for backwards compatibility
> reasons -- there was already an E_ALL, and E_STRICT added a new bit to
> the mask, basically. Silly PHP. :)
>
>
>
Whoever doesn't like it is welcome to simply remember this:  8191

(-:

-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


Re: [fw-general] the blank screen (no error information)

2011-03-30 Thread David Mintz
On Wed, Mar 30, 2011 at 3:58 PM, Matthew Weier O'Phinney
wrote:

> -- David Mintz  wrote
> (on Wednesday, 30 March 2011, 03:41 PM -0400):
> > 2011/3/30 Iñigo Aldama 
> > > see the last comment in this page
> > > http://php.net/manual/en/errorfunc.configuration.php
> > >
> > I was over there reading up earlier today (-: That doesn't help me
> because I
> > already have display_errors set to On in my php.ini. The settings in
> > application.ini are redundant, maybe I should have mentioned. And as I
> did
> > mention, I do get error information -- e.g., parse errors -- when I
> execute
> > non-ZF php files.
>
> Make sure your error reporting is set to most strict: (E_ALL | E_STRICT)
> If it isn't, display_errors may not show anything.
>
>
>
On my knees in gratitude, I thank you. In my naivete I though E_STRICT *was*
the most strict so that's where it was set. RTFM.


-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


Re: [fw-general] the blank screen (no error information)

2011-03-30 Thread David Mintz
2011/3/30 Iñigo Aldama 

> see the last comment in this page
> http://php.net/manual/en/errorfunc.configuration.php
>
>
>
I was over there reading up earlier today (-: That doesn't help me because I
already have display_errors set to On in my php.ini. The settings in
application.ini are redundant, maybe I should have mentioned. And as I did
mention, I do get error information -- e.g., parse errors -- when I execute
non-ZF php files.



-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


[fw-general] the blank screen (no error information)

2011-03-30 Thread David Mintz
In my development environment I have my error_reporting up to E_STRICT and
display_errors is ON:


[development : production]
resources.frontController.params.displayExceptions = 1
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
phpSettings.error_log = APPLICATION_PATH "/logs/error.log"
phpSettings.log_errors = 1
phpSettings.error_reporting = E_STRICT

I have found that if an Exception is thrown I get a nice stack trace
displayed in the browser. But if the request doesn't get that far -- e.g.,
if the is a parse error in a file or if PHP can't find a file that is
require()ed, nothing. Blank screen. So I just spent the better part of the
past day tracking down an idiotic housekeeping error -- inadvertently
omitting the .php extension on a newly created file.

Weird thing is, I don't think it was always thus, but I haven't explicitly
changed my environment lately. Just accepted some upgrades suggested by
Ubuntu -- including a Firefox upgrade -- but that doesn't seem to be the
issue.

This is ZF 1.10.4. Experimenting with PHP files outside of ZF I get all the
error reporting I expect, so it does look like a ZF issue.

Any suggestions?

-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


Re: [fw-general] Re: after submit form event

2011-03-30 Thread David Mintz
Quite interesting. I rolled my own jQuery plugin to do the same thing. It is
crude, but FWIW here it is:

 http://davidmintz.org/code/ajaxFormPost.js

One thing I like is that it handles tabbed forms created with jQuery UI.

-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


Re: [fw-general] Re: how to use json action context?

2011-03-08 Thread David Mintz
On Tue, Mar 8, 2011 at 7:40 AM, bguery  wrote:

> Hi,
>
> I wrote a plugin to set a defaut format on XHR to avoid you to set the
> format parameter on each request.
>
> You can check it out on github
>
> https://github.com/borisguery/bgylibrary/blob/master/library/Bgy/Controller/Plugin/AjaxContextDefaultFormat.php
>
> Here is an usage example :
>
> http://borisguery.github.com/bgylibrary/#bgylib-components-bgy-controller-plugin-ajaxcontextdefaultformat
>
> Hope that helps
>
>

Just a thought: maybe I am wrong but you might also be able to do something
comparable on the client side with whatever javascript library you're using,
e.g., in jQuery there is $.ajaxSetup().

Either way, IMHO adding the 'format' parameter isn't so ugly or burdensome.

-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


Re: [fw-general] Re: [zf-contributors] Re: [fw-general] Re: [zf-contributors] Discontinuing Maintenance of ZendX JQuery - Suggest drop for 2.0

2011-02-01 Thread David Mintz
On Mon, Jan 31, 2011 at 6:28 PM, Hector Virgen  wrote:

> > Damn. As a high-level userland freeloader I have been loving the
> convenience
> > of doing what seems kind of like time travel --
> > $this->JQuery()->onLoadCaptureStart() -- in my views. I wonder how you
> might
> > hack up something equivalent in ZF 2.0.
>
> I use this:
>
> jQuery(function($){
>// js code goes here
> });
>
> It's regular jquery so you can place it in an external file or use
> $this->headScript()->appendScript($jscode);
>

True, but with the ZendX_JQuery helper, everything you capture in successive
calls to onLoadCaptureStart() get stuffed into the one block:

$(document).ready(function() {

// ... i.e., here

})

and I think that's more elegant that creating multiple $(document).ready()
event handlers.

-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


Re: [fw-general] Re: [zf-contributors] Re: [fw-general] Re: [zf-contributors] Discontinuing Maintenance of ZendX JQuery - Suggest drop for 2.0

2011-01-31 Thread David Mintz
On Mon, Jan 31, 2011 at 4:15 PM, Matthew Weier O'Phinney
wrote:

> -- David Mintz  wrote
> (on Monday, 31 January 2011, 03:37 PM -0500):
> > A naive question: even if ZendX JQuery is dropped as of ZF 2.0, if you
> > wanted to migrate to 2.0 *and* keep ZendX JQuery, is there any reason why
> > you couldn't install it and use like any other 3rd party or home-grown
> > plugin?
>
> The main problem is that the interfaces and base classes will have
> changed to make use of namespaces. As such, at minimum, it would need to
> be migrated to be compatible with the new names.
>
>
Damn. As a high-level userland freeloader I have been loving the convenience
of doing what seems kind of like time travel --
$this->JQuery()->onLoadCaptureStart() -- in my views. I wonder how you might
hack up something equivalent in ZF 2.0.

-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


Re: [fw-general] Re: [zf-contributors] Re: [fw-general] Re: [zf-contributors] Discontinuing Maintenance of ZendX JQuery - Suggest drop for 2.0

2011-01-31 Thread David Mintz
A naive question: even if ZendX JQuery is dropped as of ZF 2.0, if you
wanted to migrate to 2.0 *and* keep ZendX JQuery, is there any reason why
you couldn't install it and use like any other 3rd party or home-grown
plugin?

-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


[fw-general] cleaning cache of ids matching a regex

2010-10-07 Thread David Mintz
Suppose you want to clear your file-system-based cache of all ids matching
/$pattern/.

Is there some clever way I am overlooking, or do you just use
preg_grep($pattern, $cache->getIds()) to get an array of ids to pass to
clean()?

Thanks.

-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/


[fw-general] can _getParam() get $_POST['bar']['foo'] ?

2010-08-30 Thread David Mintz
Just wondering if there's a way for a controller to use $this->_getParam()
directly to get a POST datum which itself is within an array. Like with a
subform for example. So if you have $_POST['person']['email'] can you get at
the email in one _getParam() call? Or do you have to

 $person = $this->_getParam('person') ;

and then work with $person['email'] ?





-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


[fw-general] Re: zend_form for dummies: force-feeding a datum to a form

2010-08-27 Thread David Mintz
On Fri, Aug 27, 2010 at 10:38 AM, David Mintz  wrote:

>
>
> On Fri, Aug 27, 2010 at 10:37 AM, David Mintz wrote:
>
>> Long story, but I would like to add a form element -- it might as well be
>> ' hidden' -- set its value and manually mark it as valid before calling
>> validate so that this element name/value will be in the $context that a
>> validator requires. I would rather not render this element along with the
>> rest of the form because it's basically none of the end user's business.
>>
>>

Nevermind. Zend_Form for Dummies, Chapter 1: when you say

if ($form->isValid($this->getRequest()->getPost()) {

}

you just populated your $form with $_POST, overwriting any manipulation you
may have done to any element value before that point. So manipulate the
request parameter itself, directly, instead, before validating.

May this help somebody some day and help her or him avoid spending a day on
it.

-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


[fw-general] Re: zend_form for dummies: force-feeding a datum to a form

2010-08-27 Thread David Mintz
On Fri, Aug 27, 2010 at 10:37 AM, David Mintz  wrote:

> Long story, but I would like to add a form element -- it might as well be '
> hidden' -- set its value and manually mark it as valid before calling
> validate so that this element name/value will be in the $context that a
> validator requires. I would rather not render this element along with the
> rest of the form because it's basically none of the end user's business.
>
> if ($this->getRequest()->isPost()) {
> $personForm->person_type_id->setValue(1);
>
>
And then I accidentally sent the message prematurely but I guess that's
pretty much the story.

Thanks in advance for any suggestions.


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


[fw-general] zend_form for dummies: force-feeding a datum to a form

2010-08-27 Thread David Mintz
Long story, but I would like to add a form element -- it might as well be '
hidden' -- set its value and manually mark it as valid before calling
validate so that this element name/value will be in the $context that a
validator requires. I would rather not render this element along with the
rest of the form because it's basically none of the end user's business.

if ($this->getRequest()->isPost()) {
$personForm->person_type_id->setValue(1);


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] Question

2010-08-26 Thread David Mintz
On Thu, Aug 26, 2010 at 2:11 PM, Hector Virgen  wrote:

> PHP is a loosely-typed language, meaning that the empty string '' will
> evaluate to false unless you do strict comparisons (=== and !==). For
> example:
>
> $test = FALSE;
>
> if ('' != $test) {
> // this executes because of loose typing
> }
>
> if ('' !== $test) {
>// this doesn't execute because of strict comparison
> }
>
> When testing function return values that may return a number or FALSE, it
> is best to use strict comparisons:
>
> while(false !== ($attribute = $result->fetch_assoc())) {
> ...
> }
>
> --
> **
>


As I understand it, one reason for putting the literal on the left side of a
comparison test is to safeguard against introducing a typo/bug when you
mistakenly type '='  instead of '=='  or '==='

if ($foo = 346)  {


}

which in fact is an idiom some of us are fond of, i.,e assigning values
inside conditionals

if ($foo = $this->_getParam('something_verbose')) {
 // work with $foo

}



-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] best practice: getting a Zend_Mail instance on demand

2010-08-04 Thread David Mintz
On Wed, Aug 4, 2010 at 11:34 AM, David Mintz  wrote:

>
>
> On Wed, Aug 4, 2010 at 10:38 AM, Paul  wrote:
>
>>
>>
>> On 8/4/2010 10:31 AM, David Mintz wrote:
>>
>>
>>
>> On Tue, Aug 3, 2010 at 4:43 PM, Sudheer Satyanarayana <
>> sudhee...@sudheer.net> wrote:
>>
>>>
>>>  but I think there's the disadvantage that your Zend_Mail resource would
>>>> get instantiated at bootstrap time whether you need it or not -- true? --
>>>> and not every controller/action in my app needs to send email.
>>>>
>>>>  Right.
>>>
>>>  Finally, I suppose you could set the email configuration data in its own
>>>> separate config file.
>>>>
>>>> Any thoughts?
>>>>
>>>>  I have my email settings in the database. I have extended Zend_Mail
>>> and added a method setup().
>>>
>>> Class My_Mail extends Zend_Mail
>>> {
>>>
>>>   public function setup()
>>>   {
>>>// get the info to setup the clss
>>>// set it up
>>>   }
>>> }
>>>
>>> Client code:
>>>
>>> $mail = new My_Mail();
>>> $mail->setup();
>>>
>>>
>>
>>  Hmmm -- I am starting to think in this direction. Would you regard this
>> class as a Model and stick it in your models directory?
>>
>>  Parenthetically, any reason you don't do the setup in your constructor?
>> You could have your defaults and have your constructor acception options to
>> override them.
>>
>>  I am also consider a controller action helper. What do you think of that
>> idea?
>>
>>
>>  --
>> Support real health care reform:
>> http://phimg.org/
>>
>> --
>> David Mintz
>> http://davidmintz.org/
>>
>>
>> All my systems have an Email Service class located in
>> application/services.   The benefit here is that I can lazy load all email
>> objects AND have preconfigured email objects like System Email, Debug Email,
>> etc.
>>
>
>
> And now I belatedly RTFM and discover Zend_Application_Resource_Mail and
> wonder why not use it. I have been looking at some of the ZF source to try
> to understand how much happens at bootstrap time and haven't yet figured
> out:  the Zend_Mail object doesn't actually get instantiated until you
> explicitly access the resource, or does it? Sorry for exposing my ignorance
> of ZF internals. Just wondering if it makes sense to use this Resource
> mechanism even when you know you app will not need it most of the time.
>
>

Nevermind, I was confusing the transport object with the mailer object.
Sorry about the noise.


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] best practice: getting a Zend_Mail instance on demand

2010-08-04 Thread David Mintz
On Wed, Aug 4, 2010 at 10:38 AM, Paul  wrote:

>
>
> On 8/4/2010 10:31 AM, David Mintz wrote:
>
>
>
> On Tue, Aug 3, 2010 at 4:43 PM, Sudheer Satyanarayana <
> sudhee...@sudheer.net> wrote:
>
>>
>>  but I think there's the disadvantage that your Zend_Mail resource would
>>> get instantiated at bootstrap time whether you need it or not -- true? --
>>> and not every controller/action in my app needs to send email.
>>>
>>>  Right.
>>
>>  Finally, I suppose you could set the email configuration data in its own
>>> separate config file.
>>>
>>> Any thoughts?
>>>
>>>  I have my email settings in the database. I have extended Zend_Mail and
>> added a method setup().
>>
>> Class My_Mail extends Zend_Mail
>> {
>>
>>   public function setup()
>>   {
>>// get the info to setup the clss
>>// set it up
>>   }
>> }
>>
>> Client code:
>>
>> $mail = new My_Mail();
>> $mail->setup();
>>
>>
>
>  Hmmm -- I am starting to think in this direction. Would you regard this
> class as a Model and stick it in your models directory?
>
>  Parenthetically, any reason you don't do the setup in your constructor?
> You could have your defaults and have your constructor acception options to
> override them.
>
>  I am also consider a controller action helper. What do you think of that
> idea?
>
>
>  --
> Support real health care reform:
> http://phimg.org/
>
> --
> David Mintz
> http://davidmintz.org/
>
>
> All my systems have an Email Service class located in
> application/services.   The benefit here is that I can lazy load all email
> objects AND have preconfigured email objects like System Email, Debug Email,
> etc.
>


And now I belatedly RTFM and discover Zend_Application_Resource_Mail and
wonder why not use it. I have been looking at some of the ZF source to try
to understand how much happens at bootstrap time and haven't yet figured
out:  the Zend_Mail object doesn't actually get instantiated until you
explicitly access the resource, or does it? Sorry for exposing my ignorance
of ZF internals. Just wondering if it makes sense to use this Resource
mechanism even when you know you app will not need it most of the time.


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] best practice: getting a Zend_Mail instance on demand

2010-08-04 Thread David Mintz
On Tue, Aug 3, 2010 at 4:43 PM, Sudheer Satyanarayana  wrote:

>
>  but I think there's the disadvantage that your Zend_Mail resource would
>> get instantiated at bootstrap time whether you need it or not -- true? --
>> and not every controller/action in my app needs to send email.
>>
>>  Right.
>
>  Finally, I suppose you could set the email configuration data in its own
>> separate config file.
>>
>> Any thoughts?
>>
>>  I have my email settings in the database. I have extended Zend_Mail and
> added a method setup().
>
> Class My_Mail extends Zend_Mail
> {
>
>   public function setup()
>   {
>// get the info to setup the clss
>// set it up
>   }
> }
>
> Client code:
>
> $mail = new My_Mail();
> $mail->setup();
>
>

Hmmm -- I am starting to think in this direction. Would you regard this
class as a Model and stick it in your models directory?

Parenthetically, any reason you don't do the setup in your constructor? You
could have your defaults and have your constructor acception options to
override them.

I am also consider a controller action helper. What do you think of that
idea?


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


[fw-general] best practice: getting a Zend_Mail instance on demand

2010-08-03 Thread David Mintz
Ladies and gents,

What is the ZF way to get a Zend_Mail instance all set up and ready to go on
demand? The examples in the docs are hard-coded.  It seems like a good
candidate for a config file, like this, or similar:


http://mysqltalk.wordpress.com/2009/05/16/how-to-pull-your-mail-configuration-from-application-ini-for-zend-framework-1-8-0/

But there's the disadvantage, I think, that in your config you will end up
mixing resource.* style config directives with others, potentially confusing
people later to install and set up your application. Although -- who cares?
Maybe I am being a bit anal-retentive about that.

There is also this, which is elegant


http://www.codewithstyle.eu/2009/11/18/configurare-zend_mail-usando-application-ini/

but I think there's the disadvantage that your Zend_Mail resource would get
instantiated at bootstrap time whether you need it or not -- true? -- and
not every controller/action in my app needs to send email.

Finally, I suppose you could set the email configuration data in its own
separate config file.

Any thoughts?


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] New York PHP

2010-07-29 Thread David Mintz
2010/7/28 José de Menezes Soares Neto 

> Hello friends,
>
> I am going to stay 15 days at New York on October.
>
> I would like to know companies there that are working with PHP.
>
> I would like to visit them and see how stuff works inside USA, and make
> some php friends.
>
> Please send me the website of all companies based there you know!



You might try nyphp.org and have a look at the mailing lists, so you can
establish contact with some NY PHP people.

 --
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] project planning

2010-07-29 Thread David Mintz
On Thu, Jul 29, 2010 at 10:52 AM, Mario Guenterberg <
mario.guenterb...@googlemail.com> wrote:

> On Do, Jul 29, 2010 at 10:28:32 -0400, Matthew Weier O'Phinney wrote:
> > It's actually somewhat hard to answer that question at this time.
> >
> > We're preparing to release our first development milestone of ZF2, which
> > has accomplished the following:
> >
> >  * Stripping of require_once calls
> >  * Conversion to namespaces (except for some Zend_Service components)
> >  * Updates to the test suite (removed all AllTests classes in favor of
> >using native PHPUnit functionality)
> >  * Rewrite of Zend\Session (required so that we could actually test it
> >post-migration; it's been entirely re-architected)
> >
> > Ralph is building a sample app currently so that we have a baseline
> > against which we can do some performance profiling. He's discovered that
> > despite passing tests in individual components, the MVC is not fully
> > functional currently. He is investigating, and hoping to get it working
> > soon.
> >
> > However, this is just the first milestone. Refactoring begins in earnest
> > after this point, so the APIs will be very unstable for a matter of some
> > months at the least. I'm not sure if we'll have a stable release ready
> > in the January/February timeline or not; much of it will be dependent on
> > how much mindshare and time we can get from our own contributor
> > community as we move into a more active ZF2 development phase.
> >
> > Personally, if your project is intended to be production stable for the
> > timeframe you indicate, I'd go with ZF1, and plan a later iteration
> > of the project to migrate to ZF2.
> >
> Okay, it is to be feared that we must go with the zf1 and migrate
> later to the zf2 code base ;-)
>
> Thank you for the answer.
>
> Mario
>


How painful should we expect migration to be? I know:  "it depends."  But
still...


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] GET form submission -> pretty URL

2010-07-15 Thread David Mintz
On Wed, Jul 14, 2010 at 4:06 PM, Hector Virgen  wrote:

> By default, web browsers submit GET forms using the ?foo=bar
> syntax. There's nothing that ZF nor PHP can do to change this, because it
> all happens on the client side. So the only way to get pretty URLs is to use
> Javascript to override the default behavior.
>
> The only way to get this to work using server-side code is to perform a
> redirect, which is an expensive process, so I don't suggest it.
>
> Regarding a JS solution, you'll need to be sure that you implement this in
> a way that is consistent with how forms are normally submitted. For example,
> if your form has two inputs by the same name, only the value of the last
> input is submitted (it overwrites the previous ones). But if you use array
> notation, then you can have multiple values for the same name, and they will
> all be submitted and PHP will read them as an array. AFAIK this can be
> difficult to do with the ZF router because it doesn't turn multiple values
> into arrays.
>
> Also, if your form has multiple submit buttons, each with their own actions
> (like "post" versus "cancel" buttons) then you'll need to submit the value
> for the button that was clicked.
>
> And finally, supporting this may have an impact on your controllers. If you
> are using $this->_request->getQuery() to read the values, note that it only
> reads from $_GET (by default). So if you rewrite your URL using Javascript,
> you'll only be able to use $this->_request->getParam() because $_GET will be
> empty.
>
> With that being said, it's a lot of work for very little benefit. But if
> you have a simple form with only a few elements, then you may not run into
> any problems supporting it.
>


Interesting points. My case is just a fairly simply search form for a roster
of language interpreters. The user selects a language and submits, the
controller action queries a db and uses Zend_Paginate for pagination. The
pagination links give you pretty URLs but the initial form submission is of
course contrastingly "ugly."  Not really a big deal. I think I will let it
go for now and concentrate on more important areas.

@Wil, thanks for the suggestion. I confess I don't quite get it but that's
an opportunity for further RTFM.


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] GET form submission -> pretty URL

2010-07-14 Thread David Mintz
On Wed, Jul 14, 2010 at 3:11 PM, Andrew Ballard  wrote:

> On Wed, Jul 14, 2010 at 2:58 PM, David Mintz  wrote:
> >
> > Having become addicted to pretty URLs, I am finding the ugly kind you get
> > following submission of a GET form rather... ugly. Just wondering if
> anyone
> > has any ideas about this, before I consider writing some Javascript to
> > suppress the default event and location.href = example.org/param1/value1etc
> >
> > --
> > Support real health care reform:
> > http://phimg.org/
> >
> > --
> > David Mintz
> > http://davidmintz.org/
> >
> >
> >
>
> That would be pretty simple to do. If you pursue it, you would need to
> make sure your PHP code still correctly handles the page with the
> regular GET parameters in case someone visiting your site has
> Javascript blocked/disabled. In other words, the page would need to
> respond the same to a request for either of these resources:
>
> example.org/?param1=value1
>
> example.org/param1/value1
>
>

ZF handles that for us transparently, doesn't it? That is, in a controller
$this->_getParam('param1') will return 'value1' either way.


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


[fw-general] GET form submission -> pretty URL

2010-07-14 Thread David Mintz
Having become addicted to pretty URLs, I am finding the ugly kind you get
following submission of a GET form rather... ugly. Just wondering if anyone
has any ideas about this, before I consider writing some Javascript to
suppress the default event and location.href = example.org/param1/value1 etc

-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] ACRONYM casing, or MixedCasing? You decide!

2010-07-14 Thread David Mintz
> >
> > Simply fill out this form:
> >
> >http://short.ie/zf-acrocase
> >
>


Well, I got "MDB2 Error: connect failed" which looks like acronym case. (-:

-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] Repository of common models/entities

2010-07-14 Thread David Mintz
On Wed, Jul 14, 2010 at 9:50 AM, Paul  wrote:

> On 7/14/2010 12:05 AM, Mike A wrote:
>
>> On 13/07/2010 22:44, Jonathon Suggs wrote:
>>
>>> Would the community find benefit in having a repository of commonly
>>> used models/entities?
>>>
>>> The classes would all just be plain php classes with Doctrine2
>>> annotations (and unit tests).  I understand that use cases will vary
>>> between projects but the classes could always be extended and
>>> overridden.
>>>
>>> Subsequently, the classes could be used to create pluggable modules.
>>> I'm thinking that it would be a nice feature for the framework to be
>>> able to add in a blog or forum (or whatever) module that could be part
>>> of your codebase, but without requiring too much developer
>>> customizations (unless wanted).
>>>
>>> I realize this is somewhat of a vague and ambitious request, but if
>>> there is interest I'd like to get some ideas for defining requirements
>>> and use cases.  I guess my only two initial requirements/constraints
>>> are Zend Framework (target ZF2) and Doctrine2.  I also would expect
>>> for the development to happen outside of the official project but
>>> would (obviously) work closely with all projects involved.
>>>
>>>
>> I am writing a ZF book named ModJewelz at the moment. An ongoing work it
>> will eventually become a huge reference. The idea of it is not only to act
>> as a guide to building modular ZF systems but as a reference for modules,
>> plugins and helpers built, tested and available in a central repository
>> after being subjected to scrutiny by the community. To give an idea about
>> the depth of reference, the chapter on building a common foundation template
>> as a basis for modular systems already runs to about 70 pages.
>>
>> So yes, I think the idea is good, but only for tested components capable
>> of interfacing with common templates. Otherwise the repository could become
>> saturated and obfusated by poorly written components - as with other CMS and
>> frameworks.
>>
>>  Sounds like a great book, but I do not see why we have to have to put
> limitations on it.  The community can filter these components on their own.
>  As long as users can rate the components you can let the people choose what
> they want.
>

I think it as Larry Wall who said something about there being a law that
holds that 90% of everything is crap. Talking about CPAN, he goes on to say
that CPAN is so huge -- 18,000 modules at this point -- that the other 10%
of non-crap is quite a significant amount of quality code.

Seems like a middle course would be prudent:  exercise a degree of quality
control, but without becoming too obsessive or exclusive about it.

-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] contextSwitch problem!

2010-05-24 Thread David Mintz
On Mon, May 24, 2010 at 6:51 AM, shahrzad khorrami <
shahrzad.khorr...@gmail.com> wrote:

> hi all,
>
> $funcName is a parameter (comes from extjs)
>
> public function init()
> {
> $this->funcName = $this->getRequest()->getParam('funcName');
> // here must get $funcName and pass it to listAction then json
> create,. HOW ..?
> $this->_helper->contextSwitch()
> ->addActionContext('list', 'json')
> ->setAutoJsonSerialization(true)
> ->initContext();
>
> .
> .
> .
> .
> How can I pass $funcName to listAction?
>
> public function listAction($funcName)
> {
> // need funcName
>echo $funcName ;
>
>
> Regards,
> Shahrzad Khorrami
>



 $this->getRequest()->getActionName() will give you the current action. If
you really need to know the name of the currently executing function,
there's always __FUNCTION__

-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] Zend_Test_PHPUnit_ControllerTestCase: asserting a checkbox is checked

2010-04-29 Thread David Mintz
On Thu, Apr 29, 2010 at 3:24 AM, Núria  wrote:

> Yesterday I reported the issue:
> http://framework.zend.com/issues/browse/ZF-9764 and Matthew resolved it at
> the speed of light (many thanks!), so the fix will be included in the next
> mini release.
>
>
I guess I won't be demanding a refund just yet (-:

-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


[fw-general] Zend_Test_PHPUnit_ControllerTestCase: asserting a checkbox is checked

2010-04-27 Thread David Mintz
I am having some trouble figuring out the magic words. My response body
contains this:



In the controller test, I when I say

 $this->assertQuery('#person_active');

the assertion succeeds, but

 $this->assertQuery('#person_active[checked="checked"]');

fails with 'Failed asserting node DENOTED BY
#person_active[checked="checked"] EXISTS.'

After diddling around with several variations, the only thing that works for
me is to assert that the containing element contains a checkbox whose
"checked" attribute is "checked:"

 $this->assertQuery('#person_active-element input[checked="checked"]') ;

It might be worth noting that the jQuery snippet

 $('#person_active[checked="checked"]').length == 1

typed into the Firebug console evaluates to true. So it looks like my CSS is
kosher.

Any ideas? Thanks.

-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] Testing isValid on zend form with a file element

2010-04-20 Thread David Mintz
On Sun, Apr 18, 2010 at 9:17 AM, dmitrybelyakov wrote:

>
> Hi,
>
> I have a quick question on the best approach to testing Zend_Form classes
> that have Zend_Form_Element_File in them.
>
> I have constructed a small test that shows what i am trying to do. In this
> test the file element is optional so we not goig to provide a value for
> that.
>
> The test is checking if we can process a valid submission:
>
>
>public function testCanProcessValidSubmission()
>{
>$form = new Zend_Form();
>$form->setAttrib('enctype', 'multipart/form-data');
>
>//Add text field
>$username = new Zend_Form_Element_Text('username');
>$username->setRequired(true);
>$form->addElement($username, 'username');
>
>//Add file field
>$file = new Zend_Form_Element_File('image');
>$file->setLabel('Upload an image:');
>$file->setDestination('/tmp');
>$form->addElement($file, 'image');
>
>//Prepare form data
>$formData = array();
>$formData['username'] = 'Test user name';
>
>
>//Validate
>$result = $form->isValid($formData);
>
>//Assert validation passed
>$this->assertTrue($result);
>}
>
>
> The form is working fine from the browser, i just whant to programmatically
> test it for accepting valid data submission but that always fails.
>
> I guess that has something to do with the global $_FILES array - just no
> idea how should we alter that for testing.
>


Have you dumped $form->getMessages() to see what's failing?

-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


[fw-general] conditional elements in Zend_Form

2010-04-13 Thread David Mintz
Here's an interesting problem (hope you'll agreee (-: ). I have a Zend_Form
to which 1 or more elements might be added to the DOM with Javascript.
Imagine something like an employment application where the applicant has the
opportunity to tell us how many languages she/he is proficient in. There's a
"languages" select element. When they choose one, we create a DIV containing
the textual name of the language and a hidden element, e.g.,  <...
name=languages[] value=23 />, holding the id. (I recognize that the downside
to this DOM-manipulation approach is that it won't degrade gracefully in the
absence of js support -- not worried about that.)

Hard to know how to add elements and validators at instantiation time since
I don't know how many elements there will be. Inside the form class' init()
I could get the request object out of the front controller instance, examine
the parameters and see how many elements to add along with their validators.

But I also think -- tell me if I am right -- from the server-side point of
view this is indistinguishable from a multi-select Zend_Form_Element_Select.
I could lie to Zend_Form about what kind of element I am using, and manually
display a regular select in its place in the view script. True?


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] Where to issue final common logic

2010-04-09 Thread David Mintz
On Thu, Apr 8, 2010 at 6:26 PM, jsuggs  wrote:

>
> I'm wanting to do some cleanup commands (ex. issue Doctrine "flush") after
> all activity has completed (ie. no more [state] changes).
>
> Where is the most logical place to issue that command?
>


Maybe a controller plugin's dispatchLoopShutdown() hook?

-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] Zend_Form + JQuery + tabs

2010-03-15 Thread David Mintz
On Fri, Mar 12, 2010 at 4:45 PM, Mike Wright wrote:

> David Mintz wrote:
>
>> On Fri, Mar 12, 2010 at 1:34 PM, scs  wrote:
>>
>>  Hi,
>>> I would validate each step's data and save it in session.
>>> However, if any previous tab is clicked and there was an attempt to
>>> change any validated input,
>>> then I would validate that input again.
>>>
>>> In other words,
>>> click 2nd tab->validate 1st tab data and save in session.
>>> click 3rd tab->validate 2nd tab data and save in session
>>> click submit button -> validate 3rd tab data and insert the
>>> session-saved+3rd tab's validated data in db (or any operation else)
>>> if any previous/validated tab clicked and information is changed on
>>> that tab (before the submit is clicked), re-validate that data again.
>>> I do not think there is a need to re-submit all tabs' data again once
>>> the submit button is clicked.
>>>
>>>
>> So it doesn't make it into the session unless it's valid. This sounds like
>> a
>> good approach.
>>
>> Question: how do we detect whether they have changed data in a
>> previously-validated tab? Compare POSTed data to what's in the session,
>> obviously. But how expensive is that compared to validating again
>> unconditionally? Especially considering that if it's changed we will
>> definitely validate again anyway.
>>
>
> Doesn't all of this become irrelevant if the current subForm is validated
> and stored on any submission?  After that your model/flow can decide which
> subForm should be presented next.  That makes possible previous/next and
> buttons to arbitrarily select the order of the forms (after all, the user
> should be able to determine their own workflow, no?).
>
> .02 US (not worth much before, a lot less now)
>

Maybe I'm not getting your point.

I don't plan to have subforms correspond to tabs one-for-one, because there
are multiple models, each with a corresponding subform. I just want to split
up groups of fields into tabs for the sake of presentation; there's a single
submit button for all. When they move from tab to tab they aren't going to
be submitting, but it seems a fine opportunity to processAjax() and validate
the current section of the form before it gets hidden from view.

-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] Zend_Form + JQuery + tabs

2010-03-12 Thread David Mintz
On Fri, Mar 12, 2010 at 1:34 PM, scs  wrote:

> Hi,
> I would validate each step's data and save it in session.
> However, if any previous tab is clicked and there was an attempt to
> change any validated input,
> then I would validate that input again.
>
> In other words,
> click 2nd tab->validate 1st tab data and save in session.
> click 3rd tab->validate 2nd tab data and save in session
> click submit button -> validate 3rd tab data and insert the
> session-saved+3rd tab's validated data in db (or any operation else)
> if any previous/validated tab clicked and information is changed on
> that tab (before the submit is clicked), re-validate that data again.
> I do not think there is a need to re-submit all tabs' data again once
> the submit button is clicked.
>

So it doesn't make it into the session unless it's valid. This sounds like a
good approach.

Question: how do we detect whether they have changed data in a
previously-validated tab? Compare POSTed data to what's in the session,
obviously. But how expensive is that compared to validating again
unconditionally? Especially considering that if it's changed we will
definitely validate again anyway.


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


[fw-general] Zend_Form + JQuery + tabs

2010-03-12 Thread David Mintz
Embarking on my first ajaxified Zend Form with a JQuery UI-tabbed interface,
I am wondering what sort of practices people recommend.

Say we have tabs 1, 2 and 3, left to right. Tab 1 is displayed first. They
click tab 2. We use a JQuery tabsselect callback to submit only the data
from tab 1 for validation. So... in the controller I presume we should call
$form->processAjax(...) to validate the $_POSTed data, yes?

Back to the client side, the JQuery callback displays errors and returns
false if there are any errors, otherwise true and the next tab is displayed.
Right?

When they finally click the submit button, do we xhr-submit all the data
from all the tabs and fields, and validate it all once again? It seems
redundant if you do, but risky if you don't.

OTOH, with each click on the next tab, you could actually save the
successfully validated data from the current tab (in this case, in a
database) and carry on. That would obviate the need for re-validating. Then
again, as a user I don't expect to save until I actually click a submit
button rather than a tab.

Comments?

-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] array elements in a .ini file

2010-02-25 Thread David Mintz
On Thu, Feb 25, 2010 at 2:55 PM, Mike Wright wrote:

> Hi all,
>
> (3 hrs later) I know I've seen this explained before but searching for
> non-alphanumeric characters just doesn't google and I can't find it again
> anywhere.
>
> How do I specify within a config.ini file an element whose name may be an
> array?
>
> e.g.
> 
>
> elements.test[].type = "text"  ;doesn't work.  (and you'd probably get a
> good laugh out of some of the things I've tried ;)
>

Just a wild guess, because this is not my strong suit, but --- the solution
may be to forget about array notation and have a look at belongsTo.


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


[fw-general] Re: Zend_Filter_Digits: filter() not invoked on subform element

2010-02-17 Thread David Mintz
Nevermind. It appears -- emphasis on "appears" -- that attaching the filter
to the element before attaching the element to the form does not work. What
does appear to work is adding the element to the form, then adding the
validator to the form element.

Please do tell me if I'm wrong.



On Wed, Feb 17, 2010 at 3:39 PM, David Mintz  wrote:

> I have a class that extends Zend_Form_Subform. In init() I do this:
>
> $phone = new Zend_Form_Element_Text(
> array('name' => 'office_phone','id'
> =>'person_office_phone','label' => 'Office phone',
> 'belongsTo' => 'person' ,'class' => 'telephone'
> )
> );
> $phone->addValidator('StringLength',true,array('min'=>10,'max'=>10,
> 'messages' => array(
>  Zend_Validate_StringLength::TOO_SHORT => $m = "phone
> number must be 10 digits",
> Zend_Validate_StringLength::TOO_LONG => $m
> )));
> $phone->addFilter(new Zend_Filter_Digits());
> $this->addElement($phone);
>
> I have a Zend_Form subclass that contains two subforms, the above being one
> of them.
>
> In this case I am trying to strip non-digits form a 10-digit phone number.
> When I POST the form with
> "212 805-0362" in this field, validation is failing.
>
> Crude but effective, I put echo statements in Zend_Filter_Digits
> constructor and filter() method, and determined that the Zend_Filter_Digits
> instance is created, but the filter() method is never executed.
>
> Pray tell, what I am doing wrong? Or have I discovered a bug?
>
> This is ZF 1.10.0. Any guidance is deeply appreciated.
>
>
> --
> Support real health care reform:
> http://phimg.org/
>
> --
> David Mintz
> http://davidmintz.org/
>
>
>


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


[fw-general] Zend_Filter_Digits: filter() not invoked on subform element

2010-02-17 Thread David Mintz
I have a class that extends Zend_Form_Subform. In init() I do this:

$phone = new Zend_Form_Element_Text(
array('name' => 'office_phone','id'
=>'person_office_phone','label' => 'Office phone',
'belongsTo' => 'person' ,'class' => 'telephone'
)
);
$phone->addValidator('StringLength',true,array('min'=>10,'max'=>10,
'messages' => array(
 Zend_Validate_StringLength::TOO_SHORT => $m = "phone number
must be 10 digits",
Zend_Validate_StringLength::TOO_LONG => $m
)));
$phone->addFilter(new Zend_Filter_Digits());
$this->addElement($phone);

I have a Zend_Form subclass that contains two subforms, the above being one
of them.

In this case I am trying to strip non-digits form a 10-digit phone number.
When I POST the form with
"212 805-0362" in this field, validation is failing.

Crude but effective, I put echo statements in Zend_Filter_Digits constructor
and filter() method, and determined that the Zend_Filter_Digits instance is
created, but the filter() method is never executed.

Pray tell, what I am doing wrong? Or have I discovered a bug?

This is ZF 1.10.0. Any guidance is deeply appreciated.


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] validator Db_NoRecordExists -- support for multifield unique indices?

2010-02-16 Thread David Mintz
On Thu, Feb 11, 2010 at 5:03 PM, Саша Стаменковић wrote:

> Can we see the source?
>
> Regards,
> Saša Stamenković
>
>
>
Sure...

The next thing however that I plan to do is likewise add support for
multiple columns in the 'exclude' option.

toArray();
}
if (array_key_exists('fields',$options)) {
$this->_fields =  $options['fields'];
// to prevent parent from throwing missing option exception:
$options['field'] = $this->_fields;
}
parent::__construct($options);
}


function isValid($value,$context=null) {


$this->_setValue($value);
/** FROM Zend_Validate_Db_Abstract: ///
 * Check for an adapter being defined. if not, fetch the default
adapter.
 */

if ($this->_adapter === null) {
$this->_adapter = Zend_Db_Table_Abstract::getDefaultAdapter();
if (null === $this->_adapter) {
throw new Zend_Validate_Exception('No database adapter
present');
}
}
if (! $this->_fields) { // plural !
$result = $this->_query($value);
if ($result) {
$this->_error(self::ERROR_RECORD_FOUND);
return false;
} else {
return true;
}
}
/**
 * Build select object
 */

$select = new Zend_Db_Select($this->_adapter);


$select->from($this->_table, $this->_fields, $this->_schema);
// sole difference from parent implementation: add multiple WHERE
clauses
// note: we are assuming form field name == column name
foreach ($this->_fields as $field) {
$select->where("$field = ?",$context[$field]);
}

if ($this->_exclude !== null) {
if (is_array($this->_exclude)) {

$select->where($this->_adapter->quoteIdentifier($this->_exclude['field']).'
!= ?', $this->_exclude['value']);
} else {
$select->where($this->_exclude);
}
}
$select->limit(1);

$result = $this->_adapter->fetchRow($select, array(),
Zend_Db::FETCH_ASSOC);
if ($result) {
    $this->_error(self::ERROR_RECORD_FOUND);
   return false;
} else {
return true;
}
}
}




-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


[fw-general] validator Db_NoRecordExists -- support for multifield unique indices?

2010-02-11 Thread David Mintz
I've just written my own extension of Zend_Validate_Db_Abstract that
supports multiple fields to query against, for the case where your table has
a multi-field unique index. I wonder if there's any demand for this feature,
it might be a cool thing for this relative novice ZFer to contribute,
perhaps as a feature enhancement to Zend_Validate_Db_NoRecordExists.

Comments?


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] subforms: flattening $form->getMessages in a DRY way

2010-02-09 Thread David Mintz
On Mon, Feb 8, 2010 at 5:12 PM, Peter Warnock  wrote:

> You might look at using a custom error decorator to adapt getMessages to
> your need. - pw
>
>

Thanks for the suggestion. In this case, I'm not sure that would apply. I've
written a jQuery plugin that submits the form via xhr and handles the JSON
response. If the response contains a validationErrors object, I step through
it and display the messages adjacent to the appropriate elements, relying on
a simple naming convention to figure out what goes where. So, in a sense,
that's my error decoration. Basically I only need zend_form to be rendered
once -- when they GET it for the first time and there are no user input
validation errors to think about.

Seems to be working fine, but if there's a better way, or if this wheel has
already been invented, I am listening.


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] subforms: flattening $form->getMessages in a DRY way

2010-02-08 Thread David Mintz
On Mon, Feb 8, 2010 at 2:12 PM, Aleksey Zapparov wrote:



2010/2/8 David Mintz :
[snip]
> But!  [I will need to flatten the return of getMessages()] in various
> places around the application, so I
> am considering the best approach. A controller action helper that mangles
> $form->getMessages() for me? Or have all my complex forms extend a base
> class that overrides getMessages()? Or... ?
>

> Hello,
>
> I suggest you to extand Zend_Form with your own, let's call it App_Form.
> But I do not recommend to override Zend_Form's getMessges() method, instead
> I suggest to create new one, let's call it getMessagesFlatten() where
> you'll
> implement necessary logic.
>
> Or, if you don't need all features of Zend_Form extending, I think it's
> better to re-write your jQuery plugin/script.
>
>
Just for curiosity's sake, why not overrride getMessages()? My "simple"
forms will subclass Zend_Form directly, and my "compound"
(subform-containing) forms will extend my Form_CompoundForm which has its
own getMessages() implementation, so that I can rely on getMessages() to
give me what I want.

-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


[fw-general] subforms: flattening $form->getMessages in a DRY way

2010-02-08 Thread David Mintz
I am using a Zend_Form containing Zend_Form_Subform instances, and
submitting via jQuery/Ajax, using the AjaxContext helper on the controller
side. When validation fails, I am sending a JSON data structure with the
validation errors and using a crude jQuery plugin of my own devise that
displays the errors where they belong. Works fine for simple (subformless)
forms, but I discovered that where there are subforms, $form->getMessages()
(naturally enough) groups the error messages under the subform name, while
my jQuery plugin is expecting a flat array of validation error messages. I
could make my plugin smarter, I guess, but it seems simpler to do the work
server side. So, I am ensuring unique array keys by prepending the form name
to each field name:

$messages = $form->getMessages();
$validationErrors = array();
foreach (array_keys($messages) as $name) {
foreach($messages[$name] as $k => $v) {
$validationErrors["{$name}_{$k}"] = $v;
}
}
$this->view->assign(array('validationErrors' =>
$validationErrors));

Seems to work fine. Any comments so far?

But! This is going to happen in various places around the application, so I
am considering the best approach. A controller action helper that mangles
$form->getMessages() for me? Or have all my complex forms extend a base
class that overrides getMessages()? Or... ?

Thanks.

-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] controller actions and zend_form both need db table access

2010-01-29 Thread David Mintz
On Fri, Jan 29, 2010 at 10:52 AM, Konr Ness  wrote:

> Why does your init need access to the model? Maybe to populate a select
> element's options?
>

Exactly.


>
> In that case, yeah, you'll probably have to set the model via the
> constructor.
>
>

Sometimes I write static methods in my Zend_Db_Table subclasses that return
arrays for populating select elements. That would seem to resolve the
problem of multiple instantiations of the same class.

Of course, static methods have no $this so you can't use the parent class'
instance methods. What I've been doing is grabbing a reference to my $db
resource out of the bootstrap (via the front controller) and running
fetchPairs() on it. Maybe it's a bit baroque but it seems to work.



-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] controller actions and zend_form both need db table access

2010-01-29 Thread David Mintz
On Thu, Jan 28, 2010 at 10:49 PM, Konr Ness  wrote:

> David,
>
> That's exactly how I do it. If my form needs an instance of the model I *
> always* have a setter for the model (instead of requiring the form to
> create it's own instance).
>
> I do this a lot for forms like user registration which needs to have a
> unique email address validator (which obviously needs access to the model to
> check the DB). [...]
>


Thanks. Just curious: do you call your setter every time, or have you
devised away to hand your model instance to your form's constructor? Because
I would like that database connection to be available to init(), which is
called by the constructor.

If you say new My_Form(array('model' => $model')) I imagine that would work
but it would constrain your constructor to using arrays and not Zend_Config.
Then again, do we care?

I guess another alternative is to add an optional second argument $model to
your subclass' constructor.



-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] controller actions and zend_form both need db table access

2010-01-29 Thread David Mintz
On Fri, Jan 22, 2010 at 7:51 PM, Meroe Meroe  wrote:

> What about using some sort of service method? That way you separate some of
> the logic in the service and tie that to the model only if needed?  Just a
> thought.
>
>

Honestly? Because I don't really understand very much about what we mean by
"service" and "service layer."  If we mean, esssentially, abstracting away
the dirty details of data persistence, I don't think that's really necessary
for the app I'm working on. I am prepared to be married forever to a RDBMS
backend -- indeed, to MySQL. (MySQL:  with this ring I do thee wed.)



>
>
On Fri, Jan 22, 2010 at 4:00 PM, David Mintz  wrote:
>
>> I have a situation in which certain controller actions need to use an
>> instance of my Model_DbTable_Foo (which extends Zend_Db_Table_Abstract), but
>> those actions also instantiate my Zend_Form subclasses, which also need
>> access to Model_DbTable_Foo for getting data to populate select menu
>> options.[]
>>
>>
>


-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


[fw-general] controller actions and zend_form both need db table access

2010-01-22 Thread David Mintz
I have a situation in which certain controller actions need to use an
instance of my Model_DbTable_Foo (which extends Zend_Db_Table_Abstract), but
those actions also instantiate my Zend_Form subclasses, which also need
access to Model_DbTable_Foo for getting data to populate select menu
options. It's a waste if each instantiates its own instance. On the other
hand I haven't determined what would be the most sensible way for them to
share. I suppose the controller could somehow pass the $table instance to
the form's constructor.

Suggestions?

-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


[fw-general] testing form input 'value' attrib with Zend_Test_PHPUnit_ControllerTestCase

2009-12-30 Thread David Mintz
I want to test a controller action that when accessed via GET is supposed to
prepopulate and display a form.  I've discovered that

 $this->assertQueryContentContains('input#comments', 'bla bla bla');

fails even when calling the action in a browser -- or printing the response
body to the console in the test -- clearly shows 'bla bla bla' in the
'comments' field.

It finally ocurred to me that 'bla bla bla' really isn't the content, it's
the value of the   element's 'value' attribute. Therefore the failure is the
correct result, technically (stupid computers!). So, I tried

$this->assertQuery('input[value="bla bla bla"]')

but that doesn't do it either.  What's the right way to do it?

Thanks.

-- 
Demand health care for everyone:
http://mobilizeforhealthcare.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] Zend_Validate_NotEqual ?

2009-12-09 Thread David Mintz
On Tue, Dec 8, 2009 at 4:39 PM, Daniel Latter  wrote:

> Why can't you use a select box in a master detail rel?
>

Sorry -- what's a master detail rel?

-- 
Demand health care for everyone:
http://mobilizeforhealthcare.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] Zend_Validate_NotEqual ?

2009-12-08 Thread David Mintz
On Fri, Dec 4, 2009 at 5:25 PM, Thomas Weidner wrote:

> There is a Zend_Validate_Db_NoRecordExists which can check DB input.
>
> Or you could simply use
>
> if (!$validator->isValid($value)) {
>   // whatever should be done
> }
>

I don't quite follow, perhaps because you haven't quite understood my point.
I have a case where I need to ensure that a submitted value is something
other than x. Imagine a rule that if they order a product x with its main
color 'red' , then the color of the trim has to be other than 'red.' You
conditionally put a validator on the 'trim color' field that enforces the
rule 'if that other thing is red, this thing cannot be red.'

Hence, this class which I proudly present to the community:


class Zend_Validate_NotEqual extends Zend_Validate_Abstract {

public $different;

const NOT_EQUAL = 'notEqual';

protected $_messageTemplates = array(
self::NOT_EQUAL => "submitted value '%value%' cannot be equal to
%different%."
);

function __construct($different) {
$this->different = $different;
$this->_messageVariables = array('different'=>'different');
}


function isValid($value) {

$this->_setValue($value);
if ($value == $this->different) {
$this->_error();
    return false;
}
return true;
}
}





-- 
Demand health care for everyone:
http://mobilizeforhealthcare.org/

--
David Mintz
http://davidmintz.org/


[fw-general] Zend_Validate_NotEqual ?

2009-12-04 Thread David Mintz
 I am encountering a scenario where I need to enforce a rule that a
submitted value is NOT equal to something else. Before I write it, I wonder
if anyone else has done this already.

Specifically, it's kind of an unusual situation where the user can insert
what I call a "location" into a db table, and this model supports one level
of nesting -- that is, a location can either be in another location, or it
can be a top-level location, that's it. These locations have an attribute
"type," and the rule I want to enforce is:  a location of a given type
cannot have as parent a location of the same type. Example:  a hotel room is
in a hotel. A hotel cannot be in another hotel.

The form has a select menus for choosing a parent location, and for choosing
the type of the location. I am thinking of writing a custom validator for
the "select type" element, and throwing the parent location's type_id at its
constructor. Then isValid($value) will simply compare $value to
$this->parent_type_id.

Do you think this makes sense?

class My_Validate_NotEqual
{
function __construct($valueThatShouldBeDifferent) {
$this->valueThatShouldBeDifferent = $valueThatShouldBeDifferent;
   }

   function isValid($value) {
// stuff omitted for brevity, but basically...
return $value != $this->valueThatShouldBeDifferent;
  }

}


Thanks.

-- 
Demand health care for everyone:
http://mobilizeforhealthcare.org/

--
David Mintz
http://davidmintz.org/


[fw-general] when/where to add a view script path to the stack

2009-11-10 Thread David Mintz
Still confused about this.

Suppose you would like a common view script directory to be available to the
whole application, such as

APPLICATION_PATH . /views/common

In my Bootstrap class'  _initView(), I tried inserting a
$view->addScriptPath(APPLICATION_PATH.'/views/common');

Evidently, that does not work. When I try to run a controller action in the
browser I get an exception about the error handler not being able to locate
the error script. From within a controller, dumping the output of
$this->view->getScriptPaths() I find that the path you tried to add is not
added to anything, it's the only thing. I infer that by calling
addScriptPath() on my $view object so early in cycle, you defeat the routing
and ZF can't resolve your URL to a controller/action.

The same $this->view->addScriptPath(APPLICATION_PATH.'/views/common') inside
a controller init() or action method does the job. But I don't want to have
to do that in every controller.  So what's the best-practice, DRY way to
accomplish this? Front controller plugin/preDispatch()?

Next question:  after much trial and error, the only way I could make an
action method just render a non-default view, not puke, not render the
default view as well, and not make me do a
$this->_helper->viewRender->setNoRender(), was the following:

$this->_helper->viewRenderer->renderScript('test.phtml');

Is that the only way? Seems kind of verbose.

Thanks,

    David


-- 
Demand health care for everyone:
http://mobilizeforhealthcare.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] Re: Accessing the controller's name from layout

2009-11-04 Thread David Mintz
On Wed, Nov 4, 2009 at 7:31 AM, Alayn Gortazar  wrote:

> Hi Diego,
>
> You can get the Controllers instance with
> Zend_Controller_Front::getInstance(), so:
>
> $controllerName =
> Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
>
>

But whatever the reason for doing this, it kind of smells like a lot of PHP
code for the layout layer. You might want to consider moving this logic back
somewhere earlier in the request cycle.


-- 
Demand health care for everyone:
http://mobilizeforhealthcare.org/

--
David Mintz
http://davidmintz.org/


[fw-general] triple rendering of layout when exception thrown in preDispatch()

2009-10-27 Thread David Mintz
I am finding that when an Exception is raised at the top of my
preDispatch(), I get a generic PHP uncaught exception error.

When I throw one a little further along the way, I get my error
controller/error action as expected, but the layout is rendered three times.

When I throw an Exception in the course of a controller action, the error
handler does its thing as it should and the layout is rendered but once.

So -- I am doing something weird, or is this expected, and if so, what's the
solution -- any ideas?

Here's a sample from my authentication/Acl plugin:


function preDispatch(Zend_Controller_Request_Abstract $request ) {
// throw new Exception('oops!'); // generic PHP uncaught exception
error is displayed
$module = $request->getModuleName();

if ( 'default' != $module)
{
if (! $this->auth->hasIdentity()) {
$session = new Zend_Session_Namespace();
$session->redirectTo = $_SERVER['REQUEST_URI'];

$request->setModuleName('default')
->setControllerName('users')
->setActionName('login');
return;
}
// throw new Exception('oops!');   // layout renders 3 times
$this->checkAcl($request);
}
}

Gratefully,

   David

-- 
Demand health care for everyone:
http://mobilizeforhealthcare.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] false negative in unit testing whether plugin is loaded (?)

2009-10-26 Thread David Mintz
On Mon, Oct 26, 2009 at 5:06 PM, prodigitalson wrote:

>
> Well first off you shouldnt really throw exceptions in your test... thats
> what the assertions are for really for example:
>
> function testAclPluginLoadsIfUserIsAuthenticated() {
>
>$this->loginDavid(); // tested independently and known to work
>$this->resetRequest()->resetResponse();
>$this->dispatch('/admin/index');
>$auth = Zend_Auth::getInstance();
> $this->assertTrue($auth->hasIdentity());
>$this->assertEquals('david', $auth->getStorage()->read()->username);
>
>  $this->assertType('Plugin_Acl',$front->getPlugin('Plugin_Acl'),"Plugin_Acl
> not loaded when it should be");
> }
>
> If you do it this way youll get more meaningful output from PHP unit. Which
> brings us to the key question... Where exactly in the test you provided (or
> my modified version) is it failing?
>
>
Um, it's sort of moot now, because the frustration with the tests got me
thinking about my code organization, and I decided to collapse my
authentication and ACL into a single plugin. But the preDispatch() does not
instantiate my Model_Acl unless there is an authenticated user. It has the
efficiency of what I was attempting before, and then some, while not
presenting any testing problems (yet).

But I take your point about the exception. Although the method is tested
elsewhere and so  I figured if it fails here, abort the test run and fix the
problem.But -- still learning.

Many thanks.

-- 
Demand health care for everyone:
http://mobilizeforhealthcare.org/

--
David Mintz
http://davidmintz.org/


[fw-general] false negative in unit testing whether plugin is loaded (?)

2009-10-26 Thread David Mintz
I got the idea that I should create an ACL front controller plugin that
loads only if there is an authenticated user. My reasoning is, if they ain't
logged in, why load my ACL class? Send them to the login page, end of story.

Hence, in my Bootstrap,

function _initFrontControllerPlugins() {
$log = $this->getResource('log');
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new Plugin_Authentication());
if (Zend_Auth::getInstance()->hasIdentity()) {
$front->registerPlugin(new Plugin_Acl());
$log->info("yes auth identity, Acl plugin loaded at Bootstrap
".__LINE__ ."\n");
} else {
$log->info("no auth identity, ergo acl not loaded at Bootstrap
".__LINE__ ."\n");
}
}

In a browser, I can log in, then load another page and see my Firebug logger
telling me the ACL plugin class has loaded as it should.

But in my unit test, this assertion fails:

function testAclPluginLoadsIfUserIsAuthenticated() {

$this->loginDavid(); // tested independently and known to work
$this->resetRequest()->resetResponse();
$this->dispatch('/admin/index');
$auth = Zend_Auth::getInstance();
if (! $auth->hasIdentity()) {
throw new Exception("test login for admin failed");
} else {
echo " OK there is an identity (Acl Test: ".__LINE__.  ")\n";
}
if ($auth->getStorage()->read()->username != 'david') {
throw new Exception("unexpected username is logged in, can't run
test");
return;
} else {
echo " OK David is authenticated\n" ;
}
$front = $this->bootstrap->getResource('FrontController');

$this->assertType('Plugin_Acl',$front->getPlugin('Plugin_Acl'),"Plugin_Acl
not loaded when it should be");
}
}

Any ideas what I am doing wrong? (I am, I confess, still fairly new to
automated testing but I am an enthusiastic believer.)

btw, I tried simply loading both plugins unconditionally, and when I rewrite
the tests to check that both are loaded, it works. But it seems like the
tail is wagging the dog when you refactor (de-optimize?) your app just to
force tests to pass.

Gratefully,

   David


-- 
Demand health care for everyone:
http://mobilizeforhealthcare.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] Mysql adapter

2009-10-21 Thread David Mintz
On Wed, Oct 21, 2009 at 9:41 AM, Daniel Latter  wrote:

> *Any chance of either changing your server environment or moving someplace
> more congenial?*
> I asked but no joy, rubbish I know - cant move either.
>
>
Sound like you need to dl() your extension then, or else write your own
adapter.

-- 
Demand health care for all.
Commit to doing civil disobedience, legal protest,
or make a donation:  http://mobilizeforhealthcare.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] Mysql adapter

2009-10-21 Thread David Mintz
On Wed, Oct 21, 2009 at 9:12 AM, Daniel Latter  wrote:

> Hi, I just have a quick question, Why doesn't ZF have a standard mysql
> adapter? apart from PDO, mysqli?
>
> Would it be easy to modify an existing adapter to get this functionality?
> I'm on a server that's not got mysqli, or PDO mysql driver.
>
> Thanks.
>

I'm no expert, but I would speculate that the reason is that the old
mysql_ API is on its way to deprecation.

Any chance of either changing your server environment or moving someplace
more congenial?

Or maybe you can load what you need dynamically with dl()?


-- 
Demand health care for all.
Commit to doing civil disobedience, legal protest,
or make a donation:  http://mobilizeforhealthcare.org/

--
David Mintz
http://davidmintz.org/


Re: [fw-general] QuickStart -- An action and provider is required

2009-10-14 Thread David Mintz
On Wed, Oct 14, 2009 at 9:45 AM, Jerry McG  wrote:

>
> Thanks David.  I did two things before it executed without any errors. Not
> sure which one did the trick:
>
> 1) I copied the library folder to the folder where I wanted the zf.bat to
> create my new project
> 2) I went to php.ini and changed the include_path settings to point to this
> newly copied library folder
>
>

I'm not an expert, but my money is on #2.



-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] QuickStart -- An action and provider is required

2009-10-14 Thread David Mintz
On Tue, Oct 13, 2009 at 10:01 AM, Jerry McG  wrote:

> Hi All, I am trying to create a new project using Zend Framework Quick
> Start. I am on a Windows machine with XAMPP PHP instalation. I am using the
> zf.bat. When I try to execute zf.bat from command line, I am getting this
> error: *An error has occurred. An action and provider is required.* Please
> help. Thanks!
>

Sounds like it's working just fine.

Seriously, though:  when it's working and you run it without any arguments,
that's what you get. Try something like 'zf show version'

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] HeadMeta

2009-10-13 Thread David Mintz
On Mon, Oct 12, 2009 at 11:55 PM, Hector Virgen  wrote:

> Another way around this would be to set your default description early
> (like in a bootstrap init method) and let your view scripts override it
> when necessary.
>
>
Let your view scripts override it when necessary -- that's exactly what I am
not figuring out how to do.

My scenario is slightly different, but typical. I want my layout to detect
if there's a logged in user; if so, display "Welcome User Foo" , otherwise
display a link to the login page. No problem.

If, however, the current page itself is the login page, I want to suppress
the welcome/log in message entirely. Thus, in my layout,

$this->placeholder('loginBox')->captureStart();?>

user) :?>Welcome user->firstname?>

[log in]


placeholder('loginBox')->captureEnd();

and later in the layout script,

placeholder('loginBox')?>

Once I get into login.phtml, I can't seem to reset the content of the
placeholder to empty string, or unset it, or otherwise prevent it from being
displayed, having tried exchangeArray() and various other tricks. It seems
it's already been output to the browser and that's that. What am I missing?

Thanks a million,

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] Is the book Is "Zend Framework: The Official Programmer’s Reference Guide" based on ZF v1.9?

2009-10-09 Thread David Mintz
On Fri, Oct 9, 2009 at 7:40 PM, Mark Wright  wrote:

> It will also be outdated pretty quick.
>
>
Pardon my OT, but you know what title I would like to see, either as
hard-copy and/or a collaborative web-based project:  The Zend Framework
Cookbook. We already have a good reference manual and a plethora of articles
and tutorials, but we don't have a collection of "recipes," relatively short
lessons that concentrate on a particular problem and its solution(s). There
have been a couple of really good books in this format, like the PHP
Cookbook and the MySQL Cookbook. A ZF Cookbook would be a great addition to
any serious cook's bookshelf.

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] Is the book Is "Zend Framework: The Official Programmer’s Reference Guide" based on ZF v1.9?

2009-10-09 Thread David Mintz
On Fri, Oct 9, 2009 at 12:01 PM, Matthew Weier O'Phinney
wrote:

> -- swilhelm  wrote
> (on Thursday, 08 October 2009, 04:34 PM -0700):
> > Is the
> >
> http://www.amazon.com/exec/obidos/tg/detail/-/1430219068/ref=ord_cart_shr?_encoding=UTF8&m=ATVPDKIKX0DER&v=glance
> > book , Zend Framework: The Official Programmer's Reference Guide" base on
> ZF
> > 1.9?
>
> Yes -- it uses the docbook sources from 1.9.3.
>

Yours for just US$43.45 (plus shipping). What a deal.

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] getActionName() in bootstrap

2009-10-09 Thread David Mintz
On Fri, Oct 9, 2009 at 8:46 AM, Vadim Gabriel  wrote:

> i don't think they exits there yet. Those values are being set after the
> bootstrap and the dispatch process.
>


Therefore, this is the way to go, at least for the time being:
http://framework.zend.com/manual/en/zend.controller.plugins.html

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] Is the book Is "Zend Framework: The Official Programmer’s Reference Guide" based on ZF v1.9?

2009-10-09 Thread David Mintz
On Fri, Oct 9, 2009 at 10:47 AM, David Mintz  wrote:

>
>
> On Fri, Oct 9, 2009 at 10:14 AM, Ralph Schindler  > wrote:
>
>> And... I was wrong, it IS actually based on *1.9.3*.
>>
>
>
> OMG!!! An up-to-date ZF book? How is this possible? Quick, buy it and read
> it at once before it's too late (-: !
>



D'oh! Sorry I got over-excited. It isn't out yet.

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] Is the book Is "Zend Framework: The Official Programmer’s Reference Guide" based on ZF v1.9?

2009-10-09 Thread David Mintz
On Fri, Oct 9, 2009 at 10:14 AM, Ralph Schindler
wrote:

> And... I was wrong, it IS actually based on *1.9.3*.
>


OMG!!! An up-to-date ZF book? How is this possible? Quick, buy it and read
it at once before it's too late (-: !

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] post-login, redirecting back to where they came from

2009-10-08 Thread David Mintz
On Thu, Oct 8, 2009 at 4:28 PM, Hector Virgen  wrote:

> I found it better to use a $_GET parameter for this. This allows you to
> create hyperlinks out of the URL that redirects the user to a specific page
> after logging in.
>
>
>
Not sure I follow. You would put this GET parameter... where? Append it to
the login form's action attribute (url-encoding any slashes in the URI you
want to redirect to)? How's that different from putting in a hidden field,
ultimately?


-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] Auto escape all variables in View

2009-10-08 Thread David Mintz
On Thu, Oct 8, 2009 at 12:02 PM, admirau  wrote:

>
> Has anyone here already created custom View,
> which escapes all variables by default?
>
> Willing to share?
>
>
Or imagine a Zend_View whose constructor took an option autoEscape => true,
true by default. Hmmm



-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


[fw-general] post-login, redirecting back to where they came from

2009-10-08 Thread David Mintz
Let's say you have a front controller plugin with a preDispatch method that
looks at the module/action/controller, checks if
Zend_Auth::getInstance()->hasIdentity(), and resets the
module/action/controller to default/users/login if appropriate.

How do you save the initial request URI and redirect following a successful
login? I can think of two techniques: (1) save it in the session or (2)
stuff it in the login form as a hidden field and let it go along for the
ride.

Any suggestions as to which is preferable, or other alternatives?

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] Zend_Acl roles and permission on action

2009-10-08 Thread David Mintz
On Wed, Oct 7, 2009 at 6:58 PM, tomascejka  wrote:

>
> I read about Acl and I think about roles and permisson and I want to ask if
> there is necessary make implementation on database layer. I mean persisting
> permissions with relations to roles strutured in tree structure.
>
> As I have read about Acl there is a possibility that it is not necessary to
> make another layer above Acl princip implemented in Zend_Acl.
>
> Can m


As I understand it, it is perfectly OK to write all your ACL rules in PHP
and load them at runtime, with no persistence involved. If, however, you
want to create an interface through which an administrator can manipulate
ACL rules interactively, you obviously will need persistence.

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] Application Resources Access

2009-10-08 Thread David Mintz
On Wed, Oct 7, 2009 at 2:01 AM, Саша Стаменковић  wrote:

> Yes, you're right, but the only bad thing is writing:
>
> Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('cache');
> v.s.
> Zend_Registry::get('cache');
>
> and maybe using Zend_Registry is faster?
>
> Regards,
> Saša Stamenković
>
>
>
> On Tue, Oct 6, 2009 at 5:21 PM, Hector Virgen  wrote:
>
>> It probably wouldn't hurt to check in both places. I think you're right
>> and checking for a bootstrap resource might be better (or clearer to another
>> developer) than checking Zend_Registry.
>> The question that comes to mind when running into this code later is
>> "Where does the cache get initialized?". Zend_Registry gives us no clues as
>> to where or when that cache was registered, but the bootstrap resource clues
>> us in to the bootstrap.
>>
>> --
>> Hector
>>
>>
>>
>> On Mon, Oct 5, 2009 at 10:59 PM, Саша Стаменковић wrote:
>>
>>> Thx Hector.
>>> Nice answer and useful code example.
>>> Is there a reason to use registry over bootstrap init and get resource?
>>>
>>> Is it better to do
>>>
>>>   if (Zend_Registry::has('cache')) {
>>> $this->setCache(Zend_Registry::get('cache'));
>>>  }
>>>
>>> or
>>>
>>>  if ($cache = $this->setCache(Zend_Registry::get('cache'))) {
>>> //
>>>  }
>>>
>>> Regards,
>>> Saša Stamenković
>>>
>>>
>>>
>>> On Mon, Oct 5, 2009 at 8:06 PM, Hector Virgen wrote:
>>>
>>>> If it's system-wide, I usually place it in the registry for easy access.
>>>> But then I also use a lazy-loading technique in the model layer that pulls
>>>> the cache from the registry if it wasn't set:
>>>> public function setCache(Zend_Cache_Core $cache)
>>>> {
>>>> $this->_cache = $cache;
>>>> return $this;
>>>> }
>>>>
>>>> public function getCache()
>>>> {
>>>> if (null === $this->_cache) {
>>>> if (Zend_Registry::has('cache')) {
>>>> $this->setCache(Zend_Registry::get('cache'));
>>>> }
>>>> }
>>>> return $this->_cache;
>>>> }
>>>>
>>>> --
>>>> Hector
>>>>
>>>>
>>>>
>>>> On Mon, Oct 5, 2009 at 1:03 AM, umpirsky  wrote:
>>>>
>>>>>
>>>>> Hi.
>>>>>
>>>>> I need several Zend_Cache objects for my app (file, memcached...), and
>>>>> I
>>>>> don't want to instantiate and initialize it all over my app. So, there
>>>>> are 2
>>>>> options:
>>>>>
>>>>> - Init Zend_Cache in bootstrap and then get it all over app (in models
>>>>> for
>>>>> ex) with:
>>>>> $this->getFrontController()->getParam('bootstrap')->getResource('cache');
>>>>> -
>>>>> if I can do this in models at all? How do I access bootstrap resources
>>>>> from
>>>>> outside controllers?
>>>>> - Init Zend_Cache in bootstrap but store it in Zend_Registry then get
>>>>> it
>>>>> with Zend_Registry::get('cache');
>>>>>
>>>>> What is better/faster approach and why?
>>>>> --
>>>>> View this message in context:
>>>>> http://www.nabble.com/Application-Resources-Access-tp25746631p25746631.html
>>>>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>>>>
>>>>>

Once upon a time I asked M. O'Phinney this very question and his answer was
testability. It's easier to test things with the bootstrap approach, I
believe he said. The thread is somewhere in the archives, presumably.



-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] newbie Auth problem

2009-10-08 Thread David Mintz
2009/10/8 robos85 

>
> Hi, I'm starting to learn the Zend FM. I'm making some tutorials for 1.8
> (i'm
> using 1.9).
> I stuck on error: Notice: Undefined property:
> Zend_Auth_Storage_Session::$read
>

Stop right there. It looks highly probable that you forgot the parentheses
followeding 'read'. That is, where you say $whatever->read, you need to say
$whatever->read(); PHP thinks you're trying to access a property rather than
call a method.

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


[fw-general] zend_mail_storage_imap and removeMessage()

2009-10-02 Thread David Mintz
I am suffering from http://framework.zend.com/issues/browse/ZF-5655 and
wondering if anyone knows if there's relief in sight, or what a good
workaround would be.

Subclass Zend_Mail_Storage_Imap and override removeMessage(), and do your
own expunge()?

This is clearly a significant problem -- how are we supposed to loop through
a set of messages and delete certain ones if we have an exception thrown at
us at every iteration that follows a call to removeMessage()?

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] grade zend framework and compared to Symfony and ASP.NET MVC

2009-09-22 Thread David Mintz
Yeah but ZF has the most incredibly patient, tolerant, indulgent, forgiving
community of users -- perhaps too much so! Why do I keep reading these
threads? Because I am looking for a good flamewar, but it's so hard to bait
these equanimous ZFers that none is forthcoming. It's getting really boring.
Enough is enough. Please stop your insufferable whining and go away.

Thank you.


-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


[fw-general] Re: can Zend_Auth_Adapter_DbTable::getResultRowObject() return result of a JOIN ?

2009-09-21 Thread David Mintz
On Mon, Sep 21, 2009 at 4:56 PM, David Mintz  wrote:

>
> If you want to load into the session a $user object holding the results of
> a JOIN query, is there any way to beat getResultRowObject() into
> cooperating, other than subclassing Zend_Auth_Adapter_DbTable and overriding
> the method? From what I have read (including source code) I think extending
> the class might not be a bad idea, but I thought I'd check.
>
>
Nevermind, I think I see the answer to my own question, that is if I surmise
correctly that we can get the Zend_Db_Select with getDbSelect() and
manipulate it before calling authenticate().

Man you ZF guys thought of everything. (Although ZF still won't do my
laundry; I expect that feature in the next release.)

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


[fw-general] can Zend_Auth_Adapter_DbTable::getResultRowObject() return result of a JOIN ?

2009-09-21 Thread David Mintz
If you want to load into the session a $user object holding the results of a
JOIN query, is there any way to beat getResultRowObject() into cooperating,
other than subclassing Zend_Auth_Adapter_DbTable and overriding the method?
>From what I have read (including source code) I think extending the class
might not be a bad idea, but I thought I'd check.


Thanks.

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] 2 actions my controller must be access for only loged users

2009-09-21 Thread David Mintz
2009/9/21 Vladas Diržys 

> Seems that aoohralex has a new name - aaabbbcccdaabb... :-)



Clever, huh? I guess that's the Pseudonym Pattern.

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] zf tool: no way to delete yet?

2009-09-09 Thread David Mintz
On Wed, Sep 9, 2009 at 10:13 AM, Benjamin Eberlei wrote:

>
> Don't underestimate yourself :-) We are always happy for any help
> and ralph would probably mentor you through the process if you would
> dedicate yourself to implementing this (and he hasn't started yet).
>
> If you seperate the Provider and the actual deletion, you can probably get
> this working by writing some tests for all the possible cases you can up
> with without too many problems.
>
> You should check out the Trunk documentation on Writing Providers it got
> several updates that should help you with some of the details on how
> to write a provider. I am thinking about updating it further to include
> details on the Project specific provider options.
>

First noob question:  when you say check out the trunk documentation, you
mean svn checkout http://framework.zend.com/svn/framework/standard/trunk, cd
into documentation/manual/  and build as per the README.
Right?

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] zf tool: no way to delete yet?

2009-09-09 Thread David Mintz
On Tue, Sep 8, 2009 at 11:55 PM, Ralph Schindler
wrote:

> Hey David,
>
> [delete] functionality is slated for 1.10.  It was left out of the 1.8 and
> 1.9 release for a couple of good reasons.  Since deleting is a pretty
> irreversible action, and sometimes is also a recursive action- we wanted to
> ensure that the console/cli interface at least had the capability to ask the
> user if deleting is OK, in other words confirming the decision to delete
> something.  This way, people will not accidentally delete things they will
> not be able to recover.
>
>
I wonder -- how hard is it to implement? I ask because I might like to
contribute, but if you guys are black belts, I am like, a yellow belt --
maybe green on a good day -- so don't know if I am equal to the task.


-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


[fw-general] zf tool: no way to delete yet?

2009-09-08 Thread David Mintz
Suppose you created controller foo with the cli tool but then you changed
your mind. I don't suppose there's way to 'zf delete controller foo'  so
that .zfproject.xml will stay in sync with reality. Or is there?
Meanwhile... delete it manually and don't worry about .zfproject.xml? Or...
bleh... update it by hand?

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] Re: unit testing front controller plugin: $front->getParam('bootstrap') returns NULL

2009-09-08 Thread David Mintz
On Sat, Sep 5, 2009 at 6:19 AM, Jens Kleikamp wrote:

> David Mintz wrote:
>
>> Playing around with Zend_Application and friends, I made a Bootstrap.php
>> which does this:
>>
>> protected function _initLog() {
>>
>>printf ("running %s:%s()\n",__CLASS__,__FUNCTION__);
>>return new Zend_Log(new Zend_Log_Writer_Firebug());
>> }
>> ---
>>
>> And a controller plugin:
>>
>> ---
>>
>> class Plugin_OurTestPlugin extends Zend_Controller_Plugin_Abstract {
>>
>>
>>function preDispatch(Zend_Controller_Request_Abstract $request ) {
>>
>>$front = Zend_Controller_Front::getInstance();
>>$bootstrap = $front->getParam('bootstrap');
>>printf ("\$bootstrap is a %s.\n", gettype($bootstrap));
>>$log = $front->getParam('bootstrap')->getResource('log');
>>$log->info('woo hoo, your controller plugin works');
>>}
>> }
>> ---
>> In a browser, the printf statement outputs " $bootstrap is a object" and
>> indeed it is, but when I run phpunit tests from the command line, --
>> forgive
>> all the "echo" output, I have temporarily polluted my code with echo()s in
>> order to determine what's executing --
>>
>>
>> Bootstrap constructor running...
>> running Bootstrap:_initLog()
>> we are bootstrapping the application in
>> /opt/www/shitou/tests/ControllerTestCase.php
>> $bootstrap is a NULL.
>>
>> Fatal error: Call to a member function getResource() on a non-object in
>> /opt/www/shitou/application/plugins/OurTestPlugin.php on line 14
>> 
>>
>


>
> I stumbled across the same issue lately.
>
> The bootstrap object is assigned as a frontcontroller param in the run()
> method of Zend_Application_Bootstrap_Bootstrap. But this method is not
> executed in the test environment, only bootstrap().
> I think that愀 the reason for the error you get (Fatal error: Call to a
> member function getResource() on a non-object...)
>
> As a workaround I set the frontcontroller param "bootstrap" manually within
> the callback method appBootstrap() of my testclasses.
>
> public function setUp()
> {
>    ...
> }
>
> public function appBootstrap()
> {
>$this->application->bootstrap();
>
>// set bootstrap param
>$bootstrap = $this->application->getBootstrap();
>$front = $bootstrap->getResource('FrontController');
>$front->setParam('bootstrap', $bootstrap);
> }
>
>
Sweet! That works. Thank you very much.

btw maybe this deserves to be mentioned in the official docs.

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


[fw-general] unit testing front controller plugin: $front->getParam('bootstrap') returns NULL

2009-09-04 Thread David Mintz
Playing around with Zend_Application and friends, I made a Bootstrap.php
which does this:

protected function _initLog() {

printf ("running %s:%s()\n",__CLASS__,__FUNCTION__);
return new Zend_Log(new Zend_Log_Writer_Firebug());
}
---

And a controller plugin:

---

class Plugin_OurTestPlugin extends Zend_Controller_Plugin_Abstract {


function preDispatch(Zend_Controller_Request_Abstract $request ) {

$front = Zend_Controller_Front::getInstance();
$bootstrap = $front->getParam('bootstrap');
printf ("\$bootstrap is a %s.\n", gettype($bootstrap));
$log = $front->getParam('bootstrap')->getResource('log');
$log->info('woo hoo, your controller plugin works');
}
}
---
In a browser, the printf statement outputs " $bootstrap is a object" and
indeed it is, but when I run phpunit tests from the command line, -- forgive
all the "echo" output, I have temporarily polluted my code with echo()s in
order to determine what's executing --


Bootstrap constructor running...
running Bootstrap:_initLog()
we are bootstrapping the application in
/opt/www/shitou/tests/ControllerTestCase.php
$bootstrap is a NULL.

Fatal error: Call to a member function getResource() on a non-object in
/opt/www/shitou/application/plugins/OurTestPlugin.php on line 14

Seems like my Bootstrap is instantiated before, not after, my base class
ControllerTestCase.php bootstraps the application. I must be doing something
weird but can't figure out what.

My test setup:

I have a phpunit.xml:
---


./


---

and bootstrap.php contains:

---
define('BASE_PATH', realpath(dirname(__FILE__) . '/../'));
define('APPLICATION_PATH', BASE_PATH . '/application');

// Include path
set_include_path(
'.'
. PATH_SEPARATOR . BASE_PATH . '/library'
. PATH_SEPARATOR . get_include_path()
);

// Define application environment
define('APPLICATION_ENV', 'testing');

require_once './ControllerTestCase.php';
echo "we are in ".__FILE__. "\n";

---

and ControllerTestCase.php looks like
---

abstract class ControllerTestCase extends
Zend_Test_PHPUnit_ControllerTestCase
{
public $application;
public $bootstrap;

public function setUp()
{
$this->application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);

$this->bootstrap = array($this, 'appBootstrap');
parent::setUp();
}

public function appBootstrap()
    {
    $this->application->bootstrap();

echo "we are bootstrapping the application in ".__FILE__."\n";
}
}

---


This is with ZF 1.9.0a1 -- because therein is a fix for a bug that was
ruining my day.

Thanks!

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] bootstrap resource versus zend_registry

2009-09-01 Thread David Mintz
On Tue, Sep 1, 2009 at 10:58 AM, Matthew Weier O'Phinney
wrote:

> -- David Mintz  wrote
> (on Tuesday, 01 September 2009, 10:03 AM -0400):
> > What are the relative merits of storing resources in the bootstrap
> container as
> > opposed to storing them in Zend_Registry?
>
> Testing. :)
>
> It's much harder to know what to put into the registry when testing than
> it is to setup your bootstrap, and to pull items from the bootstrap
> container.
>

Good enough! Then I guess I'm gonna start doing it that way (independent
thinker that I am.) Thanks.


-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


[fw-general] bootstrap resource versus zend_registry

2009-09-01 Thread David Mintz
What are the relative merits of storing resources in the bootstrap container
as opposed to storing them in Zend_Registry?

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] How to email the result of a dispatched request (or better how to save generated html)

2009-08-31 Thread David Mintz
On Mon, Aug 31, 2009 at 4:01 PM, David Mintz  wrote:

>
>
> On Sun, Aug 30, 2009 at 9:31 AM, fab2008  wrote:
>
>>
>> Hi all,
>>
>> I have a page with some news generated using ZF stack (Zend_MVC,
>> Zend_Layout, Zend_View, Zend_Navigation, etc); this page is available for
>> web browsing, but I need also to email this page with some additional
>> info.
>> Suppose I have a link like "Send this page to a friend" that bring to a
>> form
>> with from and to fields and a name field. When an user fill this form I
>> want
>> to email the complete news page (possibly using a different layout) with
>> an
>> header div that says "This page was sent to you by 
>> ".
>>
>> I want to avoid duplication of code, so I want to use the same
>> implementation of the web page, but i need the generated content in a
>> string, in this way I can email the generated HTML.
>>
>> Which is the best way for doing this in a controller action?
>>
>>
>
[Damn this gmail! your focus accidentally gets on the send button and you
press the wrong key and presto! your email is sent prematurely, speaking of
email. Hate it when that happens. Anyway, I meant to say...]

$this->_helper->layout->setLayout('foobaz');
$mailer = new Zend_Mail();
$mailer->addTo( $user->email, "$user->firstname $user->lastname" )
   ->setBodyHtml( $this->view->render( 'your/view.phtml' ) )
   ->setFrom ( 'some...@example.org', "Whomever" )
   ->setSubject ( "Your subject line" )
   ->send ();

HTH.



-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Re: [fw-general] How to email the result of a dispatched request (or better how to save generated html)

2009-08-31 Thread David Mintz
On Sun, Aug 30, 2009 at 9:31 AM, fab2008  wrote:

>
> Hi all,
>
> I have a page with some news generated using ZF stack (Zend_MVC,
> Zend_Layout, Zend_View, Zend_Navigation, etc); this page is available for
> web browsing, but I need also to email this page with some additional info.
> Suppose I have a link like "Send this page to a friend" that bring to a
> form
> with from and to fields and a name field. When an user fill this form I
> want
> to email the complete news page (possibly using a different layout) with an
> header div that says "This page was sent to you by 
> ".
>
> I want to avoid duplication of code, so I want to use the same
> implementation of the web page, but i need the generated content in a
> string, in this way I can email the generated HTML.
>
> Which is the best way for doing this in a controller action?
>
>

within a controller action, I have done something like

$this->_helper->layout->setLayout('foobaz');
$mailer = new Zend_Mail( );
$mailer->addTo( $user->email, "$user->firstname $user->lastname" )
 ->setBodyText ( $this->view->render( 'your/view.phtml' ) )
->setFrom ( 'interpret...@nysd.uscourts.gov', "Southern District
Interpreters" )->setSubject ( "SDNY Interpreters: Password Retrieval"
)->send ();
}




-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


[fw-general] custom validation error messages in ZF >= 1.8

2009-08-20 Thread David Mintz
I could use some help figuring out how to override the default validation
error messages with my own. Consider this snippet, based on the example in
the docs:


$validators = array(
'month' => array(
'NotEmpty',
'Digits',
'messages' => array(
0 =>'my custom message: this is empty',
1=>'my custom message: this ain\'t digits!'),
)
);
$input = new Zend_Filter_Input(null,$validators,
array(
'month'=>''
)
);
if ($input->isValid()) {
echo "input is valid\n" ;
} else {
print_r($input->getMessages());
}


Output when I run this in 1.7.8:

Array
(
[month] => Array
(
[isEmpty] => my custom message: this is empty yo
[stringEmpty] => '' is an empty string
)

)

Output when I run this in 1.9.0: (undesired):


Array
(
[month] => Array
(
[isEmpty] => You must give a non-empty value for field 'month'
    )

)

I am having this problem with several Zend validation classes, not just
Zend_Validate_NotEmpty. Any help is much appreciated.

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


  1   2   >