2010年2月26日星期五

RE: [fw-mvc] Generated urls to map to controllers and actions

Hi,

I think a good start could be to write a Controller Plugin, something like:

<?php
class Controllers_Plugin_Maproutes extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
Zend_Registry::set('zfRequestController', $request->getControllerName());
Zend_Registry::set('zfRequestAction', $request->getActionName());

$oYourMappingTable = new MappingTable();

if($oYourMappingTable->isMappable($request->getControllerName(), $request->getActionName())) {
$request->setControllerName($oYourMappingTable->getMappedControllerName());
$request->setActionName($oYourMappingTable->setMappedActionName());
} else {
// route to error (or pass the request to a next route...)
$request->setControllerName('error');
$request->setActionName('error');
}
}
}

Regards, Viktor

> -----Original Message-----
> From: Jachim Coudenys [mailto:Jachim.Coudenys@guideline.be]
> Sent: Friday, February 26, 2010 8:55 AM
> To: fw-mvc@lists.zend.com
> Subject: [fw-mvc] Generated urls to map to controllers and actions
>
> Hi,
>
> I'm searching for a correct solution for a routing problem
> I'm struggling with for quite a while now, but I can't
> extract the answer out of the Zend_Controller_Router manual page.
>
> Our system produces friendly url's lik this:
> - language/catagory/category/product
> - language/catagory
> - language/category/product/article
> - language/section/page/subpage
> - etc...
>
> This can be quite long/deep (the customer organizes its
> tree), but I can map a controller/action/id/etc... to every url.
>
> I've tried to subclass the router, but that overrides the
> complete routing section.
>
> I want to be able to check for a record in my mapping table
> (url to controller/etc...), but pass the request to a next
> route (with translated segments and the 'normal' route e.g.)
> when no mapping could be done.
>
> The nicest thing would be if I could use assemble() to create
> a url base don the mapping table.
>
> Do I need a router, or a route and how would I get started?
>
> Thanks in advance!
>
> Regards,
> Jachim Coudenys
>

Re: [fw-mvc] Dojo view helpers don't automatically "dojoRequire" their respective dijits

As you can see, I didn't fully understand what was happening. At some
point I was thinking how odd it was that the view helpers could be
used in the layout AFTER $view->dojo() had been echo'd, and still
properly require the necessary dijits at a later point in time. The
answer is, of course, they can't. Unless...you use an instance of
Zend_TimeTravel. Ah, but how would you code around the ensuing
paradoxes? ;)

Thanks for showing me how to use the helpers with the layout and
achieve the functionality I was looking for. As always, much
appreciated.

--regards,
Nathan Garlington

On Fri, Feb 26, 2010 at 6:16 AM, Matthew Weier O'Phinney
<matthew@zend.com> wrote:
> -- Nathan Garlington <garlinto@gmail.com> wrote
> (on Thursday, 25 February 2010, 02:58 PM -0700):
>> V1.10.1
>>
>> I have been refactoring my layouts and views to use the dojo view
>> helpers, thinking that the helpers auto-required their respective
>> dijits ala Zend_Dojo_Form, and quickly found out that this is not the
>> case. Am I missing a step in configuring the view (other than
>> dojoRequire-ing the dijits myself) that will enable this
>> functionality, or is this a functionality that doesn't exist atm?
>
> The functionality does exist (has since it was initially released), and
> it does create the necessary dojo.require statements.
>
> Please be aware, though, that if you are adding dijits to your _layout_,
> you will need to be careful about the order in which you do so. Any
> dijits created _after_ the dojo view helper has been echoed will not be
> present.
>
> As an example:
>
>    <html>
>    <head>
>        <?php echo $this->dojo() ?>
>    </head>
>    <body>
>        <?php $this->tabContainer()->captureStart('tabs') ?>
>            <?php $this->contentPane()->captureStart('main') ?>
>            <?php echo $this->layout()->content ?>
>            <?php echo $this->contentPane()->captureEnd('main') ?>
>        <?php echo $this->tabContainer()->captureEnd('tabs') ?>
>    </body>
>    </html>
>
> In the above, the tab container and content pane should be aggregating
> dojo.require statements for dijit.layout.TabContainer and
> dijit.layout.ContentPane, respectively -- but since the dojo() view
> helper was rendered _earlier_ in the script, they will not have been
> aggregated yet when that happens.
>
> The solution to this is to move these calls into another view script,
> capture that content early in your layoute, and then echo it later.
>
>  content.phtml:
>    <?php $this->tabContainer()->captureStart('tabs') ?>
>        <?php $this->contentPane()->captureStart('main') ?>
>        <?php echo $this->layout()->content ?>
>        <?php echo $this->contentPane()->captureEnd('main') ?>
>    <?php echo $this->tabContainer()->captureEnd('tabs') ?>
>
>  layout.phtml:
>    <?php $content = $this->render('content.phtml') ?>
>    <html>
>    <head>
>        <?php echo $this->dojo() ?>
>    </head>
>    <body>
>        <?php echo $content ?>
>    </body>
>    </html>
>
> --
> Matthew Weier O'Phinney
> Project Lead            | matthew@zend.com
> Zend Framework          | http://framework.zend.com/
> PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
>

Re: [fw-webservices] return a soap fault

On 26 February 2010 13:23, Richard Quadling <rquadling@googlemail.com> wrote:
> On 26 February 2010 11:56, Mark Hage <m.c.hage@gmail.com> wrote:
>> Hi,
>>
>> I want to do some validation on the client in my soap server, before the
>> zend_soap_server is actually loaded.
>> I wrote it like this:
>>
>> $validatorObj = new Myclass_Validator();
>> if ($validatorObj->isValid($this->getRequest())===false){
>>    if (isset($_GET['wsdl'])){
>>          //return an empty wdl
>>          $this->handleWSDL('Service_Empty');
>>     } else {
>>          $server = new Zend_Soap_Server();
>>          $server->fault('not valid');
>>     }
>> } else {
>>     //valide
>>     if(isset($_GET['wsdl'])) {
>>          //return the WSDL
>>           $this->handleWSDL('Service_Functions');
>>      } else {
>>            //handle SOAP request
>>            $this->handleSOAP('Service_Functions');
>>       }
>> }
>>
>>
>> The problem is that I don't get the soap fault 'not valid'. How should I do
>> this?
>>
>> Thanks,
>> Mark
>>
>>
>
> I would do the validation in the soap served class (the class you
> supply to the SOAP server by using the setClass() method).
>
> I have this sort of process to allow users to supply data (or ask for
> a WSDL file or the HTML documentation).
>
> When they supply data, the method called does the validation and
> throws normal exceptions. My exceptions generate an email and are
> restricted to only send 1 email for a particular exception per day.
> The email contains a full stack trace and indicators of how many times
> the exception has been thrown since I last examined the code.
>
> By registering the exceptions with the soap server class (
> registerFaultException($Exceptions) ), I can get SOAP faults back to
> the client.
>
> I'm new to Zend and I'm currently only using Zend_Soap (Client,
> Server, WSDL, AutoDiscover), but it seems to be working really well
> for me.
>
> Does that make sense?
>
> Regards,
>
> Richard.
>
> --
> -----
> Richard Quadling
> "Standing on the shoulders of some very clever giants!"
> EE : http://www.experts-exchange.com/M_248814.html
> EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> ZOPA : http://uk.zopa.com/member/RQuadling
>

When you create the new Zend_Soap_Server, make sure you enable
'exeption' in the options.

--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

Re: [fw-webservices] return a soap fault

On 26 February 2010 11:56, Mark Hage <m.c.hage@gmail.com> wrote:
> Hi,
>
> I want to do some validation on the client in my soap server, before the
> zend_soap_server is actually loaded.
> I wrote it like this:
>
> $validatorObj = new Myclass_Validator();
> if ($validatorObj->isValid($this->getRequest())===false){
>    if (isset($_GET['wsdl'])){
>          //return an empty wdl
>          $this->handleWSDL('Service_Empty');
>     } else {
>          $server = new Zend_Soap_Server();
>          $server->fault('not valid');
>     }
> } else {
>     //valide
>     if(isset($_GET['wsdl'])) {
>          //return the WSDL
>           $this->handleWSDL('Service_Functions');
>      } else {
>            //handle SOAP request
>            $this->handleSOAP('Service_Functions');
>       }
> }
>
>
> The problem is that I don't get the soap fault 'not valid'. How should I do
> this?
>
> Thanks,
> Mark
>
>

I would do the validation in the soap served class (the class you
supply to the SOAP server by using the setClass() method).

I have this sort of process to allow users to supply data (or ask for
a WSDL file or the HTML documentation).

When they supply data, the method called does the validation and
throws normal exceptions. My exceptions generate an email and are
restricted to only send 1 email for a particular exception per day.
The email contains a full stack trace and indicators of how many times
the exception has been thrown since I last examined the code.

By registering the exceptions with the soap server class (
registerFaultException($Exceptions) ), I can get SOAP faults back to
the client.

I'm new to Zend and I'm currently only using Zend_Soap (Client,
Server, WSDL, AutoDiscover), but it seems to be working really well
for me.

Does that make sense?

Regards,

Richard.

--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

Re: [fw-mvc] Dojo view helpers don't automatically "dojoRequire" their respective dijits

-- Nathan Garlington <garlinto@gmail.com> wrote
(on Thursday, 25 February 2010, 02:58 PM -0700):
> V1.10.1
>
> I have been refactoring my layouts and views to use the dojo view
> helpers, thinking that the helpers auto-required their respective
> dijits ala Zend_Dojo_Form, and quickly found out that this is not the
> case. Am I missing a step in configuring the view (other than
> dojoRequire-ing the dijits myself) that will enable this
> functionality, or is this a functionality that doesn't exist atm?

The functionality does exist (has since it was initially released), and
it does create the necessary dojo.require statements.

Please be aware, though, that if you are adding dijits to your _layout_,
you will need to be careful about the order in which you do so. Any
dijits created _after_ the dojo view helper has been echoed will not be
present.

As an example:

<html>
<head>
<?php echo $this->dojo() ?>
</head>
<body>
<?php $this->tabContainer()->captureStart('tabs') ?>
<?php $this->contentPane()->captureStart('main') ?>
<?php echo $this->layout()->content ?>
<?php echo $this->contentPane()->captureEnd('main') ?>
<?php echo $this->tabContainer()->captureEnd('tabs') ?>
</body>
</html>

In the above, the tab container and content pane should be aggregating
dojo.require statements for dijit.layout.TabContainer and
dijit.layout.ContentPane, respectively -- but since the dojo() view
helper was rendered _earlier_ in the script, they will not have been
aggregated yet when that happens.

The solution to this is to move these calls into another view script,
capture that content early in your layoute, and then echo it later.

content.phtml:
<?php $this->tabContainer()->captureStart('tabs') ?>
<?php $this->contentPane()->captureStart('main') ?>
<?php echo $this->layout()->content ?>
<?php echo $this->contentPane()->captureEnd('main') ?>
<?php echo $this->tabContainer()->captureEnd('tabs') ?>

layout.phtml:
<?php $content = $this->render('content.phtml') ?>
<html>
<head>
<?php echo $this->dojo() ?>
</head>
<body>
<?php echo $content ?>
</body>
</html>

--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

[fw-webservices] return a soap fault

Hi,

I want to do some validation on the client in my soap server, before the zend_soap_server is actually loaded.
I wrote it like this:

$validatorObj = new Myclass_Validator();
if ($validatorObj->isValid($this->getRequest())===false){
   if (isset($_GET['wsdl'])){
         //return an empty wdl
         $this->handleWSDL('Service_Empty');
    } else {
         $server = new Zend_Soap_Server();
         $server->fault('not valid');
    }
} else {
    //valide
    if(isset($_GET['wsdl'])) {
         //return the WSDL
          $this->handleWSDL('Service_Functions');
     } else {
           //handle SOAP request
           $this->handleSOAP('Service_Functions');
      }
}


The problem is that I don't get the soap fault 'not valid'. How should I do this?

Thanks,
Mark
 

2010年2月25日星期四

[fw-mvc] Generated urls to map to controllers and actions

Hi,

I'm searching for a correct solution for a routing problem I'm struggling with for quite a while now, but I can't extract the answer out of the Zend_Controller_Router manual page.

Our system produces friendly url's lik this:
- language/catagory/category/product
- language/catagory
- language/category/product/article
- language/section/page/subpage
- etc...

This can be quite long/deep (the customer organizes its tree), but I can map a controller/action/id/etc... to every url.

I've tried to subclass the router, but that overrides the complete routing section.

I want to be able to check for a record in my mapping table (url to controller/etc...), but pass the request to a next route (with translated segments and the 'normal' route e.g.) when no mapping could be done.

The nicest thing would be if I could use assemble() to create a url base don the mapping table.

Do I need a router, or a route and how would I get started?

Thanks in advance!

Regards,
Jachim Coudenys

[fw-mvc] RE: Autodetected baseUrl not available in bootstrap?

Hi Matthew,
 
I added this resource method to my bootstrap:
 
protected function _initBaseUrl() {
        $this->bootstrap("frontController");
        $front=$this->getResource("frontController");
        $request=new Zend_Controller_Request_Http();
        $front->setRequest($request);
}

and now I have autodetected baseUrl available in the bootstrap methods. Thanks for your help!

David


________________________________

From: weierophinney [via Zend Framework Community] [mailto:[hidden email]]
Sent: Thursday, February 25, 2010 8:37 PM
To: David Lukáš
Subject: Re: Autodetected baseUrl not available in bootstrap?


-- Andy Daykin <[hidden email] <http://n4.nabble.com/user/SendEmail.jtp?type=node&node=1569563&i=0> > wrote
(on Thursday, 25 February 2010, 10:23 AM -0600):
> I'm having a similar problem. I'm trying to get the base url in the controller
> methods, by using:
>  
>
> Zend_Controller_Front::getInstance()->getBaseUrl();
>
> But nothing gets returned from that method. How should I get the baseUrl in a
> controller (or bootstrap for another matter - didn't mean to hijack your thread
> David).

At that point, the request is not yet initialized, and
Zend_Controller_Front::getRequest() does not lazy-load one. The simplest
way would be to simply do this:

    $request = new Zend_Controller_Request_Http();
    $front->setRequest($request);

Once you've done this, the baseUrl() view helper will have access to a
valid request object, which will give you a valid base URL.



> From: Hector Virgen
> Sent: Thursday, February 25, 2010 10:20 AM
> To: David Lukas
> Cc: [hidden email] <http://n4.nabble.com/user/SendEmail.jtp?type=node&node=1569563&i=1>  
> Subject: Re: [fw-mvc] Autodetected baseUrl not available in bootstrap?
>
> I may be wrong but I believe the baseUrl is detected during the dispatching
> process, which is after all of the resources have been loaded.
>
> Are you using a layout? It would be easier to add your common CSS/JS to the
> layout script. Within the layout $this->baseUrl() should be working properly.
>
> --
> Hector
>
>
> On Wed, Feb 24, 2010 at 11:47 PM, David Lukas <[hidden email] <http://n4.nabble.com/user/SendEmail.jtp?type=node&node=1569563&i=2> > wrote:
>
>
>     Hi,
>     I am intializing view placeholders in a bootstrap resource method like
>     this:
>
>     protected function _initViewPlaceholders() {
>       $this->bootstrap("frontController");
>       $front=$this->getResource("frontController");
>       $this->bootstrap('view');
>       $view = $this->getResource('view');
>
>     $view->headLink()->appendStylesheet($view->baseUrl("path/to/
>     stylesheet.css"));
>       $view->headScript()->appendFile($view->baseUrl("path/to/script.js"));
>     }
>
>     But the method does not work as expected - the style and script links have
>     no baseUrl prepended. When called from this method, $view->baseUrl() as
>     well
>     as  $front->getBaseUrl() return "/", although when called from an action
>     controller they return correctly autodetected baseUrl.
>
>     When I manually specify baseUrl in the config file:
>
>     resources.frontController.baseUrl = "/baseUrl"
>
>     the resource method works fine and files are linked correctly.
>
>     Which resource is responsible for injecting the autodetected baseUrl into
>     the front controller? Or am I missing the point completely? If yes, what is
>     the best practice for getting hold of the autodetected baseUrl in a
>     bootstrap resource method?
>
>     Thanks for any help,
>     David
>
>     ZF 1.10.1
>     --
>     View this message in context: http://n4.nabble.com/
>     Autodetected-baseUrl-not-available-in-bootstrap-tp1568601p1568601.html
>     Sent from the Zend MVC mailing list archive at Nabble.com.
>
>
>

--
Matthew Weier O'Phinney
Project Lead            | [hidden email] <http://n4.nabble.com/user/SendEmail.jtp?type=node&node=1569563&i=3>  
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc



________________________________

View message @ http://n4.nabble.com/Autodetected-baseUrl-not-available-in-bootstrap-tp1568601p1569563.html 
To start a new topic under Zend MVC, email [hidden email]
To unsubscribe from Zend MVC, click here <<Link Removed>> .



View this message in context: RE: Autodetected baseUrl not available in bootstrap?
Sent from the Zend MVC mailing list archive at Nabble.com.

Re: [fw-mvc] Autodetected baseUrl not available in bootstrap?

thanks  Matthew




On Thu, Feb 25, 2010 at 11:06 PM, Matthew Weier O'Phinney <matthew@zend.com> wrote:
-- Andy Daykin <daykinandy@gmail.com> wrote
(on Thursday, 25 February 2010, 10:23 AM -0600):
> I'm having a similar problem. I'm trying to get the base url in the controller
> methods, by using:
>
>
> Zend_Controller_Front::getInstance()->getBaseUrl();
>
> But nothing gets returned from that method. How should I get the baseUrl in a
> controller (or bootstrap for another matter - didn't mean to hijack your thread
> David).

At that point, the request is not yet initialized, and
Zend_Controller_Front::getRequest() does not lazy-load one. The simplest
way would be to simply do this:

   $request = new Zend_Controller_Request_Http();
   $front->setRequest($request);

Once you've done this, the baseUrl() view helper will have access to a
valid request object, which will give you a valid base URL.


> From: Hector Virgen
> Sent: Thursday, February 25, 2010 10:20 AM
> To: David Lukas
> Cc: fw-mvc@lists.zend.com
> Subject: Re: [fw-mvc] Autodetected baseUrl not available in bootstrap?
>
> I may be wrong but I believe the baseUrl is detected during the dispatching
> process, which is after all of the resources have been loaded.
>
> Are you using a layout? It would be easier to add your common CSS/JS to the
> layout script. Within the layout $this->baseUrl() should be working properly.
>
> --
> Hector
>
>
> On Wed, Feb 24, 2010 at 11:47 PM, David Lukas <david.lukas@langfor.cz> wrote:
>
>
>     Hi,
>     I am intializing view placeholders in a bootstrap resource method like
>     this:
>
>     protected function _initViewPlaceholders() {
>       $this->bootstrap("frontController");
>       $front=$this->getResource("frontController");
>       $this->bootstrap('view');
>       $view = $this->getResource('view');
>
>     $view->headLink()->appendStylesheet($view->baseUrl("path/to/
>     stylesheet.css"));
>       $view->headScript()->appendFile($view->baseUrl("path/to/script.js"));
>     }
>
>     But the method does not work as expected - the style and script links have
>     no baseUrl prepended. When called from this method, $view->baseUrl() as
>     well
>     as  $front->getBaseUrl() return "/", although when called from an action
>     controller they return correctly autodetected baseUrl.
>
>     When I manually specify baseUrl in the config file:
>
>     resources.frontController.baseUrl = "/baseUrl"
>
>     the resource method works fine and files are linked correctly.
>
>     Which resource is responsible for injecting the autodetected baseUrl into
>     the front controller? Or am I missing the point completely? If yes, what is
>     the best practice for getting hold of the autodetected baseUrl in a
>     bootstrap resource method?
>
>     Thanks for any help,
>     David
>
>     ZF 1.10.1
>     --
>     View this message in context: http://n4.nabble.com/
>     Autodetected-baseUrl-not-available-in-bootstrap-tp1568601p1568601.html
>     Sent from the Zend MVC mailing list archive at Nabble.com.
>
>
>

--
Matthew Weier O'Phinney
Project Lead            | matthew@zend.com
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc




--
________________
Sincerely
Sina Miandashti
MuSicBasE.ir & InvisionPower.ir Admin

[fw-mvc] Dojo view helpers don't automatically "dojoRequire" their respective dijits

V1.10.1

I have been refactoring my layouts and views to use the dojo view
helpers, thinking that the helpers auto-required their respective
dijits ala Zend_Dojo_Form, and quickly found out that this is not the
case. Am I missing a step in configuring the view (other than
dojoRequire-ing the dijits myself) that will enable this
functionality, or is this a functionality that doesn't exist atm?

--regards,
Nathan Garlington

Re: [fw-mvc] Autodetected baseUrl not available in bootstrap?

-- Andy Daykin <daykinandy@gmail.com> wrote
(on Thursday, 25 February 2010, 10:23 AM -0600):
> I'm having a similar problem. I'm trying to get the base url in the controller
> methods, by using:
>
>
> Zend_Controller_Front::getInstance()->getBaseUrl();
>
> But nothing gets returned from that method. How should I get the baseUrl in a
> controller (or bootstrap for another matter - didn't mean to hijack your thread
> David).

At that point, the request is not yet initialized, and
Zend_Controller_Front::getRequest() does not lazy-load one. The simplest
way would be to simply do this:

$request = new Zend_Controller_Request_Http();
$front->setRequest($request);

Once you've done this, the baseUrl() view helper will have access to a
valid request object, which will give you a valid base URL.


> From: Hector Virgen
> Sent: Thursday, February 25, 2010 10:20 AM
> To: David Lukas
> Cc: fw-mvc@lists.zend.com
> Subject: Re: [fw-mvc] Autodetected baseUrl not available in bootstrap?
>
> I may be wrong but I believe the baseUrl is detected during the dispatching
> process, which is after all of the resources have been loaded.
>
> Are you using a layout? It would be easier to add your common CSS/JS to the
> layout script. Within the layout $this->baseUrl() should be working properly.
>
> --
> Hector
>
>
> On Wed, Feb 24, 2010 at 11:47 PM, David Lukas <david.lukas@langfor.cz> wrote:
>
>
> Hi,
> I am intializing view placeholders in a bootstrap resource method like
> this:
>
> protected function _initViewPlaceholders() {
> $this->bootstrap("frontController");
> $front=$this->getResource("frontController");
> $this->bootstrap('view');
> $view = $this->getResource('view');
>
> $view->headLink()->appendStylesheet($view->baseUrl("path/to/
> stylesheet.css"));
> $view->headScript()->appendFile($view->baseUrl("path/to/script.js"));
> }
>
> But the method does not work as expected - the style and script links have
> no baseUrl prepended. When called from this method, $view->baseUrl() as
> well
> as $front->getBaseUrl() return "/", although when called from an action
> controller they return correctly autodetected baseUrl.
>
> When I manually specify baseUrl in the config file:
>
> resources.frontController.baseUrl = "/baseUrl"
>
> the resource method works fine and files are linked correctly.
>
> Which resource is responsible for injecting the autodetected baseUrl into
> the front controller? Or am I missing the point completely? If yes, what is
> the best practice for getting hold of the autodetected baseUrl in a
> bootstrap resource method?
>
> Thanks for any help,
> David
>
> ZF 1.10.1
> --
> View this message in context: http://n4.nabble.com/
> Autodetected-baseUrl-not-available-in-bootstrap-tp1568601p1568601.html
> Sent from the Zend MVC mailing list archive at Nabble.com.
>
>
>

--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

Re: [fw-db] Parsing through large result sets

There is a $db->query() method, which returns a resource-like class, on
which you can perform $res->fetch()

Regards,

Pieter Kokx
PHP Developer
Zend Framework developer

janpolsen schreef:
> Oi
>
> Now I have googled through various search queries for the last two
> hours and I'm about to toss the towel.
>
> I am used to do something like this:
> $sql = "SELECT something FROM random-table-with-an-obscene-large-amount-of-entries";
> $res = mssql_query($sql);
> while ($row = mssql_fetch_array($res)) {
> // do some with the data returned in $row
> }
>
> Now I have moved over to Zend_Db and want to do the very same thing,
> but how?
> Some places I use a simple straight through approach like:
> $sql = "SELECT something FROM random-table-with-a-small-amount-of-data";
> $rows = $db->fetchAll($sql);
> foreach ($rows AS $row) {
> // do some with the data returned in $row
> }
>
> However I run into memory problems, if I use that approach with my
> |random-table-with-an-obscene-large-amount-of-entries|.
>
> What am I missing here? Isn't it possible to use a |while()-structure|
> to loop through a Zend_Db result set? Thanks in advance...
> ------------------------------------------------------------------------
> View this message in context: Parsing through large result sets
> <http://www.nabble.com/Parsing-through-large-result-sets-tp20264357p20264357.html>
> Sent from the Zend DB mailing list archive
> <http://www.nabble.com/Zend-DB-f16192.html> at Nabble.com.

Re: [fw-db] Parameter Binding and SQL injection

It is safe.

--
Regards,
Vladas Diržys


On Thu, Feb 25, 2010 at 19:18, Andy Daykin <daykinandy@gmail.com> wrote:
Hello, I was wondering if doing parameter binding is enough to make me safe against SQL injection when I make db queries:
 
$db->query("INSERT INTO addresses(name, email, address, city , state, zip) VALUES(?,?,?,?,?,?)", array($name, $email, $address, $city, $state, $zip));
 
If not, do I have to do something else to be safe against SQL injection?
 
-Andy
 
 
 

[fw-db] Parameter Binding and SQL injection

Hello, I was wondering if doing parameter binding is enough to make me safe against SQL injection when I make db queries:
 
$db->query("INSERT INTO addresses(name, email, address, city , state, zip) VALUES(?,?,?,?,?,?)", array($name, $email, $address, $city, $state, $zip));
 
If not, do I have to do something else to be safe against SQL injection?
 
-Andy
 
 
 

Re: [fw-mvc] Autodetected baseUrl not available in bootstrap?

I'm having a similar problem. I'm trying to get the base url in the controller methods, by using:
 

Zend_Controller_Front::getInstance()->getBaseUrl();

But nothing gets returned from that method. How should I get the baseUrl in a controller (or bootstrap for another matter - didn't mean to hijack your thread David).

 

-Andy Daykin


Sent: Thursday, February 25, 2010 10:20 AM
Subject: Re: [fw-mvc] Autodetected baseUrl not available in bootstrap?

I may be wrong but I believe the baseUrl is detected during the dispatching process, which is after all of the resources have been loaded.

Are you using a layout? It would be easier to add your common CSS/JS to the layout script. Within the layout $this->baseUrl() should be working properly.

--
Hector


On Wed, Feb 24, 2010 at 11:47 PM, David Lukas <david.lukas@langfor.cz> wrote:

Hi,
I am intializing view placeholders in a bootstrap resource method like this:

protected function _initViewPlaceholders() {
  $this->bootstrap("frontController");
  $front=$this->getResource("frontController");
  $this->bootstrap('view');
  $view = $this->getResource('view');

$view->headLink()->appendStylesheet($view->baseUrl("path/to/stylesheet.css"));
  $view->headScript()->appendFile($view->baseUrl("path/to/script.js"));
}

But the method does not work as expected - the style and script links have
no baseUrl prepended. When called from this method, $view->baseUrl() as well
as  $front->getBaseUrl() return "/", although when called from an action
controller they return correctly autodetected baseUrl.

When I manually specify baseUrl in the config file:

resources.frontController.baseUrl = "/baseUrl"

the resource method works fine and files are linked correctly.

Which resource is responsible for injecting the autodetected baseUrl into
the front controller? Or am I missing the point completely? If yes, what is
the best practice for getting hold of the autodetected baseUrl in a
bootstrap resource method?

Thanks for any help,
David

ZF 1.10.1
--
View this message in context: http://n4.nabble.com/Autodetected-baseUrl-not-available-in-bootstrap-tp1568601p1568601.html
Sent from the Zend MVC mailing list archive at Nabble.com.


Re: [fw-mvc] Autodetected baseUrl not available in bootstrap?

I may be wrong but I believe the baseUrl is detected during the dispatching process, which is after all of the resources have been loaded.

Are you using a layout? It would be easier to add your common CSS/JS to the layout script. Within the layout $this->baseUrl() should be working properly.

--
Hector


On Wed, Feb 24, 2010 at 11:47 PM, David Lukas <david.lukas@langfor.cz> wrote:

Hi,
I am intializing view placeholders in a bootstrap resource method like this:

protected function _initViewPlaceholders() {
  $this->bootstrap("frontController");
  $front=$this->getResource("frontController");
  $this->bootstrap('view');
  $view = $this->getResource('view');

$view->headLink()->appendStylesheet($view->baseUrl("path/to/stylesheet.css"));
  $view->headScript()->appendFile($view->baseUrl("path/to/script.js"));
}

But the method does not work as expected - the style and script links have
no baseUrl prepended. When called from this method, $view->baseUrl() as well
as  $front->getBaseUrl() return "/", although when called from an action
controller they return correctly autodetected baseUrl.

When I manually specify baseUrl in the config file:

resources.frontController.baseUrl = "/baseUrl"

the resource method works fine and files are linked correctly.

Which resource is responsible for injecting the autodetected baseUrl into
the front controller? Or am I missing the point completely? If yes, what is
the best practice for getting hold of the autodetected baseUrl in a
bootstrap resource method?

Thanks for any help,
David

ZF 1.10.1
--
View this message in context: http://n4.nabble.com/Autodetected-baseUrl-not-available-in-bootstrap-tp1568601p1568601.html
Sent from the Zend MVC mailing list archive at Nabble.com.


2010年2月24日星期三

[fw-mvc] Autodetected baseUrl not available in bootstrap?

Hi,
I am intializing view placeholders in a bootstrap resource method like this:

protected function _initViewPlaceholders() {
$this->bootstrap("frontController");
$front=$this->getResource("frontController");
$this->bootstrap('view');
$view = $this->getResource('view');

$view->headLink()->appendStylesheet($view->baseUrl("path/to/stylesheet.css"));
$view->headScript()->appendFile($view->baseUrl("path/to/script.js"));
}

But the method does not work as expected - the style and script links have
no baseUrl prepended. When called from this method, $view->baseUrl() as well
as $front->getBaseUrl() return "/", although when called from an action
controller they return correctly autodetected baseUrl.

When I manually specify baseUrl in the config file:

resources.frontController.baseUrl = "/baseUrl"

the resource method works fine and files are linked correctly.

Which resource is responsible for injecting the autodetected baseUrl into
the front controller? Or am I missing the point completely? If yes, what is
the best practice for getting hold of the autodetected baseUrl in a
bootstrap resource method?

Thanks for any help,
David

ZF 1.10.1
--
View this message in context: http://n4.nabble.com/Autodetected-baseUrl-not-available-in-bootstrap-tp1568601p1568601.html
Sent from the Zend MVC mailing list archive at Nabble.com.

Re: [fw-mvc] cant get Fire Php working and more

Hi,

On 24 February 2010 23:13, Jigal sanders <jigalroecha@gmail.com> wrote:
> This doesn't help me.
>
> This messae: $logger->log('This is a log message!', Zend_Log::INFO); doesn't
> appear in my firePHP.
>
> any idea's?

The most common reason I see at work for FirePHP not working, is that
Firebug Net Panel is not activated.
With the net panel disabled, FirePHP does not work.

Hope that helps...

Stefan

Re: [fw-mvc] cant get Fire Php working and more

This doesn't help me.

This messae: $logger->log('This is a log message!', Zend_Log::INFO); doesn't appear in my firePHP.

any idea's?


2010/2/24 Shaun Farrell <farrelley@gmail.com>
You can just throw this into your config.ini

resources.db.params.profiler.enabled = true
resources.db.params.profiler.class = Zend_Db_Profiler_Firebug

Shaun Farrell
Washington, DC
www.farleyhills.com



On Wed, Feb 24, 2010 at 9:58 AM, Jigal sanders <jigalroecha@gmail.com> wrote:
Hello everyone,

I am trying to get logging through firePhP working. 

Here is my code:

protected function _initLogging(){
$this->bootstrap('frontController');
$logger = new Zend_Log();
$writer = 'production' == $this->getEnvironment() ? new Zend_Log_Writer_Stream(APPLICATION_PATH.'/../data/logs/app.log') : new Zend_Log_Writer_Firebug();
var_dump($this->getEnvironment);
$logger->addWriter($writer);
if('production' == $this->getEnvironment()){
$filter = new Zend_Log_Filter_Priority(Zend_Log::CRIT);
$logger->addFilter($filter);
}
$this->_logger = $logger;
$logger->log('This is a log message!', Zend_Log::INFO);
Zend_Registry::set('log', $logger);
}

I have allowed my site in firePHP .
What's also weird is that getEnvironment() returns null. But in my bootstrap file it says:

defined('APPLICATION_ENV')
or define('APPLICATION_ENV', 'development');


I use zend version 1.10.1

Anyona an idea?

Thanks,

J.sanders





--
Met vriendelijke groet,

Jigal Sanders
A.J. Ernststraat 739
1082 LK Amsterdam
Mobiel: 06-42111489

Re: [fw-mvc] cant get Fire Php working and more

You can just throw this into your config.ini

resources.db.params.profiler.enabled = true
resources.db.params.profiler.class = Zend_Db_Profiler_Firebug

Shaun Farrell
Washington, DC
www.farleyhills.com


On Wed, Feb 24, 2010 at 9:58 AM, Jigal sanders <jigalroecha@gmail.com> wrote:
Hello everyone,

I am trying to get logging through firePhP working. 

Here is my code:

protected function _initLogging(){
$this->bootstrap('frontController');
$logger = new Zend_Log();
$writer = 'production' == $this->getEnvironment() ? new Zend_Log_Writer_Stream(APPLICATION_PATH.'/../data/logs/app.log') : new Zend_Log_Writer_Firebug();
var_dump($this->getEnvironment);
$logger->addWriter($writer);
if('production' == $this->getEnvironment()){
$filter = new Zend_Log_Filter_Priority(Zend_Log::CRIT);
$logger->addFilter($filter);
}
$this->_logger = $logger;
$logger->log('This is a log message!', Zend_Log::INFO);
Zend_Registry::set('log', $logger);
}

I have allowed my site in firePHP .
What's also weird is that getEnvironment() returns null. But in my bootstrap file it says:

defined('APPLICATION_ENV')
or define('APPLICATION_ENV', 'development');


I use zend version 1.10.1

Anyona an idea?

Thanks,

J.sanders


[fw-mvc] cant get Fire Php working and more

Hello everyone,

I am trying to get logging through firePhP working. 

Here is my code:

protected function _initLogging(){
$this->bootstrap('frontController');
$logger = new Zend_Log();
$writer = 'production' == $this->getEnvironment() ? new Zend_Log_Writer_Stream(APPLICATION_PATH.'/../data/logs/app.log') : new Zend_Log_Writer_Firebug();
var_dump($this->getEnvironment);
$logger->addWriter($writer);
if('production' == $this->getEnvironment()){
$filter = new Zend_Log_Filter_Priority(Zend_Log::CRIT);
$logger->addFilter($filter);
}
$this->_logger = $logger;
$logger->log('This is a log message!', Zend_Log::INFO);
Zend_Registry::set('log', $logger);
}

I have allowed my site in firePHP .
What's also weird is that getEnvironment() returns null. But in my bootstrap file it says:

defined('APPLICATION_ENV')
or define('APPLICATION_ENV', 'development');


I use zend version 1.10.1

Anyona an idea?

Thanks,

J.sanders

2010年2月23日星期二

Re: [fw-mvc] Passing parameters to view scripts

-- electrotype <electrotype@gmail.com> wrote
(on Monday, 22 February 2010, 04:14 PM -0800):
>
> I want to be able to pass some parameters to a template I include. For
> example, in a template I would like to include another template,
> 'header.phtml', and telling it to show a logo or not:
>
> ----------------------
> <div id="top">
> <?php
> // doesn't work: no parameters allowed
> $header = $this->render('header.phtml', array('showLogo' => true));

The usage you describe here is what partial() is for. Simply substitute
"partial" for "render":

$header = $this->partial('header.phtml', array('showLogo' => true));

Look up "Zend_View_Helper_Partial" in the manual for more details.

> echo $header;
> ?>
> </div>
> <div>
> some other content
> </div>
>
> ----------------------
>
> The default Zend_View doesn't allow that. I think it's not possible to do
> that with placeholders either. So I coded my own solution, but I want to be
> sure there is not an already existing solution I didn't see!
>
> My solution:
>
> -----------------
> // I use my own view class
> class My_View extends Zend_View
> {
> protected $_renderParameters = array();
> protected function setRenderParameters($renderParameters)
> {
> $this->_renderParameters = $renderParameters;
> }
> protected function addRenderParameters($parameters)
> {
> $this->_renderParameters = array_merge($this->_renderParameters,
> $parameters);
> }
> protected function getRenderParameters()
> {
> return $this->_renderParameters;
> }
>
> public function renderWithParams($fileName, $parameters = array())
> {
> $previousParameters = $this->getRenderParameters();
>
> $this->addRenderParameters($parameters);
>
> // call real render() method
> $content = $this->render($fileName);
>
> // reset parameters
> $this->setRenderParameters($previousParameters);
>
> return $content;
> }
> }
>
> ----------------------
>
> And then I can have a template to include another template with parameters:
>
> ----------------------
> <div id="top">
> <?php
> $header = $this->renderWithParams('header.phtml', array('showLogo'
> => true));
> echo $header;
> ?>
> </div>
> <div>
> some other content
> </div>
>
> ----------------------
>
> And in "header.phtml":
>
> ----------------------
> <?php
> $params = $this->getRenderParameters();
>
> if(isset($params['showLogo']) && $params['showLogo'] === true)
> {
> ?>
> /img/logo.jpg
> <?php
> }
> ?>
> <div>
> some other content
> </div>
>
> ----------------------
>
>
> Did I reinvented the wheel? Is there something I didn't see?
>
> Thanks in advance!
>
>
>
>
>
> --
> View this message in context: http://n4.nabble.com/Passing-parameters-to-view-scripts-tp1565353p1565353.html
> Sent from the Zend MVC mailing list archive at Nabble.com.
>

--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

2010年2月22日星期一

[fw-mvc] Re: Passing parameters to view scripts

Hector Virgen wrote:
>
> Partials are a little more expensive to use than render() because the view
> instance must be cloned. With render, it's basically just an include of
> the
> view script.
>
>

Then my renderWithParams() method is better than both of them! :-P

--
View this message in context: http://n4.nabble.com/Passing-parameters-to-view-scripts-tp1565353p1565386.html
Sent from the Zend MVC mailing list archive at Nabble.com.

Re: [fw-mvc] Re: Passing parameters to view scripts

Partials are a little more expensive to use than render() because the view instance must be cloned. With render, it's basically just an include of the view script.

--
Hector


On Mon, Feb 22, 2010 at 4:51 PM, electrotype <electrotype@gmail.com> wrote:

There is something I still don't get!

Why would I want to ever use the "render()" method?

Isn't "render()" exactly like "partial()" but without the possibility to set
parameters?

When would I want to use "render()"?


--
View this message in context: http://n4.nabble.com/Passing-parameters-to-view-scripts-tp1565353p1565378.html
Sent from the Zend MVC mailing list archive at Nabble.com.


[fw-mvc] Re: Passing parameters to view scripts

There is something I still don't get!

Why would I want to ever use the "render()" method?

Isn't "render()" exactly like "partial()" but without the possibility to set
parameters?

When would I want to use "render()"?


--
View this message in context: http://n4.nabble.com/Passing-parameters-to-view-scripts-tp1565353p1565378.html
Sent from the Zend MVC mailing list archive at Nabble.com.

[fw-mvc] Re: Passing parameters to view scripts

Juozas wrote:
>
> Hi,
>
> you want to use view partials or zend_layout (more in manual).
>
>

Ha! Indeed the Partial Helper seems to be what I was looking for!

Thanks!

--
View this message in context: http://n4.nabble.com/Passing-parameters-to-view-scripts-tp1565353p1565372.html
Sent from the Zend MVC mailing list archive at Nabble.com.

[fw-mvc] Re: Passing parameters to view scripts

Hector Virgen wrote:
>
> When you call $this->render() from within a view script, the existing view
> is re-used. So you should be able to set it like this:
>
> // in view script
> <?php
> $this->showLogo = true;
> $this->render('header.phtml');
>
> // in header.phtml
> <?php if ($this->showLogo): ?>
>
> <?php endif; ?>
>
>

This would work indeed, but I think my solution is better because the added
parameter "showLogo" is persistent in your code. When you are going to
output another view script, your view will still contain "showLogo", and
that may potentially leads to problems, I think.

Hector Virgen wrote:
>
> However, I would suggest using Zend_Layout instead -- it's much better at
> handling layout-specific tasks and it contains it's own view instance,
> allowing you to set view vars like this:
>
> // in view script
> <?php
> $this->layout()->showLogo = true;
>
> // in layout
> <?php if ($this->layout()->showLogo): ?>
>
> <?php endif; ?>
>

I didn't know I could access the layout this way, good to know! But this
doesn't help in all situations, where a regular view script needs to include
another regular view script, having no relation with the global layout...

Thanks for the help!

--
View this message in context: http://n4.nabble.com/Passing-parameters-to-view-scripts-tp1565353p1565369.html
Sent from the Zend MVC mailing list archive at Nabble.com.

Re: [fw-mvc] Passing parameters to view scripts

Hi,

you want to use view partials or zend_layout (more in manual).

For what you are building, zend_layout is a best choice. 

--
Juozas Kaziukėnas (juozas@juokaz.com)
Aš internete - JuoKaz (http://www.juokaz.com)


On Tue, Feb 23, 2010 at 12:14 AM, electrotype <electrotype@gmail.com> wrote:

I want to be able to pass some parameters to a template I include. For
example, in a template I would like to include another template,
'header.phtml', and telling it to show a logo or not:

----------------------
<div id="top">
   <?php
       // doesn't work: no parameters allowed
       $header = $this->render('header.phtml', array('showLogo' => true));
       echo $header;
   ?>
</div>
<div>
   some other content
</div>

----------------------

The default Zend_View doesn't allow that. I think it's not possible to do
that with placeholders either. So I coded my own solution, but I want to be
sure there is not an already existing solution I didn't see!

My solution:

-----------------
// I use my own view class
class My_View extends Zend_View
{
   protected $_renderParameters = array();
   protected function setRenderParameters($renderParameters)
   {
       $this->_renderParameters = $renderParameters;
   }
   protected function addRenderParameters($parameters)
   {
       $this->_renderParameters = array_merge($this->_renderParameters,
$parameters);
   }
   protected function getRenderParameters()
   {
       return $this->_renderParameters;
   }

   public function renderWithParams($fileName, $parameters = array())
   {
       $previousParameters = $this->getRenderParameters();

       $this->addRenderParameters($parameters);

       // call real render() method
       $content = $this->render($fileName);

       // reset parameters
       $this->setRenderParameters($previousParameters);

       return $content;
   }
}

----------------------

And then I can have a template to include another template with parameters:

----------------------
<div id="top">
   <?php
       $header = $this->renderWithParams('header.phtml', array('showLogo'
=> true));
        echo $header;
   ?>
</div>
<div>
   some other content
</div>

----------------------

And in "header.phtml":

----------------------
<?php
$params = $this->getRenderParameters();

if(isset($params['showLogo']) && $params['showLogo'] === true)
{
?>
    /img/logo.jpg
<?php
}
?>
<div>
   some other content
</div>

----------------------


Did I reinvented the wheel? Is there something I didn't see?

Thanks in advance!





--
View this message in context: http://n4.nabble.com/Passing-parameters-to-view-scripts-tp1565353p1565353.html
Sent from the Zend MVC mailing list archive at Nabble.com.


Re: [fw-mvc] Passing parameters to view scripts

When you call $this->render() from within a view script, the existing view is re-used. So you should be able to set it like this:

// in view script
<?php
$this->showLogo = true;
$this->render('header.phtml');

// in header.phtml
<?php if ($this->showLogo): ?>
<img ... />
<?php endif; ?>

However, I would suggest using Zend_Layout instead -- it's much better at handling layout-specific tasks and it contains it's own view instance, allowing you to set view vars like this:

// in view script
<?php
$this->layout()->showLogo = true;

// in layout
<?php if ($this->layout()->showLogo): ?>
<img ... />
<?php endif; ?>

--
Hector


On Mon, Feb 22, 2010 at 4:14 PM, electrotype <electrotype@gmail.com> wrote:

I want to be able to pass some parameters to a template I include. For
example, in a template I would like to include another template,
'header.phtml', and telling it to show a logo or not:

----------------------
<div id="top">
   <?php
       // doesn't work: no parameters allowed
       $header = $this->render('header.phtml', array('showLogo' => true));
       echo $header;
   ?>
</div>
<div>
   some other content
</div>

----------------------

The default Zend_View doesn't allow that. I think it's not possible to do
that with placeholders either. So I coded my own solution, but I want to be
sure there is not an already existing solution I didn't see!

My solution:

-----------------
// I use my own view class
class My_View extends Zend_View
{
   protected $_renderParameters = array();
   protected function setRenderParameters($renderParameters)
   {
       $this->_renderParameters = $renderParameters;
   }
   protected function addRenderParameters($parameters)
   {
       $this->_renderParameters = array_merge($this->_renderParameters,
$parameters);
   }
   protected function getRenderParameters()
   {
       return $this->_renderParameters;
   }

   public function renderWithParams($fileName, $parameters = array())
   {
       $previousParameters = $this->getRenderParameters();

       $this->addRenderParameters($parameters);

       // call real render() method
       $content = $this->render($fileName);

       // reset parameters
       $this->setRenderParameters($previousParameters);

       return $content;
   }
}

----------------------

And then I can have a template to include another template with parameters:

----------------------
<div id="top">
   <?php
       $header = $this->renderWithParams('header.phtml', array('showLogo'
=> true));
        echo $header;
   ?>
</div>
<div>
   some other content
</div>

----------------------

And in "header.phtml":

----------------------
<?php
$params = $this->getRenderParameters();

if(isset($params['showLogo']) && $params['showLogo'] === true)
{
?>
    /img/logo.jpg
<?php
}
?>
<div>
   some other content
</div>

----------------------


Did I reinvented the wheel? Is there something I didn't see?

Thanks in advance!





--
View this message in context: http://n4.nabble.com/Passing-parameters-to-view-scripts-tp1565353p1565353.html
Sent from the Zend MVC mailing list archive at Nabble.com.


[fw-mvc] Passing parameters to view scripts

I want to be able to pass some parameters to a template I include. For
example, in a template I would like to include another template,
'header.phtml', and telling it to show a logo or not:

----------------------
<div id="top">
<?php
// doesn't work: no parameters allowed
$header = $this->render('header.phtml', array('showLogo' => true));
echo $header;
?>
</div>
<div>
some other content
</div>

----------------------

The default Zend_View doesn't allow that. I think it's not possible to do
that with placeholders either. So I coded my own solution, but I want to be
sure there is not an already existing solution I didn't see!

My solution:

-----------------
// I use my own view class
class My_View extends Zend_View
{
protected $_renderParameters = array();
protected function setRenderParameters($renderParameters)
{
$this->_renderParameters = $renderParameters;
}
protected function addRenderParameters($parameters)
{
$this->_renderParameters = array_merge($this->_renderParameters,
$parameters);
}
protected function getRenderParameters()
{
return $this->_renderParameters;
}

public function renderWithParams($fileName, $parameters = array())
{
$previousParameters = $this->getRenderParameters();

$this->addRenderParameters($parameters);

// call real render() method
$content = $this->render($fileName);

// reset parameters
$this->setRenderParameters($previousParameters);

return $content;
}
}

----------------------

And then I can have a template to include another template with parameters:

----------------------
<div id="top">
<?php
$header = $this->renderWithParams('header.phtml', array('showLogo'
=> true));
echo $header;
?>
</div>
<div>
some other content
</div>

----------------------

And in "header.phtml":

----------------------
<?php
$params = $this->getRenderParameters();

if(isset($params['showLogo']) && $params['showLogo'] === true)
{
?>
/img/logo.jpg
<?php
}
?>
<div>
some other content
</div>

----------------------


Did I reinvented the wheel? Is there something I didn't see?

Thanks in advance!

--
View this message in context: http://n4.nabble.com/Passing-parameters-to-view-scripts-tp1565353p1565353.html
Sent from the Zend MVC mailing list archive at Nabble.com.

2010年2月21日星期日

[fw-mvc] Re: Your thoughs on Zend_Form and the fact that they include some presentation logic

I prefer using it as-is!

You are able to use it the way you prefer, but I think you should stick to
the getter functions, e.g. getMethod(), getValue()...
--
View this message in context: http://n4.nabble.com/Your-thoughs-on-Zend-Form-and-the-fact-that-they-include-some-presentation-logic-tp1563896p1564108.html
Sent from the Zend MVC mailing list archive at Nabble.com.

Re: [fw-mvc] Layout will not recognize view data passed to it from controller

Zend_Layout uses a different view instance, so you can't use $this->view->varname to assign to the layout's view. Your method works, but there is a shortcut you can use from within controllers:

// in controller
$this->_helper->layout()->varname = 'var';

In your layout script, you can access the variable like this:

// in layout
echo $this->layout()->varname;

--
Hector


On Sun, Feb 21, 2010 at 12:18 PM, Andy Daykin <daykinandy@gmail.com> wrote:
Hello,
 
I used the batch file to setup my directory structure for the MVC application with version 1.10.1. So I have the same file structure as in the quick start demo on the framework site. In my controller I am trying to send variables to my layout, like so:
 
$this->view->varname = "Var"
 
and then echo them in my layout like:
 
echo $this->varname
 
I am able to get this working in my files in the application/views/scripts/*/*.phtml files, but in my layout which is in application/layouts/layout.phtml, this does not work. In order to get variables to my layout I have to use:
 

Zend_Layout::getMvcInstance()->assign(

'varname', 'Var');

 

How can I access the view data in my layout the same way I am in my view files?

 
In my bootstrap file I have the following:
 

<?php

class

Bootstrap extends Zend_Application_Bootstrap_Bootstrap

{

protected function _initAutoload()

{

$moduleLoader = new Zend_Application_Module_Autoloader(array(

'namespace' => '',

'basePath' => APPLICATION_PATH));

return $moduleLoader;

}

protected function _initViewHelpers()

{

$this->bootstrap('layout');

$layout = $this->getResource('layout');

$view = $layout->getView();

$view->doctype('XHTML1_STRICT');

$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');

$view->headTitle()->setSeparator(' - ');

$view->headTitle('Test');

}

protected function _initDb()

{

$dbResource = $this->getPluginResource("db");

$db = $dbResource->getDbAdapter();

Zend_Registry::set(

"db", $db);

}

}

 

Thanks,

 

-Andy Daykin


[fw-mvc] Re: How to extend Zend_View?

Thanks for the explanation Juozas...
--
View this message in context: http://n4.nabble.com/How-to-extend-Zend-View-tp1563653p1563842.html
Sent from the Zend MVC mailing list archive at Nabble.com.

Re: [fw-mvc] Re: How to extend Zend_View?

Hi,

resources in bootstrap are called once. They can be in form of _initXyz() methods in Bootstarp.php or separate classes. You do not need to add anything to bootstrap() method (usually). You can use bootstrap methods to do things like:

public function _initSomething()
{
   $view = $this->bootstrap('view')->getResource('view');

   $view->test = 'value';
}

First line of this method works like dependency checker - sometimes getResource() is only required to be called as view could be already instantiated, but adding bootstrap() will make sure that it is in fact instantiated. 

So as you can see - by modifying bootstrap() method (or _boostrap()) you kind of naively rely on the fact that it's only going to be called once. As noted above - add your logic to _init methods or separate resources and you'll be fine ;)

--
Juozas Kaziukėnas (juozas@juokaz.com)
Aš internete - JuoKaz (http://www.juokaz.com)


On Sun, Feb 21, 2010 at 9:23 PM, electrotype <electrotype@gmail.com> wrote:

Thanks Juozas, your solution works great indeed!

But can you tell me more about the _bootstrap() method which can be called
more than once during a request?

Where should I place my application initialization stuff, that should be run
only once, if the bootstrap is not the appropriated place?
--
View this message in context: http://n4.nabble.com/How-to-extend-Zend-View-tp1563653p1563828.html
Sent from the Zend MVC mailing list archive at Nabble.com.


[fw-mvc] Re: How to extend Zend_View?

Thanks Juozas, your solution works great indeed!

But can you tell me more about the _bootstrap() method which can be called
more than once during a request?

Where should I place my application initialization stuff, that should be run
only once, if the bootstrap is not the appropriated place?
--
View this message in context: http://n4.nabble.com/How-to-extend-Zend-View-tp1563653p1563828.html
Sent from the Zend MVC mailing list archive at Nabble.com.

Re: [fw-mvc] Re: How to extend Zend_View?

Hi,

_bootstrap() method is used by a method bootstrap(), which is used for boostraping resources manually or for main boostrap. So it might be the case that it gets called once for you, but this is not true for all apps (saying this so you and others do not use it in this fashion)

To add custom pats to resources do this in config (can rename to My namespace if you want):

pluginpaths.App_Application_Resource = "App/Application/Resource"

And then this path will be used before Zend original one, so any resource you add will be used. Hope that helps

--
Juozas Kaziukėnas (juozas@juokaz.com)
Aš internete - JuoKaz (http://www.juokaz.com)


On Sun, Feb 21, 2010 at 8:35 PM, electrotype <electrotype@gmail.com> wrote:

Juozas,

If I'm correct _bootstrap() is called only once... It's the bootstrap's
"constructor"!

But I'm curious about your solution. Where do you use your
App_Application_Resource_View class? How do you tell ZF to use it instead of
the default one?


--
View this message in context: http://n4.nabble.com/How-to-extend-Zend-View-tp1563653p1563790.html
Sent from the Zend MVC mailing list archive at Nabble.com.


[fw-mvc] Re: How to extend Zend_View?

Juozas,

If I'm correct _bootstrap() is called only once... It's the bootstrap's
"constructor"!

But I'm curious about your solution. Where do you use your
App_Application_Resource_View class? How do you tell ZF to use it instead of
the default one?


--
View this message in context: http://n4.nabble.com/How-to-extend-Zend-View-tp1563653p1563790.html
Sent from the Zend MVC mailing list archive at Nabble.com.

Re: [fw-mvc] Re: How to extend Zend_View?

Hi,

this is very wrong way to do it as you basically making your app to create new instances of My_View every single time that method is called. This is not what you need.

You better create your own view resource:

<?php

class App_Application_Resource_View extends Zend_Application_Resource_View
{
    /**
     * Get view
     *
     * @return App_View
     */
    public function getView() {

        if (null === $this->_view) {
            $this->_view = new App_View($this->getOptions());
        }
        return $this->_view;
    }
}

That's it - all configuration is still the same, but you are using custom class now, plus no hacks are required.

--
Juozas Kaziukėnas (juozas@juokaz.com)
Aš internete - JuoKaz (http://www.juokaz.com)


On Sun, Feb 21, 2010 at 8:13 PM, electrotype <electrotype@gmail.com> wrote:

In fact, instead of removing "resources.view[] =", since some view
configurations may be needed sometimes I guess, I override _bootstrap() in
my bootstrap, to be able to set my own view after the ressources are loaded:

------------------------

   protected function _bootstrap($resource = null)
   {
       parent::_bootstrap($resource);

       $viewRenderer =
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
       $view = new My_View();
       $viewRenderer->setView($view);
   }

------------------------

This works great...
--
View this message in context: http://n4.nabble.com/How-to-extend-Zend-View-tp1563653p1563765.html
Sent from the Zend MVC mailing list archive at Nabble.com.


[fw-mvc] Layout will not recognize view data passed to it from controller

Hello,
 
I used the batch file to setup my directory structure for the MVC application with version 1.10.1. So I have the same file structure as in the quick start demo on the framework site. In my controller I am trying to send variables to my layout, like so:
 
$this->view->varname = "Var"
 
and then echo them in my layout like:
 
echo $this->varname
 
I am able to get this working in my files in the application/views/scripts/*/*.phtml files, but in my layout which is in application/layouts/layout.phtml, this does not work. In order to get variables to my layout I have to use:
 

Zend_Layout::getMvcInstance()->assign('varname', 'Var');

 

How can I access the view data in my layout the same way I am in my view files?

 
In my bootstrap file I have the following:
 

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap

{

protected function _initAutoload()

{

$moduleLoader = new Zend_Application_Module_Autoloader(array(

'namespace' => '',

'basePath' => APPLICATION_PATH));

return $moduleLoader;

}

protected function _initViewHelpers()

{

$this->bootstrap('layout');

$layout = $this->getResource('layout');

$view = $layout->getView();

$view->doctype('XHTML1_STRICT');

$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');

$view->headTitle()->setSeparator(' - ');

$view->headTitle('Test');

}

protected function _initDb()

{

$dbResource = $this->getPluginResource("db");

$db = $dbResource->getDbAdapter();

Zend_Registry::set("db", $db);

}

}

 

Thanks,

 

-Andy Daykin