2009年1月31日星期六

Re: [fw-webservices] Problem with Zend_XmlRpc_Client

I just spent several frustrating hours trying to set up a Web service using
first Zend_REST_Server and then Zend_XmlRpc_Server. Both turned out to be to
limiting.

Eventually, I took Matthew O'Phinney's advice from
http://www.nabble.com/Our-REST-implementation-td10834932s16154.html this
discussion and used the standard MVC mechanisms and had the views returned
well formatted XML data (I do eventually intend to leverage ContextSwitch
capability).

- Steve W.


anz_nabble wrote:
>
> Can anyone explain how to develop a simple webservice using xml rpc.
> I had done many searches and didn't find a useful one. I need to know
> which files are placed in which locations
>
> Any good tutorial?
>

--
View this message in context: http://www.nabble.com/Problem-with-Zend_XmlRpc_Client-tp21598685p21772238.html
Sent from the Zend Web Services mailing list archive at Nabble.com.

Re: [fw-db] question about using a like statement in a select

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmErssACgkQ7bkAtAithusj1ACdGrX3nZMeK+jQZjSbTEyxjiRP
gXEAoMD0Y/aZLq+jz5l/UON2YNMTGrFw
=vIE2
-----END PGP SIGNATURE-----
water wrote:
> I'm having a problem using quoting and a like statement with somehting
> like this:
...
> $sql="select id, headline, body from node where body like
> '%".$this->_db->quote($query)."%'";
...
> Is there a way to call quote without it putting the surrounding single
> quotes.

As someone has already mentioned, you can use:

$this->_db->quote('%' . $query . '%');
(i.e put the wildcards inside the value.

> This is actually a larger issue (and I'd probably consider a bug
> for things like 'select * from menu where id=23' where adding a set of
> single quotes around 23 adds time to query processing on MySQL.

If the value you are passing to be quotes is an integer (and not just a
string representing an integer), it won't have quotes added around it:
eg.
$this->_db->quote((int) $value);

--

Brenton Alker

http://blog.tekerson.com/

Re: [fw-db] question about using a like statement in a select

is there a way to just escape (analagous to msqli_real_escape_string)? The docs mention escaping and quoting and just mention quote, quoteInto functions.

-jonathan


From: Jaka Jančar <jaka@kubje.org>
To: water <zflist@yahoo.com>
Cc: fw-db@lists.zend.com
Sent: Saturday, January 31, 2009 9:16:23 AM
Subject: Re: [fw-db] question about using a like statement in a select

That's the way it should work. It _QUOTES_ the value, not escapes certian chars.

Use:
$sql="select id, headline, body from node where body like " . $this->_db->quote('%' . $query . '%');

On 31. Jan 2009, at 18:12, water wrote:

I'm having a problem using quoting and a like statement with somehting like this:
<?php
class Query extends Zend_Db_Table{
    
    public function getMenuResults($query){
        $sql="select id, headline, body from node where body like '%".$this->_db->quote($query)."%'";
        echo $sql."<br/>";
       //outputting: select id, headline, body from node where body like '%'some'%'

with problem being inner single quotes.

Is there a way to call quote without it putting the surrounding single quotes. This is actually a larger issue (and I'd probably consider a bug for things like 'select * from menu where id=23' where adding a set of single quotes around 23 adds time to query processing on MySQL.

I don't want to get into the syntax of ZF's select statement as I don't see much advantage to it to writing straight SQL.

thanks,

jonathan 






Re: [fw-db] question about using a like statement in a select

That's the way it should work. It _QUOTES_ the value, not escapes certian chars.

Use:
$sql="select id, headline, body from node where body like " . $this->_db->quote('%' . $query . '%');

On 31. Jan 2009, at 18:12, water wrote:

I'm having a problem using quoting and a like statement with somehting like this:
<?php
class Query extends Zend_Db_Table{
    
    public function getMenuResults($query){
        $sql="select id, headline, body from node where body like '%".$this->_db->quote($query)."%'";
        echo $sql."<br/>";
       //outputting: select id, headline, body from node where body like '%'some'%'

with problem being inner single quotes.

Is there a way to call quote without it putting the surrounding single quotes. This is actually a larger issue (and I'd probably consider a bug for things like 'select * from menu where id=23' where adding a set of single quotes around 23 adds time to query processing on MySQL.

I don't want to get into the syntax of ZF's select statement as I don't see much advantage to it to writing straight SQL.

thanks,

jonathan 





[fw-db] question about using a like statement in a select

I'm having a problem using quoting and a like statement with somehting like this:
<?php
class Query extends Zend_Db_Table{
   
    public function getMenuResults($query){
        $sql="select id, headline, body from node where body like '%".$this->_db->quote($query)."%'";
        echo $sql."<br/>";
       //outputting: select id, headline, body from node where body like '%'some'%'

with problem being inner single quotes.

Is there a way to call quote without it putting the surrounding single quotes. This is actually a larger issue (and I'd probably consider a bug for things like 'select * from menu where id=23' where adding a set of single quotes around 23 adds time to query processing on MySQL.

I don't want to get into the syntax of ZF's select statement as I don't see much advantage to it to writing straight SQL.

thanks,

jonathan



RE: [fw-db] Zend_Db_Adapter_DB2 on I5

Yes Raplh, i'm using ZendCore 2.6.1 on I5.


-----Message d'origine-----
De : Ralph Schindler [mailto:ralph.schindler@zend.com]
Envoyé : vendredi 30 janvier 2009 21:41
À : David Ulrich; fw-db@lists.zend.com
Objet : Re: [fw-db] Zend_Db_Adapter_DB2 on I5

Are you using Zend Core for i5 by chance, or what is the PHP platform you
are running on?

-ralph

Re: [fw-mvc] Re: URL mapping

you want to look at the router
http://framework.zend.com/manual/en/zend.controller.router.html

2009/1/29 Shaun Hare <shaun_hare@yahoo.co.uk>:
>
> As a newcomer to Zend I have decided to learn quick and fast with a small
> blog engine.
> I seem to be getting along OK but have little idea how I can achieve nice
> clean post title based urls mapped to my
> getPostAction
>
> E.g myblog.com/new-post-title & myblog.com/another-post-title Routes to
> indexController getPostAction
>
> What would be my best strategy
>
> I understand I could use the _call method? Will this overide other routes I
> have set up?
>
> What route would I create? Would I just slipt the url in the call method
>
> Would be grateful of some guidence
>
> Many Thanks
> Shaun
>
>
>

--
----------------------------------------------------------------------
[MuTe]
----------------------------------------------------------------------

2009年1月30日星期五

[fw-gdata] Listing documents published to the web

I would like to list the documents that have been published to the web, but
the http://code.google.com/apis/documents/docs/2.0/reference.html#Feeds
documentation states that, currently, only the private visibility is
available.

Is there another way to determine if a document in the feed result has been
published to the web?


--
View this message in context: http://www.nabble.com/Listing-documents-published-to-the-web-tp21759859p21759859.html
Sent from the Zend gdata mailing list archive at Nabble.com.

Re: [fw-db] OOP Design question related to Zend_Db_Adapter

Also I'd like to add that I find this a *major* flaw in Zend Framework is
that they decided to require instances of classes instead of working with
interfaces. So for example, Zend_Db_Table should be able to work with *any*
class that implements IDbAdapter (which doesnt exist but should)... I'm not
sure why they havent been using interfaces, because tightly coupling their
classes with each other through class types create huge limitations.
--
View this message in context: http://www.nabble.com/OOP-Design-question-related-to-Zend_Db_Adapter-tp21754135p21756178.html
Sent from the Zend DB mailing list archive at Nabble.com.

Re: [fw-mvc] Re: Separating Models from DB Access

OK, think I'm getting my head round this now :-) . So, my "gateway" is
actually a data mapper, and that is used to hide the domain objects
from the DB and vice-versa. A script will access the mapper, request a
Site object, the mapper will do all the DB work, create a Site object
from the data and then return that object. When the object has been
updated and the changes need to be saved back to the DB the object is
parsed back to the mapper, which again takes care of the DB work.

The DB knows nothing about the mapper or the domain objects.
The domain objects no nothing about the mapper or the DB.
The mapper knows about both the DB and the domain objects.

Am I on the right lines?

Re: [fw-mvc] Zend_Dojo & I18N

Thank you for advice but I get "modulename is undefined" JavaScript
error of loader.js if I use the suggested method call.

What are the steps to setup I18N for Zend_Dojo for instance fr_FR
locale for DateTextBox's drop-down calendar? Did I miss anything in my
steps or they should work?

On Fri, Jan 30, 2009 at 7:55 PM, Matthew Weier O'Phinney
<matthew@zend.com> wrote:
> -- Kostyantyn Shakhov <kshakhov@gmail.com> wrote
> (on Friday, 30 January 2009, 05:33 PM +0200):
>> I'm trying to setup I18N for Zend_Dojo namely for elements of
>> Zend_Dojo_Form like drop-down calendar of DateTextBox etc.
>>
>> My steps are:
>>
>> 1) In the layout script:
>> $this->dojo()->setDjConfigOption('extraLocale', 'fr-fr')
>> ->requireModule('dojo.i18n');
>>
>> Nothing happened. The calendar's month name and week names are in English still;
>>
>> 2) Add 'locale' to the form element declaration:
>> $this->addElement(
>> 'DateTextBox',
>> 'foo',
>> array(
>> 'decorators' => $this->elementDecorators,
>> 'label' => 'Date',
>> 'required' => true,
>> 'invalidMessage' => 'Invalid date specified.',
>> 'formatLength' => 'long',
>> 'locale' => 'fr-fr'
>> )
>> );
>>
>> Nothing is changed still. The calendar's locale is en_US still.
>>
>> Also, in the Dojo Internationalization manual written that Dojo has
>> dojo.requireLocalization() which is used to declare usage of I18N
>> resources and load them. I haven't found a corresponding method in
>> Zend_Dojo package.
>
> You should be able to add that line using the addJavascript() method:
>
> $view->dojo()->addJavascript('dojo.requireLocalization();');
>
>
> --
> Matthew Weier O'Phinney
> Software Architect | matthew@zend.com
> Zend Framework | http://framework.zend.com/
>

Re: [fw-mvc] Re: Separating Models from DB Access

As long as your model objects are confined to being simple data holders
with no behavior or aggregated objects or collections, you're fine. But
if you find that you want to create objects that use a lot of object
composition, it gets really hard to support with table-centric gateways
(regardless of whether or not Zend_Db_Table is involved). The Data
Mapper approach is probably the best known general way to tackle this.
That said, it's still sufficiently difficult to make table-centric
domain models viable for a lot of applications.

Regards,
Bryce Lohr


Jack Sleight wrote:
> Yeah, I'm going to allow multiple tables in some of the other models.
> Still not entirely sure how I'm going to abstract some of the
> functionality for other models, but I'm aware of the need for multiple
> tables.
>
> I've put together a prototype of this now, currently looking at moving
> all DB related logic to the Site_Gateway, so that the Site objects
> only contain arrays of raw data, not rows. Reason being some objects
> will be created from selects on joined tables, so the single row idea
> doesn't really work. Also, I might want to do a single query for a
> whole load of data (spanning multiple joined tables) and then create
> individual objects. For example, perform a query for a site and all
> it's pages, then create a single Site object which will contain
> multiple Page objects.
>

Re: [fw-db] Zend_Db_Adapter_DB2 on I5

Are you using Zend Core for i5 by chance, or what is the PHP platform you
are running on?

-ralph


On 1/30/09 3:54 AM, "David Ulrich" <david@dahuu.fr> wrote:

> Ralph,
>
> I was wrong, connection problem on V5R3 was not corrected with ptf.
> I works only the first time you try to connect.
>
> David
>
> -----Message d'origine-----
> De : David Ulrich [mailto:david@dahuu.fr]
> Envoyé : jeudi 29 janvier 2009 23:31
> À : fw-db@lists.zend.com
> Objet : RE: [fw-db] Zend_Db_Adapter_DB2 on I5
>
> Ralph,
>
> After applying ptf, connection works fine on V5R3. The first problem is ok
> now.
> But as I said this morning, fetchAll() with or without select don't work on
> both version V5R3 and V5R4 with latest cum level.
> See my previous message to Lydia.
>
> Thanks,
> David
>
> -----Message d'origine-----
> De : David Ulrich [mailto:david@dahuu.fr]
> Envoyé : jeudi 29 janvier 2009 11:31
> À : 'Alexandre, Lydia'; fw-db@lists.zend.com
> Objet : RE: [fw-db] Zend_Db_Adapter_DB2 on I5
>
> Yes Lydia,
>
> This is the second problem...
>
> When I try this
>
> $alertes = new Alertes();
> $select = $alertes->select();
> echo $select->__toString();
> print_r($alertes->fetchAll($select);
>
> the result is :
> SELECT "MYFILE".* FROM "MYLIB"."MYFILE"
> And failed.
>
> This should be
> SELECT "MYFILE".* FROM "MYLIB"."MYFILE" AS MYFILE
>
>
> David
>
>
> -----Message d'origine-----
> De : Alexandre, Lydia [mailto:LAlexandre@GLD.BE]
> Envoyé : jeudi 29 janvier 2009 09:41
> À : fw-db@lists.zend.com
> Cc : David Ulrich
> Objet : RE: [fw-db] Zend_Db_Adapter_DB2 on I5
>
> Hi,
>
> The v5r3 problem apart from ...
> The real problem is : why they is no shema in the request (and no *)
>
> The trace show : ('select MYFILE...')
> It must be 'select * from MYLIB.MYFILE' (with i5 always use the shema)
>
> Now fetchAll is deprecated, try to use an other syntax. But in documentation
> I find :
>
> $alertes = new Alertes();
>
> $select = $alertes->select();
> $select->where('bug_status = ?', 'NEW'); // use the good field or try not
> use the where ...
>
> $rows = $alertes->fetchAll($select);
>
>
> Lydia
> ~maKyo
>
> -----Message d'origine-----
> De : David Ulrich [mailto:david@dahuu.fr]
> Envoyé : mercredi 28 janvier 2009 19:10
> À : 'Ralph Schindler'; fw-db@lists.zend.com
> Objet : RE: [fw-db] Zend_Db_Adapter_DB2 on I5
>
> I checked both and they are not at the latest level.
> I download now the latest level and I'll test after apply and do an ipl.
>
> Thanks,
> David
>
> -----Message d'origine-----
> De : Ralph Schindler [mailto:ralph.schindler@zend.com] Envoyé : mercredi 28
> janvier 2009 18:54 À : David Ulrich; fw-db@lists.zend.com Objet : Re:
> [fw-db] Zend_Db_Adapter_DB2 on I5
>
> I've been told that there are some DB Connection issues that were fixed by
> fixed by IBM PTF (program temporary fix). Can you confirm that both
> machines are up to date in this regard?
>
> -ralph
>
>
> On 1/28/09 11:39 AM, "David Ulrich" <david@dahuu.fr> wrote:
>
>> Ralph,
>>
>> I tested with schema too but i had the same result (on V5R3).
>> I tested with getConnection() too and the result is :
>>
>> [28-jan-2009 18:33:37] PHP Fatal error: Uncaught exception
>> 'Zend_Db_Adapter_Db2_Exception' with message 'Connexion à base de
>> données relationnelle S65EA94B déjà établie. SQLCODE=-842' in
>> /usr/local/Zend/ZendFramework-1.7.3/library/Zend/Db/Adapter/Db2.php:19
>> 1
>> Stack trace:
>> #0
>>
> /usr/local/Zend/ZendFramework-1.7.3/library/Zend/Db/Adapter/Abstract.php(300
>> ): Zend_Db_Adapter_Db2->_connect()
>> #1 /www/php/site/admin/public/testdb.php(15):
>> Zend_Db_Adapter_Abstract->getConnection()
>> #2 {main}
>> thrown in
>> /usr/local/Zend/ZendFramework-1.7.3/library/Zend/Db/Adapter/Db2.php on
> line
>> 191
>>
>> Same script works fine on V5R4.
>>
>> David Ulrich
>>
>> -----Message d'origine-----
>> De : Ralph Schindler [mailto:ralph.schindler@zend.com] Envoyé :
>> mercredi 28 janvier 2009 18:11 À : David Ulrich; fw-db@lists.zend.com
>> Objet : Re: [fw-db] Zend_Db_Adapter_DB2 on I5
>>
>>> From the trace stack, it appears your connection is not being made
>> correctly.
>>
>> Have you tried adding schema to your Zend_Db::factory()?
>>
>> I imagine it would look like so:
>>
>> $db = Zend_Db::factory('Db2',array(
>>         'host'=>'127.0.0.1',
>>         'username'=>'USERNAME',
>>         'password'=>'password',
>>         'dbname'=>'DATABASE',
>> 'schema'=>'MYLIB'
>> ));
>>
>> And to test, you can simply ensure this works:
>>
>> $db->getConnection(); // this should not fail.
>>
>> sidenote: connections are lazy-loaded until the first usage, so while
>> the above is something good to test your connection; lazy-loading the
> connection
>> (which is what you are doing in your scripts utilizing the table) are
>> a
> good
>> thing. Once you figure out why the connection is failing, remove the
>> getConnection() from your bootstrap. This will prevent requests that
> don't
>> use a db connection from actually connecting to the database.
>>
>>
>> On 1/28/09 7:45 AM, "David Ulrich" <david@dahuu.fr> wrote:
>>
>>> Hi,
>>>
>>> I¹m trying to use Zend_Db on my I5 but I have some problems.
>>> I create a little test file and test it on 2 I5 (one V5R3 and one V5R4).
>>> I downloaded the latest svn trunk for testing.
>>>
>>> [code]
>>> <?php
>>> require_once "Zend/Loader.php";
>>> // Set up autoload.
>>> Zend_Loader::registerAutoload();
>>>
>>> class Alertes extends Zend_Db_Table_Abstract {
>>>         /**
>>>          * The default table name
>>>          */
>>>         protected $_name = 'MYFILE';
>>>         protected $_schema = 'MYLIB';
>>>         protected $_primary = 'MACLE'; }
>>>
>>> $db = Zend_Db::factory('Db2',array(
>>>         'host'=>'127.0.0.1',
>>>         'username'=>'USERNAME',
>>>         'password'=>'password',
>>>         'dbname'=>'DATABASE'));
>>> Zend_Db_Table::setDefaultAdapter($db);
>>>
>>> // #1
>>> $sql = 'select * from MYLIB.MYFILE';
>>> print_r($db->fetchAll($sql));
>>>
>>> // #2
>>> $alertes = new Alertes();
>>> print_r($alertes->fetchAll());
>>> ?>
>>> [/code]
>>>
>>> On V5R3, nothing works. I got this message (as the message is in
>>> French, message is : Connection to database DATABASE already done) :
>>> [code]
>>> [28-Jan-2009 14:33:40] PHP Fatal error:  Uncaught exception
>>> 'Zend_Db_Adapter_Db2_Exception' with message 'Connexion à base de
>>> données relationnelle DATABASE déjà établie. SQLCODE=-842' in
>>> /usr/local/Zend/ZendFramework-1.7.3/library/Zend/Db/Adapter/Db2.php:1
>>> 91
>>> Stack trace:
>>> #0
>>>
>>
> /usr/local/Zend/ZendFramework-1.7.3/library/Zend/Db/Adapter/Abstract.php(441
>> ):
>>> Zend_Db_Adapter_Db2->_connect()
>>> #1
>>>
>>
> /usr/local/Zend/ZendFramework-1.7.3/library/Zend/Db/Adapter/Abstract.php(668
>> ):
>>> Zend_Db_Adapter_Abstract->query('select * from M...', Array)
>>> #2 /www/php/site/admin/public/testdb.php(16):
>>> Zend_Db_Adapter_Abstract->fetchAll('select * from M...')
>>> #3 {main}
>>>   thrown in
>>> /usr/local/Zend/ZendFramework-1.7.3/library/Zend/Db/Adapter/Db2.php
>>> on
>> line
>>> 191
>>> [/code]
>>>
>>> On V5R4, the #1 works fine but not #2 wich this message :
>>> [code]
>>> [28-Jan-2009 11:43:53] PHP Fatal error:  Uncaught exception
>>> 'Zend_Db_Statement_Db2_Exception' with message 'Qualificatif de
>>> colonne
> ou
>>> table MYFILE non défini. SQLCODE=-5001' in
>>> /usr/local/Zend/ZendFramework-1.7/library/Zend/Db/Statement/Db2.php:7
>>> 1
>>> Stack trace:
>>> #0 /usr/local/Zend/ZendFramework-1.7/library/Zend/Db/Statement.php(109):
>>> Zend_Db_Statement_Db2->_prepare('select MYFILE...')
>>> #1
> /usr/local/Zend/ZendFramework-1.7/library/Zend/Db/Adapter/Db2.php(230):
>>> Zend_Db_Statement->__construct(Object(Zend_Db_Adapter_Db2), 'select
>>> MYFILE...')
>>> #2
>>>
>>
> /usr/local/Zend/ZendFramework-1.7/library/Zend/Db/Adapter/Abstract.php(456):
>>> Zend_Db_Adapter_Db2->prepare('select MYFILE...')
>>> #3
>>>
>>
> /usr/local/Zend/ZendFramework-1.7/library/Zend/Db/Adapter/Abstract.php(668):
>>> Zend_Db_Adapter_Abstract->query('select MYFILE...', Array)
>>> #4 /www/alertes/public/testdb.php(23):
>>> Zend_Db_Adapter_Abstract->fetchAll('select MYFILE...')
>>> #5 {main}
>>>   thrown in
>>> /usr/local/Zend/ZendFramework-1.7/library/Zend/Db/Statement/Db2.php
>>> on
>> line 71
>>> [/code]
>>> The sql generated by Zend_DB_Table does not work on I5.
>>>
>>> Did I miss something ?
>>>
>>> Thanks,
>>> David
>>>
>
> --
> Ralph Schindler
> Software Engineer | ralph.schindler@zend.com
> Zend Framework | http://framework.zend.com/
>
>

--
Ralph Schindler
Software Engineer | ralph.schindler@zend.com
Zend Framework | http://framework.zend.com/

Re: [fw-mvc] Re: Separating Models from DB Access

Yeah, I'm going to allow multiple tables in some of the other models.
Still not entirely sure how I'm going to abstract some of the
functionality for other models, but I'm aware of the need for multiple
tables.

I've put together a prototype of this now, currently looking at moving
all DB related logic to the Site_Gateway, so that the Site objects
only contain arrays of raw data, not rows. Reason being some objects
will be created from selects on joined tables, so the single row idea
doesn't really work. Also, I might want to do a single query for a
whole load of data (spanning multiple joined tables) and then create
individual objects. For example, perform a query for a site and all
it's pages, then create a single Site object which will contain
multiple Page objects.

[fw-db] OOP Design question related to Zend_Db_Adapter

I'd need the help of some good designer/architect.

We will be switching to a replication database system (Master/Slaves) and I
will me modifying our company's framework (which is built on top of Zend
Framework) so that our database adapter supports Master/Slave mode, meaning
the read-only operations will be done on a slave, and all writes will be
done on the master. So the adapter will support theorically two active
connections at the same time (won't connect to more than one slave
throughout it's life). So this adapter will take a list of possible
connections, you'll specify which one(s) is/are the master(s), and which one
is/are the slave(s).

I have design issues here. I'm a purist in OOP and try to do things right,
but here's I'm kind of hitting a wall.

My first idea was to make a MyCompany_Db_Adapter_Abstract which would not
derive from anything and would only be a wrapper around all methods from
Zend_Db_Adapter_Abstract and would call the actual method on the write
server or read server depending on the operation. It would internall create
a Pdo_Adapter_MySql (when you use it in a derived MySQL adapter class) and I
would call the actual adapter through my wrapper and call the method on it.
In theory that's good because then you don't derive from a class which is
made for *single* connections... but this leads me to another problem, I
want to use classes like Zend_Db_Table and this class requires a descendant
of Zend_Db_Adapter_Abstract to be passed. So having my own adapter which
doesnt derive from Zend_Db_Adapter_Abstract would make my adapter not usable
with other Zend_Db classes...

Which leads me to the second solution, which is to derive from
Zend_Db_Adapter_Abstract. But this causes other problems.
Zend_Db_Adapter_Abstract is built with single connection in mind. It has a
_connect method which connects to a single specific server. I would need to
rewrite a bunch of methods, and would end up with lot of 'waste' in the
class. But the major problem is that from this point, if there are
modifications made to Zend_Db_Adapter_Abstract, I will need to recheck my
own MyCompany_Db_Adapter_Abstract to make sure it's in synch with it's
parent, because a few methods will have been completly rewritten and thus
become independant. Also, overriding a method without calling the parent is
bad practice, it's doable but it's really bad practice, you end up paying
the price for it when you use it too much.

Ideally, Zend Framework would come up with it's own "replication" DB
Adapter, but for now I'm a bit puzzled at what the best solution would be.
--
View this message in context: http://www.nabble.com/OOP-Design-question-related-to-Zend_Db_Adapter-tp21754135p21754135.html
Sent from the Zend DB mailing list archive at Nabble.com.

Re: [fw-mvc] Re: Separating Models from DB Access

Looks pretty logical, only one comment is that do you want to lock
yourself to one table per gateway? Other than that it looks pretty
good, I would do a prototype of it and see how the implementation
goes, I went through a few designs as some of my early prototypes
became a bit unwieldy. Just remember to set some clear goals for what
you want to achieve, in my case I wanted to be able to test without
the need for a database connection, therefore I abstracted more than
usual.

2009/1/30 Jack Sleight <jack.sleight@gmail.com>:
> Hi Everyone,
> Thanks for your help, I've been reading up on various methods of doing
> this, and found this article very useful
> http://weierophinney.net/matthew/archives/202-Model-Infrastructure.html.
> I've now got the beginnings of something that could work, this is my
> basic set up so far, feedback would be very welcome:
>
> (This is working with Site entities not Users)
>
> class Site
> {
> protected $_row;
> protected $_data;
>
> public function __construct(Zend_Db_Table_Row $row, array $data = null);
> public function save();
> public function setBatch($data);
> public function __set($name, $value);
> public function __get($name);
> public function __isset($name);
> public function __unset($name);
> }
>
> class Site_Gateway
> {
> protected $_table;
>
> public function __construct();
> public function create($data);
> public function fetch($id);
> public function fetchPrimary();
> public function fetchAll();
> }
>
> class Site_Set implements Iterator, Countable
> {
> protected $_items = array();
> protected $_index = 0;
>
> public function __construct(array $items);
> public function count();
> public function current();
> public function key();
> public function next();
> public function rewind();
> public function valid();
> }
>
> So, basic logic: You use Site_Gateway to retrieve Site objects or
> create new site objects. fetch*() methods return either a Site object
> or a Site_Set object that contains multiple site objects.
>
> When a Site object is created the data is copied out of $row and into
> $data, sets/gets are performed on $data and upon save() the date is
> copied into the row, saved and then copied back out (in case anything
> changed, eg. AUTO_INCREMENT fields).
>
> Site::__construct() takes an additional array of data.
> Site_Gateway::create() gives the Site object it creates an empty $row
> and the array of data.
>
> When values are set on Site they are filtered and validated. If
> validation fails an exception is thrown. When Site::setBatch() is used
> thrown exceptions are caught and the errors aggregated, they are then
> all thrown in one Exception object, this is so you can report multiple
> validation errors back to the UI, rather than one field at a time.
>
> Any comments, suggestions etc.?
> Cheers,
> Jack
>
>

--
----------------------------------------------------------------------
[MuTe]
----------------------------------------------------------------------

Re: [fw-mvc] replace $this->escape() with $this->esc()

-- Hans Anderson <windsurf17@gmail.com> wrote
(on Friday, 30 January 2009, 09:24 AM -0600):
> I'm new to ZF and to some of the concepts of OO type systems in general, though
> I've used PHP for quite some time. So, my apologies if this is really basic,
> but how can I efficiently create a replacement for $this->escape() that would
> still use all of the settings (like SetEscape(), etc) but be named $this->e()
> or $this->esc(), just for cleaner view files (with the caveat that $this->e()
> isn't as immediately understandable as $this->escape()).

This last point is why we have named the method escape() - to ensure
it's immediately apparent what the method does.

> Do I need to extend Zend_View and change how the whole MVC system works or is
> there some other way?

As somebody else noted, you can extend Zend_View, or also write a helper
to do this.

One idea we're playing around with is to make escaping the default for
ZF 2.0 -- in other words, shift from selectively escaping to selectively
using the raw value. This is a better practice when you consider the
security mantra, "Filter input, escape output," as it acts as a
poka-yoke -- it does the right thing by default, but gives you the
option of explicitly asking for the more dangerous alternative.

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

Re: [fw-mvc] CSS Styles when using Dojo in Zend

-- Leonard Challis <gisterogue@gmail.com> wrote
(on Friday, 30 January 2009, 08:01 AM -0800):
> I have been playing with Dojo Forms in Zend and wanted to clear something up
> regarding their CSS styling.
>
> I believe we have everything running correctly -- it's usually a
> Zend_Dojo_Form with several Zend_Dojo_Form_Element_* instances, all set up
> programatically through Zend, i.e. without writing any JavaScript ourselves.
>
> Selecting the tundra theme, each time the page was loaded it would display
> the form with very minimal styling (in fact, mostly just styles from
> dijit.css). After tailing a few logs and having a look around in the
> different CSS files I decided to try putting class="tundra" in the html tag.
> This rendered the form with the Tundra styles nicely and was far prettier. I
> thought it was a little bit 'hacky' though and thought there must be a way
> to achieve this in a nicer fashion. After a bit of searching I found this
> little snippet from
> http://www.nabble.com/Re%3A-Zend-dojo.data-usage%2C-i-dont-understand-p20915966.html
> http://www.nabble.com/Re%3A-Zend-dojo.data-usage%2C-i-dont-understand-p20915966.html
>
>
> * Set the "tundra" class on either the <body> element, or a div
> surrounding the form. Let's try the latter:
>
> <?
> $this->dojo()->requireModule('dojox.data.QueryReadStore')
> ->addStylesheetModule('dijit.themes.tundra');
> ?>
> <div class="tundra">
> <?= $this->form ?>
> </div>
>
>
> This would suggest I would have to manually add the reference to the tundra
> class anywhere I was using Dojo Forms.
>
> Is this the accepted/correct way of setting each element to inherit the
> related theme styles?

Yes. The rationale is that you may not want the Dijit theme to apply to
your entire page, but may only want it selectively around certain areas
of your page -- forms, for instance, or accordion containers.

> And would it be a bad idea to have this set automatically like the
> other classes and javascript codes is when using Dojo in Zend?

The problem with this is that ZF actually doesn't know what your markup
will look like. While Zend_Dojo_Form will create a form, and could
potentially wrap it in a <div> with the dijit theme class set, it's also
entirely possible that you'll be setting the dijit theme later in the
request lifecycle -- for instance, in the layout file. As such, it
becomes very difficult -- if not impossible -- to do this automatically
in a consistent way.

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

Re: [fw-mvc] Zend_Dojo & I18N

-- Kostyantyn Shakhov <kshakhov@gmail.com> wrote
(on Friday, 30 January 2009, 05:33 PM +0200):
> I'm trying to setup I18N for Zend_Dojo namely for elements of
> Zend_Dojo_Form like drop-down calendar of DateTextBox etc.
>
> My steps are:
>
> 1) In the layout script:
> $this->dojo()->setDjConfigOption('extraLocale', 'fr-fr')
> ->requireModule('dojo.i18n');
>
> Nothing happened. The calendar's month name and week names are in English still;
>
> 2) Add 'locale' to the form element declaration:
> $this->addElement(
> 'DateTextBox',
> 'foo',
> array(
> 'decorators' => $this->elementDecorators,
> 'label' => 'Date',
> 'required' => true,
> 'invalidMessage' => 'Invalid date specified.',
> 'formatLength' => 'long',
> 'locale' => 'fr-fr'
> )
> );
>
> Nothing is changed still. The calendar's locale is en_US still.
>
> Also, in the Dojo Internationalization manual written that Dojo has
> dojo.requireLocalization() which is used to declare usage of I18N
> resources and load them. I haven't found a corresponding method in
> Zend_Dojo package.

You should be able to add that line using the addJavascript() method:

$view->dojo()->addJavascript('dojo.requireLocalization();');


--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

[fw-mvc] Re: Separating Models from DB Access

Hi Everyone,
Thanks for your help, I've been reading up on various methods of doing
this, and found this article very useful
http://weierophinney.net/matthew/archives/202-Model-Infrastructure.html.
I've now got the beginnings of something that could work, this is my
basic set up so far, feedback would be very welcome:

(This is working with Site entities not Users)

class Site
{
protected $_row;
protected $_data;

public function __construct(Zend_Db_Table_Row $row, array $data = null);
public function save();
public function setBatch($data);
public function __set($name, $value);
public function __get($name);
public function __isset($name);
public function __unset($name);
}

class Site_Gateway
{
protected $_table;

public function __construct();
public function create($data);
public function fetch($id);
public function fetchPrimary();
public function fetchAll();
}

class Site_Set implements Iterator, Countable
{
protected $_items = array();
protected $_index = 0;

public function __construct(array $items);
public function count();
public function current();
public function key();
public function next();
public function rewind();
public function valid();
}

So, basic logic: You use Site_Gateway to retrieve Site objects or
create new site objects. fetch*() methods return either a Site object
or a Site_Set object that contains multiple site objects.

When a Site object is created the data is copied out of $row and into
$data, sets/gets are performed on $data and upon save() the date is
copied into the row, saved and then copied back out (in case anything
changed, eg. AUTO_INCREMENT fields).

Site::__construct() takes an additional array of data.
Site_Gateway::create() gives the Site object it creates an empty $row
and the array of data.

When values are set on Site they are filtered and validated. If
validation fails an exception is thrown. When Site::setBatch() is used
thrown exceptions are caught and the errors aggregated, they are then
all thrown in one Exception object, this is so you can report multiple
validation errors back to the UI, rather than one field at a time.

Any comments, suggestions etc.?
Cheers,
Jack

Re: [fw-mvc] replace $this->escape() with $this->esc()

I would create a new view helper. This is probably the simplest way to do this.

<?php

require_once 'Zend/View/Helper/Abstract.php';

class My_View_Helper_Esc extends Zend_View_Helper_Abstract
{
    public function esc($string)
    {
        return $this->view->escape($string);
    }
}

?>


-Hector


On Fri, Jan 30, 2009 at 8:15 AM, Hans Anderson <windsurf17@gmail.com> wrote:
Thanks for the replies. 

Here's what I've done, which works, but I am curious if it's the best/most efficent/most maintainable, etc method:

I created Hans_Zend_View.php with Nikolaos' code in the application directory (same as bootstrap... I can move it, but there for testing).

Then in bootstrap I did:

require_once 'Hans_Zend_View.php';
$view = new Hans_Zend_View();

$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRenderer->setView($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);

There was a "setViewSuffix('php')" after "setView($view)" that caused an exception, so I removed it.  Also, I'm not clear on "addHelper" -- removing that line caused an exception, but the name "Helper" seems strange.  Didn't I just extend Zend_View?  Is Zend_View itself a "helper"?

Thanks,
Hans



On Fri, Jan 30, 2009 at 9:35 AM, Nikolaos Dimopoulos <nikos@niden.net> wrote:
Create a new class:

class Hans_Zend_View extends Zend_View
{
    public function esc($var)
    {
        return parent::escape($var);
    }

    public function e($var)
    {
        return parent::escape($var);
    }
}

So when you want to use esc instead of escape it will work. You will only need to use the Hans_Zend_View class instead of the Zend_View. By extending Zend_View you have all the available resources of that class and also you add to it with your own logic i.e. esc function.

If in your class you declare a function that has the same name as a function that is present in the class that is being extended, your function will override that one. Hence if for instance you used 

    public function escape($var)
    {
        return 'blah blah';
    }

you would effectively 'kill' the Zend_View's escape function. (just an FYI)


I hope this helps.

Nikolaos


On Fri, Jan 30, 2009 at 10:24, Hans Anderson <windsurf17@gmail.com> wrote:
I'm new to ZF and to some of the concepts of OO type systems in general, though I've used PHP for quite some time.  So, my apologies if this is really basic, but how can I efficiently create a replacement for $this->escape() that would still use all of the settings (like SetEscape(), etc) but be named $this->e() or $this->esc(), just for cleaner view files (with the caveat that $this->e() isn't as immediately understandable as $this->escape()).

Do I need to extend Zend_View and change how the whole MVC system works or is there some other way?

Not a hugely important thing, but it keeps occurring to me to ask.

TIA,
Hans



--
The contents of this message may contain confidential or privileged information and is intended solely for the recipient(s). Use or distribution to and by any other party is not authorized. If you are not the intended recipient, copying, distribution or use of the contents of this information is prohibited.



--
Hans Anderson
+ growth is sparse on the tops of mountains +
http://hansanderson.com/
Psalm 41:1

Re: [fw-mvc] Separating Models from DB Access

Yeah its a big problem! The/a data mapper is used to create a clean
"Domain Model" which is really for modelling very complex business
requirements, which can be overkill for many projects, however I am
glad that there are proposals now for the tools to allow this :)

Me and Rob Allen have discussed some ideas on our blogs.

http://akrabat.com/2008/12/13/on-models-in-a-zend-framework-application

http://www.thepopeisdead.com/main/comments/zend_framework_book_example_application/

Hope this helps

2009/1/30 Bryce Lohr <brycel@patientadvocate.org>:
> You're running into the classic object-relational mapping problem. It's a
> terribly difficult problem in general, which is why you don't commonly see
> solutions in those articles. They're primarily selling the ideals, and
> leaving the implementation as an exercise for the reader... :)
>
> Check out Benjamin Eberlei's proposal [1] for a Data Mapper for ZF, and
> Martin Fowler's PoEAA for background info.
>
> [1] http://framework.zend.com/wiki/x/OwCQ
>
> Regards,
> Bryce Lohr
>
>
> Jack Sleight wrote:
>>
>> Hi,
>> I'm currently building a new ZF based app, and on the advice of many
>> articles I've read, and my own opinion, want to separate the "model" classes
>> from the DB access classes. My problem is, for all the articles advising
>> this is the way to do it, I've yet to find an example implementation or any
>> advice on how to implement it in the real world with ZF.
>>
>> As far as I understand it, the DB layer should be hidden under the model
>> layer, so at no point should the controller be accessing the Table or Row
>> classes.
>> For example, say I have these classes:
>>
>> User - This is the user object
>>
>> User_Table extends Zend_Db_Table
>> User_Table_Row extends Zend_Db_Table_Row
>>
>> So, say we're in a controller and have some data for a new user, creating
>> that user would be a case of:
>>
>> $user = new User($properties);
>>
>> But what about looking up an existing user? Which of these is right?:
>>
>> $user = new User($id);
>>
>> $user = User::find($id);
>>
>> $users = new Users();
>> $user = $users->find($id);
>>
>> And getting a collection of multiple users? I want an array of User
>> objects returned, not User_Table_Row objects, where should these come from
>> and how should they be created internally by the model.
>>
>> Sorry for all the questions, I just really want to do this the best way,
>> Thanks,
>
>

--
----------------------------------------------------------------------
[MuTe]
----------------------------------------------------------------------

RE: [fw-mvc] Auth against AztiveDirectory

Hello Jamie,

I appreciate a lot this piece of info, I just was looking right direction on
this, just yesterday I was testing the ldap module and I successfully
connected and extracted some info from my AD container, so right now I am
going to test the ldap auth adapter, thank you for the tip =)

Another thing I'm thinking is how to solve the mapping of the roles of these
users (from AD) to be loaded into my ACL object (I have a plugin that loads
all resources and roles config to Zend_Acl object from DB by the way).
Before it was easy because the mapping is straightforward from my users
table, just add some field to map the role with acl's table, but now I just
try figuring out how to accomplish with this mapping since I can't add
arbitrary fields to AD container..

my thought:
Extract each single user from AD and insert this into my DB (mysql) users
table, then do the mapping through this. but, what happens if an user from
AD is deleted? Not so bad since not logon is allowed to this user, but yet
her permissions are on DB table (mysql)... have you faced this before? Any
thoughts on this will be appreciated, thanks in advance to all.

My best regards,
JG

> -----Mensaje original-----
> De: Jamie Sutherland [mailto:jsutherland@bloxx.com]
> Enviado el: Viernes, 30 de Enero de 2009 09:48 a.m.
> Para: Jaime Garcia
> CC: fw-mvc@lists.zend.com
> Asunto: RE: [fw-mvc] Auth against AztiveDirectory
>
> Jaime,
>
> I've found that the documentation on the website is a bit misleading in
> getting a server to connect with Active Directory (AD). I've recently
> gone through the process myself and had to refer to the source several
> times to workout how to implement it. Also this is pretty difficult to
> debug if you've previously setup an authorisation plugin like in
> previous examples using a database table. If you have implemented this
> plugin, disable it until you've proved the LDAP auth is working.
>
> I'll assume you are attempting to follow the instructions here:
> http://framework.zend.com/manual/en/zend.auth.adapter.ldap.html
>
> Firstly the config.ini setup required for AD:
>
> Don't copy the example on the website completely. First off the line
>
> "ldap.log_path = /tmp/ldap.log"
>
> This line will cause issues when passing the options to
> Zend_Auth_Adapter_Ldap as it doesn't provide an array. If you whis to
> setup a log. I suggest having a different config option. (i.e.
> log.ldap.log_path = /tmp/ldap.log)
>
> Also make sure you *do not* have the line below in your config.ini.
>
> "ldap.server.bindRequiresDn = 1"
>
> This will perform a lookup on the uid (eDirectory/OpenLDAP) rather than
> the sAMAccountName (AD)
>
> A stupid point, but it's also worth mentioning is that you must have
> the
> php module ldap.so loaded or available.
>
> sudo apt-get install php5-ldap // if your running ubnutu
>
>
> Hope this helps!
>
> Cheers,
> Jamie
>
> -----Original Message-----
> From: Tobias Gies [mailto:tobiasgies@googlemail.com]
> Sent: 29 January 2009 22:32
> To: Jaime Garcia
> Cc: fw-mvc@lists.zend.com
> Subject: Re: [fw-mvc] Auth against AztiveDirectory
>
> Hi Jamie,
>
> you can use Zend_Ldap and Zend_Auth_Adapter_Ldap for that task.
> Examples of how to use Zend_Ldap with AD can be found in the manual.
>
> Best regards,
> Tobias
>
> 2009/1/29 Jaime Garcia <jgarcia@vali.com.mx>:
> > Hi my friends,
> >
> > Has anyone authenticated users against Active Directory using MVC ZF?
> >
> >
> >
> > Best regards,
> >
> > J.G.

RE: [fw-mvc] Re:Usage

Hopefully not off topic

Could any one please point me to good resources on the business case
For using Zend framework and PHP?

Many Thanks

Shaun

-----Original Message-----
From: keith Pope [mailto:mute.pop3@googlemail.com]
Sent: 31 January 2009 09:51
To: shaun_hare@yahoo.co.uk
Cc: fw-mvc@lists.zend.com
Subject: Re: [fw-mvc] Re: URL mapping


you want to look at the router
http://framework.zend.com/manual/en/zend.controller.router.html

2009/1/29 Shaun Hare <shaun_hare@yahoo.co.uk>:
>
> As a newcomer to Zend I have decided to learn quick and fast with a
> small blog engine. I seem to be getting along OK but have little idea
> how I can achieve nice clean post title based urls mapped to my
> getPostAction
>
> E.g myblog.com/new-post-title & myblog.com/another-post-title Routes
> to indexController getPostAction
>
> What would be my best strategy
>
> I understand I could use the _call method? Will this overide other
> routes I have set up?
>
> What route would I create? Would I just slipt the url in the call
> method
>
> Would be grateful of some guidence
>
> Many Thanks
> Shaun
>
>
>

--
----------------------------------------------------------------------
[MuTe]
----------------------------------------------------------------------

Re: [fw-mvc] replace $this->escape() with $this->esc()

Thanks for the replies. 

Here's what I've done, which works, but I am curious if it's the best/most efficent/most maintainable, etc method:

I created Hans_Zend_View.php with Nikolaos' code in the application directory (same as bootstrap... I can move it, but there for testing).

Then in bootstrap I did:

require_once 'Hans_Zend_View.php';
$view = new Hans_Zend_View();

$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRenderer->setView($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);

There was a "setViewSuffix('php')" after "setView($view)" that caused an exception, so I removed it.  Also, I'm not clear on "addHelper" -- removing that line caused an exception, but the name "Helper" seems strange.  Didn't I just extend Zend_View?  Is Zend_View itself a "helper"?

Thanks,
Hans


On Fri, Jan 30, 2009 at 9:35 AM, Nikolaos Dimopoulos <nikos@niden.net> wrote:
Create a new class:

class Hans_Zend_View extends Zend_View
{
    public function esc($var)
    {
        return parent::escape($var);
    }

    public function e($var)
    {
        return parent::escape($var);
    }
}

So when you want to use esc instead of escape it will work. You will only need to use the Hans_Zend_View class instead of the Zend_View. By extending Zend_View you have all the available resources of that class and also you add to it with your own logic i.e. esc function.

If in your class you declare a function that has the same name as a function that is present in the class that is being extended, your function will override that one. Hence if for instance you used 

    public function escape($var)
    {
        return 'blah blah';
    }

you would effectively 'kill' the Zend_View's escape function. (just an FYI)


I hope this helps.

Nikolaos


On Fri, Jan 30, 2009 at 10:24, Hans Anderson <windsurf17@gmail.com> wrote:
I'm new to ZF and to some of the concepts of OO type systems in general, though I've used PHP for quite some time.  So, my apologies if this is really basic, but how can I efficiently create a replacement for $this->escape() that would still use all of the settings (like SetEscape(), etc) but be named $this->e() or $this->esc(), just for cleaner view files (with the caveat that $this->e() isn't as immediately understandable as $this->escape()).

Do I need to extend Zend_View and change how the whole MVC system works or is there some other way?

Not a hugely important thing, but it keeps occurring to me to ask.

TIA,
Hans



--
The contents of this message may contain confidential or privileged information and is intended solely for the recipient(s). Use or distribution to and by any other party is not authorized. If you are not the intended recipient, copying, distribution or use of the contents of this information is prohibited.



--
Hans Anderson
+ growth is sparse on the tops of mountains +
http://hansanderson.com/
Psalm 41:1

[fw-mvc] Re: Re[fw-mvc] gex Hostname Routing + Config Ini Example?

Is this not even possible with Zend_Controller_Router_Route_Hostname?


j5 wrote:
>
> Hey,
>
> I am looking for an example of hostname routing based on regular
> expressions in Zend_Config_Ini syntax compatible with ZF 1.7.3.
>
> Could anyone provide an example?
>
> Thanks
>

--
View this message in context: http://www.nabble.com/Regex-Hostname-Routing-%2B-Config-Ini-Example--tp21741488p21750193.html
Sent from the Zend MVC mailing list archive at Nabble.com.

[fw-mvc] CSS Styles when using Dojo in Zend

I have been playing with Dojo Forms in Zend and wanted to clear something up
regarding their CSS styling.

I believe we have everything running correctly -- it's usually a
Zend_Dojo_Form with several Zend_Dojo_Form_Element_* instances, all set up
programatically through Zend, i.e. without writing any JavaScript ourselves.

Selecting the tundra theme, each time the page was loaded it would display
the form with very minimal styling (in fact, mostly just styles from
dijit.css). After tailing a few logs and having a look around in the
different CSS files I decided to try putting class="tundra" in the html tag.
This rendered the form with the Tundra styles nicely and was far prettier. I
thought it was a little bit 'hacky' though and thought there must be a way
to achieve this in a nicer fashion. After a bit of searching I found this
little snippet from
http://www.nabble.com/Re%3A-Zend-dojo.data-usage%2C-i-dont-understand-p20915966.html
http://www.nabble.com/Re%3A-Zend-dojo.data-usage%2C-i-dont-understand-p20915966.html


* Set the "tundra" class on either the <body> element, or a div
surrounding the form. Let's try the latter:

<?
$this->dojo()->requireModule('dojox.data.QueryReadStore')
->addStylesheetModule('dijit.themes.tundra');
?>
<div class="tundra">
<?= $this->form ?>
</div>


This would suggest I would have to manually add the reference to the tundra
class anywhere I was using Dojo Forms.

Is this the accepted/correct way of setting each element to inherit the
related theme styles? And would it be a bad idea to have this set
automatically like the other classes and javascript codes is when using Dojo
in Zend?
--
View this message in context: http://www.nabble.com/CSS-Styles-when-using-Dojo-in-Zend-tp21750013p21750013.html
Sent from the Zend MVC mailing list archive at Nabble.com.

RE: [fw-mvc] Auth against AztiveDirectory

Jaime,

I've found that the documentation on the website is a bit misleading in
getting a server to connect with Active Directory (AD). I've recently
gone through the process myself and had to refer to the source several
times to workout how to implement it. Also this is pretty difficult to
debug if you've previously setup an authorisation plugin like in
previous examples using a database table. If you have implemented this
plugin, disable it until you've proved the LDAP auth is working.

I'll assume you are attempting to follow the instructions here:
http://framework.zend.com/manual/en/zend.auth.adapter.ldap.html

Firstly the config.ini setup required for AD:

Don't copy the example on the website completely. First off the line

"ldap.log_path = /tmp/ldap.log"

This line will cause issues when passing the options to
Zend_Auth_Adapter_Ldap as it doesn't provide an array. If you whis to
setup a log. I suggest having a different config option. (i.e.
log.ldap.log_path = /tmp/ldap.log)

Also make sure you *do not* have the line below in your config.ini.

"ldap.server.bindRequiresDn = 1"

This will perform a lookup on the uid (eDirectory/OpenLDAP) rather than
the sAMAccountName (AD)

A stupid point, but it's also worth mentioning is that you must have the
php module ldap.so loaded or available.

sudo apt-get install php5-ldap // if your running ubnutu


Hope this helps!

Cheers,
Jamie

-----Original Message-----
From: Tobias Gies [mailto:tobiasgies@googlemail.com]
Sent: 29 January 2009 22:32
To: Jaime Garcia
Cc: fw-mvc@lists.zend.com
Subject: Re: [fw-mvc] Auth against AztiveDirectory

Hi Jamie,

you can use Zend_Ldap and Zend_Auth_Adapter_Ldap for that task.
Examples of how to use Zend_Ldap with AD can be found in the manual.

Best regards,
Tobias

2009/1/29 Jaime Garcia <jgarcia@vali.com.mx>:
> Hi my friends,
>
> Has anyone authenticated users against Active Directory using MVC ZF?
>
>
>
> Best regards,
>
> J.G.

Re: [fw-mvc] replace $this->escape() with $this->esc()

Create a new class:

class Hans_Zend_View extends Zend_View
{
    public function esc($var)
    {
        return parent::escape($var);
    }

    public function e($var)
    {
        return parent::escape($var);
    }
}

So when you want to use esc instead of escape it will work. You will only need to use the Hans_Zend_View class instead of the Zend_View. By extending Zend_View you have all the available resources of that class and also you add to it with your own logic i.e. esc function.

If in your class you declare a function that has the same name as a function that is present in the class that is being extended, your function will override that one. Hence if for instance you used 

    public function escape($var)
    {
        return 'blah blah';
    }

you would effectively 'kill' the Zend_View's escape function. (just an FYI)


I hope this helps.

Nikolaos


On Fri, Jan 30, 2009 at 10:24, Hans Anderson <windsurf17@gmail.com> wrote:
I'm new to ZF and to some of the concepts of OO type systems in general, though I've used PHP for quite some time.  So, my apologies if this is really basic, but how can I efficiently create a replacement for $this->escape() that would still use all of the settings (like SetEscape(), etc) but be named $this->e() or $this->esc(), just for cleaner view files (with the caveat that $this->e() isn't as immediately understandable as $this->escape()).

Do I need to extend Zend_View and change how the whole MVC system works or is there some other way?

Not a hugely important thing, but it keeps occurring to me to ask.

TIA,
Hans



--
The contents of this message may contain confidential or privileged information and is intended solely for the recipient(s). Use or distribution to and by any other party is not authorized. If you are not the intended recipient, copying, distribution or use of the contents of this information is prohibited.

[fw-mvc] Zend_Dojo & I18N

I'm trying to setup I18N for Zend_Dojo namely for elements of
Zend_Dojo_Form like drop-down calendar of DateTextBox etc.

My steps are:

1) In the layout script:
$this->dojo()->setDjConfigOption('extraLocale', 'fr-fr')
->requireModule('dojo.i18n');

Nothing happened. The calendar's month name and week names are in English still;

2) Add 'locale' to the form element declaration:
$this->addElement(
'DateTextBox',
'foo',
array(
'decorators' => $this->elementDecorators,
'label' => 'Date',
'required' => true,
'invalidMessage' => 'Invalid date specified.',
'formatLength' => 'long',
'locale' => 'fr-fr'
)
);

Nothing is changed still. The calendar's locale is en_US still.

Also, in the Dojo Internationalization manual written that Dojo has
dojo.requireLocalization() which is used to declare usage of I18N
resources and load them. I haven't found a corresponding method in
Zend_Dojo package.

[fw-mvc] replace $this->escape() with $this->esc()

I'm new to ZF and to some of the concepts of OO type systems in general, though I've used PHP for quite some time.  So, my apologies if this is really basic, but how can I efficiently create a replacement for $this->escape() that would still use all of the settings (like SetEscape(), etc) but be named $this->e() or $this->esc(), just for cleaner view files (with the caveat that $this->e() isn't as immediately understandable as $this->escape()).

Do I need to extend Zend_View and change how the whole MVC system works or is there some other way?

Not a hugely important thing, but it keeps occurring to me to ask.

TIA,
Hans

Re: [fw-mvc] Separating Models from DB Access

You're running into the classic object-relational mapping problem. It's
a terribly difficult problem in general, which is why you don't commonly
see solutions in those articles. They're primarily selling the ideals,
and leaving the implementation as an exercise for the reader... :)

Check out Benjamin Eberlei's proposal [1] for a Data Mapper for ZF, and
Martin Fowler's PoEAA for background info.

[1] http://framework.zend.com/wiki/x/OwCQ

Regards,
Bryce Lohr


Jack Sleight wrote:
> Hi,
> I'm currently building a new ZF based app, and on the advice of many
> articles I've read, and my own opinion, want to separate the "model"
> classes from the DB access classes. My problem is, for all the
> articles advising this is the way to do it, I've yet to find an
> example implementation or any advice on how to implement it in the
> real world with ZF.
>
> As far as I understand it, the DB layer should be hidden under the
> model layer, so at no point should the controller be accessing the
> Table or Row classes.
> For example, say I have these classes:
>
> User - This is the user object
>
> User_Table extends Zend_Db_Table
> User_Table_Row extends Zend_Db_Table_Row
>
> So, say we're in a controller and have some data for a new user,
> creating that user would be a case of:
>
> $user = new User($properties);
>
> But what about looking up an existing user? Which of these is right?:
>
> $user = new User($id);
>
> $user = User::find($id);
>
> $users = new Users();
> $user = $users->find($id);
>
> And getting a collection of multiple users? I want an array of User
> objects returned, not User_Table_Row objects, where should these come
> from and how should they be created internally by the model.
>
> Sorry for all the questions, I just really want to do this the best way,
> Thanks,

Re: [fw-mvc] Throwing an exception in the Router (part two)

-- Scott Davey <sdavey@datalink.com.au> wrote
(on Friday, 30 January 2009, 06:23 PM +1100):
> Further to my last post, in order for my suggested Front Controller change to
> work, a change needs to also be made to Zend_Controller_Plugin_ErrorHandler to
> add a preDispatch() method.
>
> Here's my suggested change (tested against ZF 1.7.3)

This is something Ralph and I have been wanting to address for some
months now, actually. Could you create an issue in the tracker and post
your patch, please?


> Zend_Controller_Plugin_ErrorHandler (begins line 189)
>
>
> /**
> * preDispatch() plugin hook -- check for exceptions during routing and
> * dispatches the error handler if necessary
> *
> * @see {@link Zend_Controller_Plugin_ErrorHandler::_handleException}
> * @param Zend_Controller_Request_Abstract $request
> * @return void
> */
> public function preDispatch(Zend_Controller_Request_Abstract $request)
> {
> $this->_handleException($request);
> }
>
>
> /**
> * postDispatch() plugin hook -- check for exceptions during the
> dispatch
> * loop and dispatches the error handler if necessary
> *
> * @see {@link Zend_Controller_Plugin_ErrorHandler::_handleException}
> * @param Zend_Controller_Request_Abstract $request
> * @return void
> */
> public function postDispatch(Zend_Controller_Request_Abstract $request)
> {
> $this->_handleException($request);
> }
>
> /**
> * Check for exceptions and dispatch error handler if necessary
> *
> * If the 'noErrorHandler' front controller flag has been set,
> * returns early.
> *
> * @param Zend_Controller_Request_Abstract $request
> * @return void
> */
> private function _handleException(Zend_Controller_Request_Abstract
> $request)
> {
> // ... code that used to be in postDispatch() goes in here
> }
>
>
> And for completeness, I'll repeat my change to Zend_Controller_Front (begins
> line 893):
>
>
>
> try {
> /**
> * Notify plugins of router startup
> */
> $this->_plugins->routeStartup($this->_request);
>
> $router->route($this->_request);
>
> /**
> * Notify plugins of router completion
> */
> $this->_plugins->routeShutdown($this->_request);
>
> /**
> * Notify plugins of dispatch loop startup
> */
> $this->_plugins->dispatchLoopStartup($this->_request);
>
> } catch (Exception $e) {
> if ($this->throwExceptions()) {
> throw $e;
> }
> $this->_response->setException($e);
> }

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

Re: [fw-mvc] Separating Models from DB Access

I would recommend using a DAO (Data Access Object)...
More or less you create an interface 

interface IUserDAO {
   public load($id);
   public save(User $user);
}

the load method should return a Transfer Object which in PHP land usually just means an associative array but could also be a Zend_Db_Row, and your User entity object should consume that array to load itself. 

normally you would use a factory or DI container for this, but in your controller you would do:
 $dao = ZendDbTableUserDAO($user_table);

$user = new User($dao->load(1));

The issue is not about not letting your controller access the data...its about separating the data access from the model. The model should only know about its own business logic, and know nothing about persistence (loading and saving itself). This is part of the Single Responsibility Principal, I think.

The DAO hides and abstracts away the data access from the model and your controller. You controller is only talking to an interface, and that interface could make straight sql queries, call database abstraction tool like Zend_DB, call a Zend_DB_Table, load an XML file, talk to a webservice, or whatever you want.

When you're done, you can either pass the model itself back into DAO or a Transfer Object back and that will handle saving it to the database

Hope this helps!



On Fri, Jan 30, 2009 at 6:04 AM, Jack Sleight <jack.sleight@gmail.com> wrote:
Hi,
I'm currently building a new ZF based app, and on the advice of many articles I've read, and my own opinion, want to separate the "model" classes from the DB access classes. My problem is, for all the articles advising this is the way to do it, I've yet to find an example implementation or any advice on how to implement it in the real world with ZF.

As far as I understand it, the DB layer should be hidden under the model layer, so at no point should the controller be accessing the Table or Row classes.
For example, say I have these classes:

User - This is the user object

User_Table extends Zend_Db_Table
User_Table_Row extends Zend_Db_Table_Row

So, say we're in a controller and have some data for a new user, creating that user would be a case of:

$user = new User($properties);

But what about looking up an existing user? Which of these is right?:

$user = new User($id);

$user = User::find($id);

$users = new Users();
$user = $users->find($id);

And getting a collection of multiple users? I want an array of User objects returned, not User_Table_Row objects, where should these come from and how should they be created internally by the model.

Sorry for all the questions, I just really want to do this the best way,
Thanks,
--
Jack


[fw-mvc] Separating Models from DB Access

Hi,
I'm currently building a new ZF based app, and on the advice of many
articles I've read, and my own opinion, want to separate the "model"
classes from the DB access classes. My problem is, for all the articles
advising this is the way to do it, I've yet to find an example
implementation or any advice on how to implement it in the real world
with ZF.

As far as I understand it, the DB layer should be hidden under the model
layer, so at no point should the controller be accessing the Table or
Row classes.
For example, say I have these classes:

User - This is the user object

User_Table extends Zend_Db_Table
User_Table_Row extends Zend_Db_Table_Row

So, say we're in a controller and have some data for a new user,
creating that user would be a case of:

$user = new User($properties);

But what about looking up an existing user? Which of these is right?:

$user = new User($id);

$user = User::find($id);

$users = new Users();
$user = $users->find($id);

And getting a collection of multiple users? I want an array of User
objects returned, not User_Table_Row objects, where should these come
from and how should they be created internally by the model.

Sorry for all the questions, I just really want to do this the best way,
Thanks,
--
Jack

RE: [fw-db] Zend_Db_Adapter_DB2 on I5

Ralph,

I was wrong, connection problem on V5R3 was not corrected with ptf.
I works only the first time you try to connect.

David

-----Message d'origine-----
De : David Ulrich [mailto:david@dahuu.fr]
Envoyé : jeudi 29 janvier 2009 23:31
À : fw-db@lists.zend.com
Objet : RE: [fw-db] Zend_Db_Adapter_DB2 on I5

Ralph,

After applying ptf, connection works fine on V5R3. The first problem is ok
now.
But as I said this morning, fetchAll() with or without select don't work on
both version V5R3 and V5R4 with latest cum level.
See my previous message to Lydia.

Thanks,
David

-----Message d'origine-----
De : David Ulrich [mailto:david@dahuu.fr]
Envoyé : jeudi 29 janvier 2009 11:31
À : 'Alexandre, Lydia'; fw-db@lists.zend.com
Objet : RE: [fw-db] Zend_Db_Adapter_DB2 on I5

Yes Lydia,

This is the second problem...

When I try this

$alertes = new Alertes();
$select = $alertes->select();
echo $select->__toString();
print_r($alertes->fetchAll($select);

the result is :
SELECT "MYFILE".* FROM "MYLIB"."MYFILE"
And failed.

This should be
SELECT "MYFILE".* FROM "MYLIB"."MYFILE" AS MYFILE


David


-----Message d'origine-----
De : Alexandre, Lydia [mailto:LAlexandre@GLD.BE]
Envoyé : jeudi 29 janvier 2009 09:41
À : fw-db@lists.zend.com
Cc : David Ulrich
Objet : RE: [fw-db] Zend_Db_Adapter_DB2 on I5

Hi,

The v5r3 problem apart from ...
The real problem is : why they is no shema in the request (and no *)

The trace show : ('select MYFILE...')
It must be 'select * from MYLIB.MYFILE' (with i5 always use the shema)

Now fetchAll is deprecated, try to use an other syntax. But in documentation
I find :

$alertes = new Alertes();

$select = $alertes->select();
$select->where('bug_status = ?', 'NEW'); // use the good field or try not
use the where ...

$rows = $alertes->fetchAll($select);


Lydia
~maKyo

-----Message d'origine-----
De : David Ulrich [mailto:david@dahuu.fr]
Envoyé : mercredi 28 janvier 2009 19:10
À : 'Ralph Schindler'; fw-db@lists.zend.com
Objet : RE: [fw-db] Zend_Db_Adapter_DB2 on I5

I checked both and they are not at the latest level.
I download now the latest level and I'll test after apply and do an ipl.

Thanks,
David

-----Message d'origine-----
De : Ralph Schindler [mailto:ralph.schindler@zend.com] Envoyé : mercredi 28
janvier 2009 18:54 À : David Ulrich; fw-db@lists.zend.com Objet : Re:
[fw-db] Zend_Db_Adapter_DB2 on I5

I've been told that there are some DB Connection issues that were fixed by
fixed by IBM PTF (program temporary fix). Can you confirm that both
machines are up to date in this regard?

-ralph


On 1/28/09 11:39 AM, "David Ulrich" <david@dahuu.fr> wrote:

> Ralph,
>
> I tested with schema too but i had the same result (on V5R3).
> I tested with getConnection() too and the result is :
>
> [28-jan-2009 18:33:37] PHP Fatal error: Uncaught exception
> 'Zend_Db_Adapter_Db2_Exception' with message 'Connexion à base de
> données relationnelle S65EA94B déjà établie. SQLCODE=-842' in
> /usr/local/Zend/ZendFramework-1.7.3/library/Zend/Db/Adapter/Db2.php:19
> 1
> Stack trace:
> #0
>
/usr/local/Zend/ZendFramework-1.7.3/library/Zend/Db/Adapter/Abstract.php(300
> ): Zend_Db_Adapter_Db2->_connect()
> #1 /www/php/site/admin/public/testdb.php(15):
> Zend_Db_Adapter_Abstract->getConnection()
> #2 {main}
> thrown in
> /usr/local/Zend/ZendFramework-1.7.3/library/Zend/Db/Adapter/Db2.php on
line
> 191
>
> Same script works fine on V5R4.
>
> David Ulrich
>
> -----Message d'origine-----
> De : Ralph Schindler [mailto:ralph.schindler@zend.com] Envoyé :
> mercredi 28 janvier 2009 18:11 À : David Ulrich; fw-db@lists.zend.com
> Objet : Re: [fw-db] Zend_Db_Adapter_DB2 on I5
>
>> From the trace stack, it appears your connection is not being made
> correctly.
>
> Have you tried adding schema to your Zend_Db::factory()?
>
> I imagine it would look like so:
>
> $db = Zend_Db::factory('Db2',array(
>         'host'=>'127.0.0.1',
>         'username'=>'USERNAME',
>         'password'=>'password',
>         'dbname'=>'DATABASE',
> 'schema'=>'MYLIB'
> ));
>
> And to test, you can simply ensure this works:
>
> $db->getConnection(); // this should not fail.
>
> sidenote: connections are lazy-loaded until the first usage, so while
> the above is something good to test your connection; lazy-loading the
connection
> (which is what you are doing in your scripts utilizing the table) are
> a
good
> thing. Once you figure out why the connection is failing, remove the
> getConnection() from your bootstrap. This will prevent requests that
don't
> use a db connection from actually connecting to the database.
>
>
> On 1/28/09 7:45 AM, "David Ulrich" <david@dahuu.fr> wrote:
>
>> Hi,
>>
>> I¹m trying to use Zend_Db on my I5 but I have some problems.
>> I create a little test file and test it on 2 I5 (one V5R3 and one V5R4).
>> I downloaded the latest svn trunk for testing.
>>
>> [code]
>> <?php
>> require_once "Zend/Loader.php";
>> // Set up autoload.
>> Zend_Loader::registerAutoload();
>>
>> class Alertes extends Zend_Db_Table_Abstract {
>>         /**
>>          * The default table name
>>          */
>>         protected $_name = 'MYFILE';
>>         protected $_schema = 'MYLIB';
>>         protected $_primary = 'MACLE'; }
>>
>> $db = Zend_Db::factory('Db2',array(
>>         'host'=>'127.0.0.1',
>>         'username'=>'USERNAME',
>>         'password'=>'password',
>>         'dbname'=>'DATABASE'));
>> Zend_Db_Table::setDefaultAdapter($db);
>>
>> // #1
>> $sql = 'select * from MYLIB.MYFILE';
>> print_r($db->fetchAll($sql));
>>
>> // #2
>> $alertes = new Alertes();
>> print_r($alertes->fetchAll());
>> ?>
>> [/code]
>>
>> On V5R3, nothing works. I got this message (as the message is in
>> French, message is : Connection to database DATABASE already done) :
>> [code]
>> [28-Jan-2009 14:33:40] PHP Fatal error:  Uncaught exception
>> 'Zend_Db_Adapter_Db2_Exception' with message 'Connexion à base de
>> données relationnelle DATABASE déjà établie. SQLCODE=-842' in
>> /usr/local/Zend/ZendFramework-1.7.3/library/Zend/Db/Adapter/Db2.php:1
>> 91
>> Stack trace:
>> #0
>>
>
/usr/local/Zend/ZendFramework-1.7.3/library/Zend/Db/Adapter/Abstract.php(441
> ):
>> Zend_Db_Adapter_Db2->_connect()
>> #1
>>
>
/usr/local/Zend/ZendFramework-1.7.3/library/Zend/Db/Adapter/Abstract.php(668
> ):
>> Zend_Db_Adapter_Abstract->query('select * from M...', Array)
>> #2 /www/php/site/admin/public/testdb.php(16):
>> Zend_Db_Adapter_Abstract->fetchAll('select * from M...')
>> #3 {main}
>>   thrown in
>> /usr/local/Zend/ZendFramework-1.7.3/library/Zend/Db/Adapter/Db2.php
>> on
> line
>> 191
>> [/code]
>>
>> On V5R4, the #1 works fine but not #2 wich this message :
>> [code]
>> [28-Jan-2009 11:43:53] PHP Fatal error:  Uncaught exception
>> 'Zend_Db_Statement_Db2_Exception' with message 'Qualificatif de
>> colonne
ou
>> table MYFILE non défini. SQLCODE=-5001' in
>> /usr/local/Zend/ZendFramework-1.7/library/Zend/Db/Statement/Db2.php:7
>> 1
>> Stack trace:
>> #0 /usr/local/Zend/ZendFramework-1.7/library/Zend/Db/Statement.php(109):
>> Zend_Db_Statement_Db2->_prepare('select MYFILE...')
>> #1
/usr/local/Zend/ZendFramework-1.7/library/Zend/Db/Adapter/Db2.php(230):
>> Zend_Db_Statement->__construct(Object(Zend_Db_Adapter_Db2), 'select
>> MYFILE...')
>> #2
>>
>
/usr/local/Zend/ZendFramework-1.7/library/Zend/Db/Adapter/Abstract.php(456):
>> Zend_Db_Adapter_Db2->prepare('select MYFILE...')
>> #3
>>
>
/usr/local/Zend/ZendFramework-1.7/library/Zend/Db/Adapter/Abstract.php(668):
>> Zend_Db_Adapter_Abstract->query('select MYFILE...', Array)
>> #4 /www/alertes/public/testdb.php(23):
>> Zend_Db_Adapter_Abstract->fetchAll('select MYFILE...')
>> #5 {main}
>>   thrown in
>> /usr/local/Zend/ZendFramework-1.7/library/Zend/Db/Statement/Db2.php
>> on
> line 71
>> [/code]
>> The sql generated by Zend_DB_Table does not work on I5.
>>
>> Did I miss something ?
>>
>> Thanks,
>> David
>>

--
Ralph Schindler
Software Engineer | ralph.schindler@zend.com
Zend Framework | http://framework.zend.com/