[fw-general] Caching DB relational values....

2010-01-13 Thread Enkhbilguun Erdenetsogt
Hello everyone!

I'm beginning with Zend_Cache. I would like to ask your help on caching DB
relational data in controller and view script.

I called my db model from my controller and assigned it to a view variable.
In order to get a list similar to below, I used _findDependentRowSet in the
view script to use less loops:

Category name
- Column 1
- Names that should be in this column
- Column 2
- Names that should be in this column
- Column 3
..
- Column 7



=
SQL
=
CREATE TABLE IF NOT EXISTS `naadam_serial` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;


CREATE TABLE IF NOT EXISTS `naadam_serial_data` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `naadam_serial_id` int(11) DEFAULT NULL,
  `place` int(11) DEFAULT NULL,
  `azarga` varchar(200) DEFAULT NULL,
  `ih_nas` varchar(200) DEFAULT NULL,
  `soyoolon` varchar(200) DEFAULT NULL,
  `hyazaalan` varchar(200) DEFAULT NULL,
  `shvdlen` varchar(200) DEFAULT NULL,
  `daaga` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `naadam_serial_id` (`naadam_serial_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=24 ;



==
In the Controller
==
$naadams = new BEREGU_Model_NaadamSerial();
$this->view->naadams = $naadams->fetchAll();

==
In the View Script
==
foreach ($this->naadams as $naadam){
$datas = $naadam->findDependentRowset('BEREGU_Model_NaadamSerialData');
$i = 0; //Originally I used html table in my view script. To print the


foreach ($datas as $data){
 if ($i == 0){ //To print column names only once

echo $naadam->name;


Place
if (null != $data->azarga){
Azarga
}

if (null != $data->ih_nas):{
Ih nas
}

if (null != $data->soyoolon){
Soyoolon
}

if (null != $data->hyazaalan){
Hyazaalan
}

if (null != $data->shvdlen){
Shvdlen
}

if (null != $data->daaga){
Daaga
}

$i = 1;
}


place; ?>
azarga; ?>
ih_nas; ?>
soyoolon; ?>
hyazaalan; ?>
shvdlen; ?>
daaga; ?>

}

}


How can I cache both db data? One is called in the controller and the other
one is called in the view script as a dependent. If you have any sample code
or tutorial link, please let me know.



Thank you friends!


---
Enkhbilguun Erdenetsogt


Re: [fw-general] can't access model from default module

2010-01-13 Thread prado

Thanks Mon Zafra, sorry for the late reply. I figured out the next day after
hours of persistence, just a thought came in my mind. Linux servers are
strict on cases whereas my test wampserver on windows lets it pass.

cheers


Mon Zafra wrote:
> 
> Also, check the letter cases in the file name.
> 
>-- Mon
> 
> 
> On Tue, Jan 5, 2010 at 10:58 PM, Victor Farazdagi
> wrote:
> 
>> Hi,
>> Actually it is worth reviewing if include_path on server actually points
>> to
>> model directory base path.
>> Autoloader can not find the class, so can not load it. Seems you have
>> correct include paths on your localbox, while server include path are
>> incomplete.
>>
>> Victor
>>
>>
>> prado wrote:
>>
>>> Hi
>>>
>>> I am accessing a default module controller named kmenu from a blog
>>> module's
>>> layout.phtml file using "$this->layout()->Knav = $this->action('index',
>>> 'kmenu');"
>>>
>>> So the KMenuController is sitting in the Default module that uses
>>> "Kcats"
>>> model from Default as well.
>>>
>>> This works all fine on my test machine which is a wampserver running php
>>> 5.2.9, but I am getting fatal error on the web hosting provider's
>>> production
>>> server also running php 5.2.9
>>>
>>> Below is the error message, not sure if double slashes (//) is causing
>>> the
>>> problem
>>>
>>> --Start Error message--
>>>
>>> Warning:
>>> include(/var/www/vhosts/
>>> zftest.com/httpdocs/system/application/models/DbTable//Kcats.php)
>>> [function.include]: failed to open stream: No such file or directory in
>>> /var/www/vhosts/
>>> zftest.com/httpdocs/system/library/Zend/Loader/Autoloader/Resource.php
>>> on line 176
>>>
>>> Warning: include() [function.include]: Failed opening
>>> '/var/www/vhosts/
>>> zftest.com/httpdocs/system/application/models/DbTable//Kcats.php'
>>> for inclusion
>>> (include_path='/var/www/vhosts/
>>> zftest.com/httpdocs/system/application/../library:/var/www/vhosts/zftest.com/httpdocs/system/library:.::../library
>>> ')
>>> in
>>> /var/www/vhosts/
>>> zftest.com/httpdocs/system/library/Zend/Loader/Autoloader/Resource.php
>>> on line 176
>>>
>>> Fatal error: Class 'Default_Model_DbTable_Kcats' not found in
>>> /var/www/vhosts/
>>> zftest.com/httpdocs/system/application/controllers/KmenuController.php
>>> on line 14
>>>
>>> --End Error message--
>>>
>>> So in nutshell, if I access a Default controller accessing a Default
>>> model
>>> from a named module, I get this error. But works fine on my test machine
>>>
>>> thanks
>>>
>>>
>>
>>
> 
> 

-- 
View this message in context: 
http://n4.nabble.com/can-t-access-model-from-default-module-tp998990p1013532.html
Sent from the Zend Framework mailing list archive at Nabble.com.


[fw-general] Input Parameters as arrays, GET and Zend_Controller_Action_Helper_Redirector::goToRoute

2010-01-13 Thread ryan.horn

I'm having a bit of trouble figuring this one out. I have a controller action
in my application that expects an input parameter to be an array of values.
The form that submits to this page sends the input parameters in the
traditional format of
"http://www.mydomain.com/controller/action?param[]=one¶m[]=two";, etc.

I need to be able to redirect to this page internally using a route, but I
cannot figure out how to pass along the parameter that is an array.

Ex:
$requestParameters = array(
'controller' => 'packages',
'action' => 'create',
'module' => 'packagebuilder',
'items' => array(
'item_1',
'item_2',
'item_3',
 )
);

// $redirector is an instance of Zend_Controller_Action_Helper_Redirector
$redirector->goToRoute(
$requestParameters,
NULL,
TRUE
);

It doesn't look like the routers take into account inputs as arrays when
assembling, as somewhere in the mix, urlencode is passed an array (assuming
it's my parameter array) and it builds it using the Zend Framework MVC
convention of
"http://www.mydomain.com/controller/action/param1/one/param2/two";, etc.

Has anyone solved this issue before or can anyone point me in the right
direction?
-- 
View this message in context: 
http://n4.nabble.com/Input-Parameters-as-arrays-GET-and-Zend-Controller-Action-Helper-Redirector-goToRoute-tp1013430p1013430.html
Sent from the Zend Framework mailing list archive at Nabble.com.


Re: [fw-general] Check if template exists in view script?

2010-01-13 Thread Matthew Weier O'Phinney
-- Carlton Gibson  wrote
(on Wednesday, 13 January 2010, 04:05 PM +):
> On 13 Jan 2010, at 15:36, Marko78 wrote:
> > Is there some way to check if some view script (template file) exists?
> 
> Yes.
> 
> You could use is_readable() in conjunction with Zend_View::getScriptPaths()

Or, simpler, use getScriptPath():

if (!$path = $this->getScriptPath('...')) {
   // NOT FOUND!!!
}

-- 
Matthew Weier O'Phinney
Project Lead| matt...@zend.com
Zend Framework  | http://framework.zend.com/


Re: [fw-general] Check if template exists in view script?

2010-01-13 Thread Carlton Gibson
Hi Marko,

On 13 Jan 2010, at 15:36, Marko78 wrote:
> Is there some way to check if some view script (template file) exists?

Yes.

You could use is_readable() in conjunction with Zend_View::getScriptPaths()

http://uk2.php.net/is_readable

http://framework.zend.com/manual/en/zend.view.html#zend.view.introduction.accessors

HTH
Carlton



[fw-general] Check if template exists in view script?

2010-01-13 Thread Marko78

Hi,

Is there some way to check if some view script (template file) exists?

I would like to do following in my view scripts:

scriptExists("subtype_templates/{$this->type}.phtml"): ?>
render("subtype_templates/{$this->type}.phtml") ?>


here is my default template





br, Marko
-- 
View this message in context: 
http://n4.nabble.com/Check-if-template-exists-in-view-script-tp1013108p1013108.html
Sent from the Zend Framework mailing list archive at Nabble.com.


Re: [fw-general] Doctrine Counter Behavior

2010-01-13 Thread drm

bparise wrote:

Ideally, these could all be under 1 "service" class... this way the "models"
don't have anything defined in them other than the ORM stuff.

ForumService::changeTopic(Post $post, Topic $newTopic)
ForumService::savePost(Post $post)
ForumService::deletePost(Post $post)
ForumService::sendEmailNotifications(Topic $topic)

What are your thoughts about this?  I feel its a bit of redundancy since
most of these methods are only going to be called within 1 place anyways.

I'm not sure if this is the info you wanted, but here goes:

I think you should think about whether your application logic should be 
worried about when and how these things need to be done. I don't really 
think so. The application is only adding a post, whether your model 
decides to precache the postcount per topic is up to the model. So you'd 
use a service layer to tell your model to add a post, and the model 
handles the rest.


In the case of the post count, it makes sense to think about where you'd 
let your application ask the model how many posts a topic has. Would you 
let the service layer, or even the application layer, wonder about where 
to get this info? The answer is no. You simply tell your model "get me 
these topics, and I want to know the post count per topic". So, if the 
application or service layer don't know how to get this info, why should 
they know how to store it in the first place?


One more piece of food-for-thought:
Let's say you didn't precache this info, but used a JOIN with a COUNT() 
whenever you read topics from the database. Now you encounter problems 
with performance and you decide to cache this info. In what part of your 
application would you want to make changes? The obvious hint is that 
we're talking about SQL here.


Also note that Doctrine 1.x's Active Record pattern isn't really a good 
practice for separating business model logic and persistence logic. 
These two are intertwined in such a pattern, and it would (imho) 
actually overcomplicate things trying to separate these more than 
absolutely necessary.


HTH
drm / Gerard


Re: [fw-general] catching exception of db connection error

2010-01-13 Thread Jurian Sluiman
I never thought about catching the Zend_Db_Adapter_Exception, which is much 
better than my idea. Thanks for the idea!
Regards, Jurian

-- 
Jurian Sluiman
CTO Soflomo V.O.F.

http://soflomo.com
On Wednesday 13 Jan 2010 15:25:12 Ralph Schindler wrote:
> I would highly suggest you keep the database connection lazy-loaded if
> you either a) have a few routes that definitely don't do anything with
> the database, or b) you use caching during some routes thus saving the
> trip to the database.
> 
> For sites that might have many requests or a high amount of traffic, it
> makes alot of sense to only connect to the database when you really need
> to so that you don't (for example with mysql), hit the maximum number of
> connections to the database at any one time.  Remember, if you
> automatically open the connection to the database at the beginning of
> every request, it will general remain open for the entire request, and
> every request you get will virtually be another connection open to mysql.
> 
> -ralph
> 
> Hector Virgen wrote:
> > Another solution would be to update your error controller to test the
> > exception to see if it is a Zend_Db_Adapter_Exception. When the
> > connection can't be made, this exception is thrown, but there may be
> > other times when it is thrown (like a bad query).
> > 
> > The advantage, however, is that your DB connection will remain
> > lazy-loaded, so if you're using caching there may be times when you
> > don't need to connect to the DB at all.
> > 
> > --
> > Hector
> > 
> > 
> > On Tue, Jan 12, 2010 at 10:31 AM, Jurian Sluiman
> > 
> > mailto:subscr...@juriansluiman.nl>> wrote:
> > I have this piece of code for my custom db resource, extending the
> > zend db
> > 
> > resource:
> >  > $db = parent::init();
> >  > try {
> >  > 
> >  > $this->_connection = $db->getConnection();
> >  > 
> >  > } catch (Exception $e) {
> >  > 
> >  > $this->getBootstrap()->bootstrap('log');
> >  > Zend_Registry::get('log')->crit('Database connection not
> > 
> > responding');
> > 
> >  > }
> >  > return $db;
> > 
> > Now you're using the zend db resource functionality and test for a
> > valid db
> > connection. The log (already registered in the registry) is used to
> > generate
> > some output.
> > Regards, Jurian
> > 
> > --
> > Jurian Sluiman
> > CTO Soflomo V.O.F.
> > http://soflomo.com
> > 
> > On Tuesday 12 Jan 2010 19:22:39 scs wrote:
> >  > Hello,
> >  > How can I catch the exception and print an error message to
> >  > visitiors when there is a database connection error?
> >  > DB connection params are defined in the application.ini. and db
> >  > resource is initiated in bootstrap file.
> >  > 
> >  > something like this? :
> >  > 
> >  > //function initDatabase () {
> >  > try {
> >  > 
> >  >   $this->bootstrap('db');
> >  >   $db = $this->getResource('db');
> >  >   Zend_Registry::set('db', $db);
> >  > 
> >  > } catch (Exception $e) {
> >  > 
> >  >   echo 'db error '.$e->getMessage();
> >  >   exit; // I have to put exit here in order to prevent other
> >  >   init
> >  > 
> >  > functions running?
> >  > }
> >  > 
> >  > Also,
> >  > I have to put exit(); in catch part in order to prevent the
> >  > following init functions run. Is this the correct way?
> >  > 
> >  > Thanks
> >  > scs


Re: [fw-general] catching exception of db connection error

2010-01-13 Thread Ralph Schindler
I would highly suggest you keep the database connection lazy-loaded if 
you either a) have a few routes that definitely don't do anything with 
the database, or b) you use caching during some routes thus saving the 
trip to the database.


For sites that might have many requests or a high amount of traffic, it 
makes alot of sense to only connect to the database when you really need 
to so that you don't (for example with mysql), hit the maximum number of 
connections to the database at any one time.  Remember, if you 
automatically open the connection to the database at the beginning of 
every request, it will general remain open for the entire request, and 
every request you get will virtually be another connection open to mysql.


-ralph

Hector Virgen wrote:
Another solution would be to update your error controller to test the 
exception to see if it is a Zend_Db_Adapter_Exception. When the 
connection can't be made, this exception is thrown, but there may be 
other times when it is thrown (like a bad query).


The advantage, however, is that your DB connection will remain 
lazy-loaded, so if you're using caching there may be times when you 
don't need to connect to the DB at all.


--
Hector


On Tue, Jan 12, 2010 at 10:31 AM, Jurian Sluiman 
mailto:subscr...@juriansluiman.nl>> wrote:


I have this piece of code for my custom db resource, extending the
zend db
resource:

 > $db = parent::init();
 > try {
 > $this->_connection = $db->getConnection();
 > } catch (Exception $e) {
 > $this->getBootstrap()->bootstrap('log');
 > Zend_Registry::get('log')->crit('Database connection not
responding');
 > }
 > return $db;

Now you're using the zend db resource functionality and test for a
valid db
connection. The log (already registered in the registry) is used to
generate
some output.
Regards, Jurian

--
Jurian Sluiman
CTO Soflomo V.O.F.
http://soflomo.com

On Tuesday 12 Jan 2010 19:22:39 scs wrote:
 > Hello,
 > How can I catch the exception and print an error message to visitiors
 > when there is a database connection error?
 > DB connection params are defined in the application.ini. and db
 > resource is initiated in bootstrap file.
 >
 > something like this? :
 >
 > //function initDatabase () {
 > try {
 >   $this->bootstrap('db');
 >   $db = $this->getResource('db');
 >   Zend_Registry::set('db', $db);
 >
 > } catch (Exception $e) {
 >   echo 'db error '.$e->getMessage();
 >   exit; // I have to put exit here in order to prevent other init
 > functions running?
 > }
 >
 > Also,
 > I have to put exit(); in catch part in order to prevent the following
 > init functions run. Is this the correct way?
 >
 > Thanks
 > scs




Re: [fw-general] Server URL absence in the URL view helper

2010-01-13 Thread Diego Potapczuk
Yeah, i extended both $this->url() and $this->baseUrl to include
serverUrl(), because i have a lot of e-mail messages with links, and i need
the full URL.

There is any advantage in using the partial URL over the full URL?


::: Diego Potapczuk


On Tue, Jan 12, 2010 at 3:02 PM, scs  wrote:

> You can use/add $this->serverUrl(); to print the
> "http://www.server.com"; part of the url.
>
> scs
>
> >
> > On 12 Jan 2010, at 17:29, Diego Potapczuk  wrote:
> >
> > Hi,
> >
> > When i use the $this->url() in the view, it don´t include the server url,
> is
> > this the correct behavior?
> >
> >
> > Example:
> > url(array('module' => 'admin',
> > 'controller' => 'info',
> > 'action' => 'show',
> > 'id' =>
> $this->var['id']),
> > 'default', true);
> > ?>
> > // /admin/info/show/id/4 (what i get)
> >
> > // /http://www.server.com/admin/info/show/id/4 (what i would like to
> get)
> >
> >
> > Thanks
> >
> > ::: Diego Potapczuk
> >
>