[fw-general] How to check the SQL string created by Zend_Db_Select?

2009-02-20 Thread Deepak Shrestha
Hi,

How can we check the SQL string created by select?

for example:

given this
$select-where ( conditions);
$select-orwhere ( conditions);
$select-order ( conditions);


I want to check the complete SQL statement it has created

Zend_Debug::Dump($select) doesn't provide what I wanted to know.

Thanks

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Re: What is the fourth parameter of pagination control?

2009-02-18 Thread Deepak Shrestha
On Tue, Feb 17, 2009 at 2:31 PM, Deepak Shrestha d88...@gmail.com wrote:
 Hi,

 Although related to my previous post on paginator, this is separate
 from what is being discussed before.

 Documentation on Zend_Paginator
 http://framework.zend.com/manual/en/zend.paginator.usage.html (In the
 last para of 36.2.2. Rendering pages with view scripts) suggests that
 it accepts four parameters, where fourth parameter is array of
 additional parameters.

 What can we pass there as an additional parameters? URL encoded data
 like search form data as an array? Where do we retrieve this fourth
 parameter and how? (view partial script of paginator control? how?)

 Probably knowing this will give me hint on how to send Search Form
 Data along with page request in URL.

 Can somebody show me a little example on how to pass search form data
 in URL for subseqent page request using paginator?

 I have used the Paginator for fetching all the records successfully
 since it has no additional paramters except the page request. But for
 the search forms I don't know how to put the form data in URL along
 with the paginator's page request.

 Thanks

 ===
 Registered Linux User #460714
 Currently Using Fedora 8, 10
 ===


Well all these issues have been solved by storing form parameters in session.

Thanks anyway

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Zend_Paginator's totalItemCount property question?

2009-02-18 Thread Deepak Shrestha
Hi all,

When trying to access the totalItemCount property of Paginator, I am
getting this error:
==
Notice: Undefined property: Zend_Paginator::$totalItemCount
==

Is this bug?

Problem elaboration
===
before using paginator, my following view script logic was working perfectly:


? if ($this-myentries): ?
? foreach ($this-myentries as $entry): ?
 //show the entries
? endforeach ?
? else: ?
h1Sorry! There are nothig to display for this search/h1
? endif ?
**

now I am passing paginator to this view script and the problem is
ELSE part is not working anymore even if no entries are fetched.
Result page shows nothing (no message). Instead it hangs my server.

I tried to use the totalItemCount property to check if paginator
really have some items before passing it to view script
OR
I tried to use the totalItemCount in viewscript itself

? if ($this-myentries-totalItemCount !== 0): ?

in both cases, i am getting the error notice.

Any suggestion on this?

What is the correct way to make this logic work again?


Thanks


===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Form values and paginator question

2009-02-16 Thread Deepak Shrestha
2009/2/17 Paweł Chuchmała pawel.chuchm...@gmail.com:
 In mypaginator.phtml, you have something like that:

a href=?= $this-url(array('page' = $page)); ?
?= $page; ?
/a

 You  must cznge parameters for $this-url(). For example:
a href=?= $this-url(array_merge(array('page' = $page),
 $this-dataForPaginatorUrl)); ?
?= $page; ?
/a

 And in controller:
 $this-view-dataForPaginatorUrl = array('searchstr' = $searchstr,
 'adlocation' = $adlocation);

 or something else.

 regards,
 pch

Doing this gives me an Warning like this:
==
 Previous |  1 | Warning: array_merge() [function.array-merge]:
Argument #2 is not an array
=
but i am sure it is array and I have verified that.

Any suggestion?

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] What is the fourth parameter of pagination control?

2009-02-16 Thread Deepak Shrestha
Hi,

Although related to my previous post on paginator, this is separate
from what is being discussed before.

Documentation on Zend_Paginator
http://framework.zend.com/manual/en/zend.paginator.usage.html (In the
last para of 36.2.2. Rendering pages with view scripts) suggests that
it accepts four parameters, where fourth parameter is array of
additional parameters.

What can we pass there as an additional parameters? URL encoded data
like search form data as an array? Where do we retrieve this fourth
parameter and how? (view partial script of paginator control? how?)

Probably knowing this will give me hint on how to send Search Form
Data along with page request in URL.

Can somebody show me a little example on how to pass search form data
in URL for subseqent page request using paginator?

I have used the Paginator for fetching all the records successfully
since it has no additional paramters except the page request. But for
the search forms I don't know how to put the form data in URL along
with the paginator's page request.

Thanks

===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Is parameter value disappears on the way?

2009-02-15 Thread Deepak Shrestha
On Sat, Feb 14, 2009 at 7:14 PM, PHPScriptor cont...@phpscriptor.com wrote:

 Would be nice if you told us what your (stupid :-D) blunder was... In case
 someone has the same problem, he would not have to ask again...

Sorry I forgot about it.

Actually it was really stupid :-)

Basically I have a function in  controller

ShowAllEntries($pg); this calls the FetchAllEntries($page=null) in my model

What really happened is I forgot to pass $pg when calling
FetchAllEntries. I was calling FetchAllEntries() instead of
FetchAllEntires($pg).

Though it was difficult to spot for some time. :-)

Regards!

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Form values and paginator question

2009-02-15 Thread Deepak Shrestha
Hi,

I need some hint on using paginator with search form.

If I have following code in my controller
=
if($request-isPost())
{
  if ($form-isValid($request-getPost()))
  {
$req = $form-getValues();
$pageno = $request-getParam('page');
$this-showRequestedNews($req, $pageno);
  }
}
else
{
//what?
   //where do I get form values here if I were to issue
showRequestedNews() function?
}
===

When I click next in my paginator, it is not a posted request from Form anymore.

so how does the next page is proceesed?

Thanks

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Form values and paginator question

2009-02-15 Thread Deepak Shrestha
On Sun, Feb 15, 2009 at 8:49 PM, PHPScriptor cont...@phpscriptor.com wrote:

 Well there are some sollutions:

 1. put the form values in a session.
 2. put your form values in the url


Got that. :-)

I was thinking other way round. Actually my question should be does
paginator retains the previous query? but anyway I got the answer
already.

thanks

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Form values and paginator question

2009-02-15 Thread Deepak Shrestha
 2. put your form values in the url

but anyway I got the answer already.

Not really

My question is how to modify the view partial script of paginator
control (mypaginator.phtml) so that it will send the form data along
with requested page number

Initially my url is

http://myweb/search/?searchstr=adlocation=Anysubmit=Search

but when next is clicked, url get changed to
http://myweb/search/index/page/2

probably I need the url like this when clicked
http://myweb/search/index/page/2/?searchstr=adlocation=Anysubmit=Search

 I took a look at the properties available for view partial
http://framework.zend.com/manual/en/zend.paginator.usage.html#zend.paginator.usage.rendering.properties
but no clue on how to set this.

Need some hints.

Thanks


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Is parameter value disappears on the way?

2009-02-14 Thread Deepak Shrestha
hi,

Tracing my previous problem on why I cannot paginate with paginator, I
found out that the value I passed from controller to model is not
interpreted properly.

supposing clicking next button in paginator control, i got this url

http://myweb/index/index/page/2

In my  controller

$request = $this-getRequest();
$pgreq = $request-getParam('page');
=

returns the expected value (2 in this case and I have verified this).

but I didn't understand why this values passes as function parameter
is not working inside the model function

so In my model function I have a code like this
==
  public function fetchAllEntries($page=null)
  {
  $table = $this-getTable();
  $select = $table-select()-order('newsdate desc');
  $pgadapter = new Zend_Paginator_Adapter_DbTableSelect($select);
  $paginator = new Zend_Paginator($pgadapter);
  $paginator-setItemCountPerPage(5);
  if ($page == null)
  {
 $paginator-setCurrentPageNumber(1);
  }
  else
  {
 $paginator-setCurrentPageNumber($page);
  }

  return $paginator;
  }

  public function getTable()
  {
  if (null === $this-_table) {
  require_once APPLICATION_PATH . '/models/DbTable/NewsTable.php';
  $this-_table = new Model_DbTable_NewsTable;
  }
  return $this-_table;
  }



the problem lies in
$paginator-setCurrentPageNumber($page);

(This is not working)


If I try to set he page manully like
$paginator-setCurrentPageNumber(3);

It is working



Can somebody tell me where is my blunder mistake?

Thanks


===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Preserving hard return in textarea

2009-02-13 Thread Deepak Shrestha
Hi

How do I preserve the hard return (CR CR/LF) entered in textarea in
zend_form? Currently my filter for textarea is StringTrim and
NotEmpty.

I thought I am getting this because $this-escape is used in my view
script. I tried removing it but I am still getting the same output
(everything in one line).

Thanks

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Another Zend_paginator Question

2009-02-13 Thread Deepak Shrestha
On Fri, Feb 13, 2009 at 2:54 PM, Deepak Shrestha d88...@gmail.com wrote:
 Let me explain a bit so that it will be clear about
 1. what I am trying to do
 2. where I am doing wrong and
 3. where I need to fill up the missing pieces.


 My front page is where all the records are shown so I wanted to use
 the paginator. For the simplicity I want to fetch all the records from
 database and paginate.

 My concept of doing that:
 
 1. IndexController will delegate the work to Model (which have access
 to DBTable)
 2. Model instantiates the Paginator and returns to controller
 3. Controller then assign the paginator to view.
 4. View will loop through the probided paginator to render the records
 plus show paginator control.
 

 Now some code

 My controller:
 ==
public function indexAction()
{
$this-showAllEntries();
}


private function showAllEntries()
{
$newsmodel = $this-_getNewsModel();
$this-view-paginator = $newsmodel-fetchAllEntries();
}

 =

 My Model:
 ==
public function fetchAllEntries()
{
$table = $this-getTable();
$select = $table-select()-order('newsdate desc');
$pgadapter = new Zend_Paginator_Adapter_DbTableSelect($select);
$paginator = new Zend_Paginator($pgadapter);
$paginator-setItemCountPerPage(5);
//$paginator-setCurrentPageNumber(1); //should be dynamic I guess
return $paginator;
}

public function getTable()
{
if (null === $this-_table) {
require_once APPLICATION_PATH . '/models/DbTable/NewsTable.php';
$this-_table = new Model_DbTable_NewsTable;
}
return $this-_table;
}

 

 My index view script and paginator control script is in the same directory
 ===
 views
  scripts
index
  index.phtml
  mypaginator.phtml
 ==


 My view script (index.phtml)
 ==
div id=newslist
? if ($this-paginator ): ?
? foreach ($this-paginator as $entry): ?
div id=ads
ul
li id=adtitle?=
 $this-escape($entry['newstitle']) ?/li
li id=addetails?=
 $this-escape($entry['newsdetails']) ?/li
/ul
/div
? endforeach ?
? endif ?
/div

div id=pgcontrol
?= $this-paginationControl($this-paginator, 'Sliding',
 'index/mypaginator.phtml'); ? //please take note of this if
 this is ok
/div
 

 my Paginator script (same as provided in documentation search style)
 ===

 !--
 See http://developer.yahoo.com/ypatterns/pattern.php?pattern=searchpagination
 --

 ?php if ($this-pageCount): ?
 div class=paginationControl
 !-- Previous page link --
 ?php if (isset($this-previous)): ?
  a href=?= $this-url(array('page' = $this-previous)); ?
lt; Previous
  /a |
 ?php else: ?
  span class=disabledlt; Previous/span |
 ?php endif; ?

 !-- Numbered page links --
 ?php foreach ($this-pagesInRange as $page): ?
  ?php if ($page != $this-current): ?
a href=?= $this-url(array('page' = $page)); ?
?= $page; ?
/a |
  ?php else: ?
?= $page; ? |
  ?php endif; ?
 ?php endforeach; ?

 !-- Next page link --
 ?php if (isset($this-next)): ?
  a href=?= $this-url(array('page' = $this-next)); ?
Next gt;
  /a
 ?php else: ?
  span class=disabledNext gt;/span
 ?php endif; ?
 /div
 ?php endif; ?
 =


 When I open the site, it shows the first five entries together with
 paginator control. However when I click next, my url get changed from
 http://myweb/ to http://myweb/index/index/page/2 and doesn't go to
 next five records. (why there is two index in my url?)

 I know now that I need some kind to routing here. So my question is
 how to do that with my current setting?


 My bootstrap.php
 =

 previously
 --
 $frontController = Zend_Controller_Front::getInstance();
 $frontController-setControllerDirectory(APPLICATION_PATH . '/controllers');
 $frontController-setParam('env', APPLICATION_ENVIRONMENT);

 now I added but not sure it this should be here. anyway this is not working
 --
 $router = $frontController-getRouter();
 $router-addRoute('index', new 
 Zend_Controller_Router_Route('index/index/:page',
array('module' = 'index', 'page' = 1,
  'Controller' = 'index',
  'Action' = 'index')));
 ===

 I am lost here. What else I need to know to get this thing done?

 Please look at what I have provided and guide me on filling the missing part.

 thanks


Ok I got some crash course on Zend_Controller_Router_Route and I am
beginning to understand

Re: [fw-general] Zend_Paginator Question

2009-02-12 Thread Deepak Shrestha
On Tue, Feb 10, 2009 at 11:58 PM, keith Pope mute.p...@googlemail.com wrote:
 Heres what I do, this is within a model resource Model has Resource -
 Zend_Db_Table.

public function getProductsByCategory($categoryId, $paged=null, 
 $order=null)
{
$select = $this-select();
$select-from('product')
   -where(categoryId IN(?), $categoryId);

if (true === is_array($order)) {
$select-order($order);
}

if (false !== $paged) {
$adapter = new 
 Zend_Paginator_Adapter_DbTableSelect($select);
$count = clone $select;
$count-reset(Zend_Db_Select::COLUMNS);
$count-reset(Zend_Db_Select::FROM);
$count-from('product', new Zend_Db_Expr('COUNT(*) AS
 `zend_paginator_row_count`'));
$adapter-setRowCount($count);

$paginator = new Zend_Paginator($adapter);
$paginator-setItemCountPerPage(5)
  -setCurrentPageNumber((int) $paged);
return $paginator;
}

return $this-fetchAll($select, array('catIds' = $categoryId));
}

 Full code here http://code.google.com/p/zendframeworkstorefront/

Thanks for the tips. I got some idea from yours and my implementation
is something like this:

===
1. Controller gets the form parameters through getValues() and pass
everything to Model.
2. Model (which have access to DBTable) will dynamically generate
query based on user's criteria and initialize the paginator and
returns to Controller.
3. Controller then assign the returned paginator to view.
=

so far I was able to display the result but I am confused over where
the paginator control's phtml file goes.

Supposing my paginator control's filename is 'mypaginator.phtml'.
Where does this file reside?

my view script for pagination control
===
div id=pgcontrol
?= $this-paginationControl($this-mypaginator,
 'Sliding',
 'mypaginator.phtml'); ?
/div
==

I am getting errors in place of paginator control.



in the same place as the view script?
===
views
   scripts
  index
 index.phtml
 mypagintor.phtml

using this I got file not found error.

OR
resides in separate directory?

views
  scripts
 mypaginator
 index.phtml

using this I got include error.

OR in the public directory?

Need some suggestions

Thanks
-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Zend_Paginator Question

2009-02-12 Thread Deepak Shrestha
this file structure


 in the same place as the view script?
 ===
 views
   scripts
  index
 index.phtml
 mypagintor.phtml
 
 using this I got file not found error.


and this modification solved the problem

===
   div id=pgcontrol
   ?= $this-paginationControl($this-mypaginator,
'Sliding',
'index/mypaginator.phtml'); ?
   /div
==

However, i cannot navigate to other results through paginator? If I
click next, my url get changed to 'http://myweb/index/index/page/2'
but same first page is shown?

What am I doing wrong?

Thanks
-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Another Zend_paginator Question

2009-02-12 Thread Deepak Shrestha
Hi,

So far I am able to use the Zend_Paginator to display the limited
results but I cannot forward through pages yet. I guess I need to
track the page number request from paginator control (either through
URL  or using Zend_Controller_Router_Interface) but before doing that
I have some questions.

1. Where should be the paginator control file (mypaginator.phtml)?
currently my paginator control phtml file is in the same view script
as my index.phtml.

2. Currently I have managed to display the paginator control but when
I click next, my url changes from http://myweb/ to
http://myweb/index/index/page/2. Why there are two index in my url?
Isn't that it should be http://myweb/page/2 only?

3. How to track page request from paginator control through URL?
Documentation recommends (although not necessary) the use of
'Zend_Controller_Router_Interface'. Can somebody give me some hints on
how to use this? Which is better?

Thanks


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Another Zend_paginator Question

2009-02-12 Thread Deepak Shrestha
You are PHPScriptor. Arn't you? I like your answering style :-)


 In the same directory I think you mean.




Yes. so that means what I am doing is fine.




 public function setupRoutes(Zend_Controller_Front $frontController)
 {
  $router = $frontController-getRouter();
  $router-addRoute(
'news',
new Zend_Controller_Router_Route('news/:page',
array('module'='news', 'page' = 1, 'controller' = 'index', 'action'
 = 'index'))
  );
 }

 this is giving me something like http//localhost/news/page/2 ('page' = 1 is
 set 'cause I want to start at this page :-))





Where this function should go?
bootstrap.php?
In the controller?
model?


Sorry for asking the silly question, I am kind of lost here. I don't
fully understand this yet.


Thank for your time.

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Another Zend_paginator Question

2009-02-12 Thread Deepak Shrestha
Let me explain a bit so that it will be clear about
1. what I am trying to do
2. where I am doing wrong and
3. where I need to fill up the missing pieces.


My front page is where all the records are shown so I wanted to use
the paginator. For the simplicity I want to fetch all the records from
database and paginate.

My concept of doing that:

1. IndexController will delegate the work to Model (which have access
to DBTable)
2. Model instantiates the Paginator and returns to controller
3. Controller then assign the paginator to view.
4. View will loop through the probided paginator to render the records
plus show paginator control.


Now some code

My controller:
==
public function indexAction()
{
$this-showAllEntries();
}


private function showAllEntries()
{
$newsmodel = $this-_getNewsModel();
$this-view-paginator = $newsmodel-fetchAllEntries();
}

=

My Model:
==
public function fetchAllEntries()
{
$table = $this-getTable();
$select = $table-select()-order('newsdate desc');
$pgadapter = new Zend_Paginator_Adapter_DbTableSelect($select);
$paginator = new Zend_Paginator($pgadapter);
$paginator-setItemCountPerPage(5);
//$paginator-setCurrentPageNumber(1); //should be dynamic I guess
return $paginator;
}

public function getTable()
{
if (null === $this-_table) {
require_once APPLICATION_PATH . '/models/DbTable/NewsTable.php';
$this-_table = new Model_DbTable_NewsTable;
}
return $this-_table;
}



My index view script and paginator control script is in the same directory
===
views
  scripts
index
  index.phtml
  mypaginator.phtml
==


My view script (index.phtml)
==
div id=newslist
? if ($this-paginator ): ?
? foreach ($this-paginator as $entry): ?
div id=ads
ul
li id=adtitle?=
$this-escape($entry['newstitle']) ?/li
li id=addetails?=
$this-escape($entry['newsdetails']) ?/li
/ul
/div
? endforeach ?
? endif ?
/div

div id=pgcontrol
?= $this-paginationControl($this-paginator, 'Sliding',
'index/mypaginator.phtml'); ? //please take note of this if
this is ok
/div


my Paginator script (same as provided in documentation search style)
===

!--
See http://developer.yahoo.com/ypatterns/pattern.php?pattern=searchpagination
--

?php if ($this-pageCount): ?
div class=paginationControl
!-- Previous page link --
?php if (isset($this-previous)): ?
  a href=?= $this-url(array('page' = $this-previous)); ?
lt; Previous
  /a |
?php else: ?
  span class=disabledlt; Previous/span |
?php endif; ?

!-- Numbered page links --
?php foreach ($this-pagesInRange as $page): ?
  ?php if ($page != $this-current): ?
a href=?= $this-url(array('page' = $page)); ?
?= $page; ?
/a |
  ?php else: ?
?= $page; ? |
  ?php endif; ?
?php endforeach; ?

!-- Next page link --
?php if (isset($this-next)): ?
  a href=?= $this-url(array('page' = $this-next)); ?
Next gt;
  /a
?php else: ?
  span class=disabledNext gt;/span
?php endif; ?
/div
?php endif; ?
=


When I open the site, it shows the first five entries together with
paginator control. However when I click next, my url get changed from
http://myweb/ to http://myweb/index/index/page/2 and doesn't go to
next five records. (why there is two index in my url?)

I know now that I need some kind to routing here. So my question is
how to do that with my current setting?


My bootstrap.php
=

previously
--
$frontController = Zend_Controller_Front::getInstance();
$frontController-setControllerDirectory(APPLICATION_PATH . '/controllers');
$frontController-setParam('env', APPLICATION_ENVIRONMENT);

now I added but not sure it this should be here. anyway this is not working
--
$router = $frontController-getRouter();
$router-addRoute('index', new Zend_Controller_Router_Route('index/index/:page',
array('module' = 'index', 'page' = 1,
  'Controller' = 'index',
  'Action' = 'index')));
===

I am lost here. What else I need to know to get this thing done?

Please look at what I have provided and guide me on filling the missing part.

thanks


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] [OT-PHP] Insert an associative array at beginning

2009-02-11 Thread Deepak Shrestha
On Wed, Feb 11, 2009 at 4:39 PM, Moritz Mertinkat mor...@mertinkat.net wrote:
 Hi there,

 the problem is that array_splice doesn't care about your string keys.
 The manual states that array_splice($input, 0, 0, array($x, $y)) is identical
 to array_unshift($input, $x, $y) which should make it clearer...

 So, instead use array_merge or the + operator:

 $locations1 = array_merge(array('Any' = 'Any'), $locations);
 $locations2 = array('Any' = 'Any') + $locations;

 Regards,
 Maurice

Thanks
-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Zend_Paginator Question

2009-02-10 Thread Deepak Shrestha
Hi,

Short and quick question:

I need some background and hint on how to use Paginator in strict Zend
Framework MVC convention? (no customization) also some insight on
Zend_Controller_Router_Interface. I cannot find enough information
in documentation to grasp this.


Long Question:
=
Currently my implementation is like this (for inserting updating data):

Controller - Model - DBTable

Now I am trying to implement search part and found out about
Paginator, which is a cool thing to implement for lots of results. I
need some hint on how to implement this in my current implementation
(staying strictly within the ZF MVC convention)? I need some overview
on where things get initialized plus how data is accessed etc.

Actually based on what I am going to implement, I guess I need to
manipulate the 'Select' in my controller (which changes based on
user's criteria) but currently I am delegating dirty works to Model.
If I delegate this to model then where do I initialize the Paginator
and feed the Select? etc. Sorry currently my view on Paginator is
still blurred and I don't know if I am asking the right question.


Thanks


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Zend_Paginator Question

2009-02-10 Thread Deepak Shrestha
On Tue, Feb 10, 2009 at 7:31 PM, PHPScriptor cont...@phpscriptor.com wrote:

 I don't know if this will answer your question, but this is how I do it:

 The paginator is set in the controller. I think you could do it in the
 model, but that would make things a lot complicater.
 Where to define your select, where,... 99% I do in the controller. 'Cause if
 not, you need to pass all your values to the model.


Thank you this is what I exactly want to know about how things get
orchestrated. This time you read my mind. :-)

 $NewsModel  = new News_NewsModel();
 $select = $NewsModel-select();
 $select-order('newsdate DESC');
 $select-where('id5');
 $news   = $NewsModel-fetchAll($select)-toArray();

 $paginator = Zend_Paginator::factory($news);
 $paginator-setCurrentPageNumber($this-_getParam('page'));
 $paginator-setItemCountPerPage(5);
 $paginator-setPageRange(10);

 $this-view-news   = $paginator;

 The 'order' and 'where' can also be done in a model-function. But why
 creating an extra function just for 2 conditions. So I do it in my
 controller.

Thanks for the example too. But small question (unclear to me).
do I need to fetch all before feeding to paginator? or I will feed the
select itself?

what I understood from documentation is if used with Zend_db_select it
will just fetch the necessary rows only. So what is the advantages and
disadvantages in this two approach? or what are the best practices
(blah)

This is what I think (please correct me if I am wrong):
==
1. If fetchall is used, we don't need to requery the db; just move
back and forth between already fetch data.So new entries after
fetchall operation will not be reflected in the serach result.

2. If we feed select to paginator, it will requery db everytime we
move back and forth plus it is possible to see the new entries made
after query when we go back (i.e, what I saw in first page can move to
second page after a while when I come back again to first page)
==

Is this true?

I am asking about this from the performance aspect

If one approach has advantage over another, can you tell me what are they?

I like your explanation. Its straight to the point.

Plus can you give me some info on Zend_Controller_Router_Interface
about how it works.

Thanks again.

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Zend_Paginator Question

2009-02-10 Thread Deepak Shrestha
On Tue, Feb 10, 2009 at 9:15 PM, PHPScriptor cont...@phpscriptor.com wrote:

 You always come back in your controller. The zend paginator add's the param
 'page' in the url.
 So you always do a requery. (if that's what you wanted to say).

 http://localhost/news become http://localhost/news/page/1

Thanks for the clarification.

What I mean is if we do fetchAll(), the result is already in the
memory (static) and no matter how paginator access it, it will show
the data already in memory (no requery to db but only get  another
part from already fetched query).

While if we feed the select() (accroding to documentation in NOTE
section http://framework.zend.com/manual/en/zend.paginator.usage.html),
it will requery db each time page changes and it is possible to see
the changes in query result over time.

Anyway I now know few concepts to get started with. By the way I found
a tutorial 
http://teethgrinder.co.uk/perm.php?a=Zend-Framework-MySQL-DB-Pagination-Tutorial
while following the previous post on similar topic but didn't make
sense till now.  I will have re-look and try something. I won't know
until I will try.

Anyway thanks and Regards!

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] [OT-PHP] Insert an associative array at beginning

2009-02-10 Thread Deepak Shrestha
Hi,

I got confused on why this is not working.

I have an array of locations stored in $location variable which is
fetched using fetchPairs(). I wanted to add and element Any = Any
at the beginning of this $location.

so my $locations is [from Zend_Degug::Dump($locations)]:
=
array(3) {
[location1] = string(9) location1
[location2] = string(9) location2
[location3] = string(9) location3
}
=

I used:
===
array_splice($locations, 0, 0, array(Any = Any));

Expecting:

array(4) {
[Any] = string(3) Any
[location1] = string(9) location1
[location2] = string(9) location2
[location3] = string(9) location3
}


But I am getting:

array(4) {
[0] = string(3) Any
[location1] = string(9) location1
[location2] = string(9) location2
[location3] = string(9) location3
}


Why?

Thanks


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Why $form-getValue() is not working?

2009-02-08 Thread Deepak Shrestha
On Sun, Feb 8, 2009 at 2:03 AM, A.J. Brown fynw...@gmail.com wrote:
 Hi Deepak,

 Can you pastebin both the controller and the form (in seperate pastes)?
 Attaching would be fine too.  I'll help you debug it.

 --
 A.J. Brown
 web | http://ajbrown.org
 phone | (937) 660-3969


Hi,

here are the files as attachment

A big Thanks


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


View.phtml
Description: Binary data
attachment: Controller.php
attachment: Form.php


Re: [fw-general] Why $form-getValue() is not working?

2009-02-08 Thread Deepak Shrestha
On Sun, Feb 8, 2009 at 9:22 PM, PHPScriptor cont...@phpscriptor.com wrote:

 your viewscript:

 ? $this-searchstr ?

 does that work?

 try something like this:

 ?php echo $this-searchstr; ?

 or
 ?= $this-searchstr; ?

 -
 visit my website at  http://www.phpscriptor.com/ http://www.phpscriptor.com/
 --
 View this message in context: 
 http://www.nabble.com/Why-%24form-%3EgetValue%28%29-is-not-working--tp21868209p21898834.html
 Sent from the Zend Framework mailing list archive at Nabble.com.



Sorry, my blunder Thanks again for pointing out that. I have
looked at my view script for about hundred times but couldn't locate
this typo.

Thanks

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Why $form-getValue() is not working?

2009-02-07 Thread Deepak Shrestha
 plus  I noticed something.

 I tried to enter the string What da Hell and it gives me invalid
 string error? why I can't type a sentence? what's wrong with the
 validation? Does this have something to do with the problem?

 Thank you for your patience.


Plus I noticed that it is causing by my Alnum validator. however I
didn't see any relation to this problem.


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] How to set option for 'Alnum' validator?

2009-02-07 Thread Deepak Shrestha
Hi,

One quick question. How to set the option for 'Alnum' validator to
accept white space?

Thanks

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Re: How to set option for 'Alnum' validator?

2009-02-07 Thread Deepak Shrestha
On Sat, Feb 7, 2009 at 7:10 PM, Deepak Shrestha d88...@gmail.com wrote:
 Hi,

 One quick question. How to set the option for 'Alnum' validator to
 accept white space?

 Thanks


Hi found the solution after digging inside Alnum.php itself:

including the third parameter like this solved the problem
=
$qsearch-addValidator('Alnum', true, array('options' =
array('allowWhiteSpace' = true)));
=

In case it will be helpful to someone

Thanks anyway

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Why $form-getValue() is not working?

2009-02-06 Thread Deepak Shrestha
Hi,

I am trying to implement a simple search function. For the test
purpose I am trying to display the search string in my view. This is
how it looks like:

my form
--
class Form_Search extends Zend_Form
{
public function init()
{
//create search text input element
$qsearch = New Zend_Form_Element_Text('qsearch');
$qsearch -setLabel('Quick Search');
$qsearch -setAttrib('size', '40');
$qsearch -setRequired(true);
$qsearch -addFilter('StringTrim');
$qsearch -addValidator('NotEmpty',true);
$qsearch -addValidator('Alnum', true);
$qsearch -addErrorMessage('Invalid search string');

// add the submit button
$submit = New Zend_Form_Element_Submit('submit');
$submit-setLabel('Search');

//add the elements to form
$this-addElements(array($qsearch, $submit));
}

}
--


my controller
-
public function indexAction()
{

$request = $this-getRequest();
$form = $this-_getSearchForm();


$this-view-form = $form;


if($request-isPost())
{
if ($form-isValid($request-getPost()))
{
$strinput = $form-getValue('qsearch');
$this-showQuickSearchResult($strinput);

}
...
...

private function showQuickSearchResult($searchstr)
{
$this-view-searchstr = $searchstr;
}

-


my view script
---
div id=quicksearch
?= $this-form ?
/div

div id=check
? if ($this-searchstr): ?
h2search string is: ? $this-searchstr ?/h2
? endif ?
/div
-



My problem is the search string I entered in the form doesn't get
shown. Its blank.

Why?

What's wrong with this code?

Isn't this how we get the value from the Form?
---
$form-getvalue(element_name);
---

Thanks


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Why $form-getValue() is not working?

2009-02-06 Thread Deepak Shrestha
On Fri, Feb 6, 2009 at 7:01 PM, PHPScriptor cont...@phpscriptor.com wrote:

 Try this:

 $this-getPost('qsearch');


It gives me:
=
Application error
Exception information:

Message: Method getPost does not exist and was not trapped in __call()
===

Trying
$request-getPost('qsearch');

gives me still blank

Any suggestion?

plus what is wrong with $form-getValue()? and what's its purpose?

Thanks

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Why $form-getValue() is not working?

2009-02-06 Thread Deepak Shrestha
On Fri, Feb 6, 2009 at 10:43 PM, PHPScriptor cont...@phpscriptor.com wrote:

 I'm assuming that if your method getPost does not exist that your
 $request-isPost() and isValid($request-getPost()) will also not work. Try
 to do a var_dump of $request-getPost(); and your $request.


Hi,

I agree with you on this. I also came up with similar logic that if
getPost() is not working then validators should also not work; however
I noticed that my validators are working perfectly.


I entered the string 'checking' in form  did var-dump of
$request-getPost() and got this:
==
array(2) {
  [qsearch] = string(8) checking
  [submit] = string(6) Search
}
==

So that means its working.

Now I don't know what's going on

Any Suggestion?

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Why $form-getValue() is not working?

2009-02-06 Thread Deepak Shrestha
Hi,

It looks like you're not setting post as the method.

$form-setMethod( 'post' );
$this-view-form = $form;

The form's method is set to post now (sorry I forgot; my bad) but I am
still getting the same result.

It's not the best way but you can do it like this maybe:

$data = $request-getPost();
echo $data['qsearch];

Still the same. After setting the method to post and getting the
vardump of getValue(), I got
==
string(8) checking
===

which I guess is correct but still can't get displayed in the view. Is
my view script wrong?

plus  I noticed something.

I tried to enter the string What da Hell and it gives me invalid
string error? why I can't type a sentence? what's wrong with the
validation? Does this have something to do with the problem?

Thank you for your patience.

--
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] How to display validator specific error message in Zend_Form?

2009-02-05 Thread Deepak Shrestha
On Thu, Feb 5, 2009 at 10:08 PM, A.J. Brown fynw...@gmail.com wrote:


 On Wed, Feb 4, 2009 at 9:44 PM, Deepak Shrestha d88...@gmail.com wrote:

 Thanks. How about assigning specific error message to each validator?


 Use the options array (3rd parameter).  The key should be 'messages' and the
 value is another array for each message type that validator can throw.
 You'll have to look at the validator class to see what message types it can
 throw.

 example (I took this from a zfforums post I just read right before seeing
 this :)):

 $username-addValidator(
  'alnum',
  true,
  array(
   'messages' = array(
'notAlnum' = 'message for sting that isnt alnum',
'stringEmpty' = 'message if field is empty'
   )
  )
 );


 --
 A.J. Brown
 web | http://ajbrown.org
 phone | (937) 660-3969


Thanks again



-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] How to display validator specific error message in Zend_Form?

2009-02-04 Thread Deepak Shrestha
Hi,

I have text element in the form with two validators
+---
$mytext= New Zend_Form_Element_Text('mytext');
$mytext-setLabel('Enter Text:');
$mytext-setAttrib('size', '40');
$mytext-setRequired(true);
$mytext-addFilter('StringTrim');
$mytext-addValidator('NotEmpty');
$mytext-addValidator('Alnum');
+---
I tried general error message to this text element like this:

$mytext-addErrorMessage('Invalid Text');

but when I try to submit the form without entering a thing, this error
message is displayed twice.

After that I tried:

$mytext-addErrorMessages(array('NotEmpty' = 'String cannot
be empty', 'Alnum' = 'Invalid string'));

Hoping this will assign the specific error to each validator, but when
I submit the empty form, now it displays the message four times.

What I actually wanted to do is:
*
Empty string will be checked first and shown error message ignoring
other validators. So if the string is empty show the error message for
empty string validator and exit from validator chain ignoring other
validators in the sequence. But it seems all validators are active
each time.
*
1. how do I do that?
plus
2. how to set the error message for specific validator so that only
that message will get displayed instead of all the error message


Thanks


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] How to display validator specific error message in Zend_Form?

2009-02-04 Thread Deepak Shrestha
 What I actually wanted to do is:
 *
 Empty string will be checked first and shown error message ignoring
 other validators. So if the string is empty show the error message for
 empty string validator and exit from validator chain ignoring other
 validators in the sequence. But it seems all validators are active
 each time.
 *
 1. how do I do that?

 You want to set the second argument of -addValidator() to true.



 --
 A.J. Brown
 web | http://ajbrown.org
 phone | (937) 660-3969


Thanks. How about assigning specific error message to each validator?


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Form layout update didn't get reflected

2009-02-02 Thread Deepak Shrestha
 Hmm, I tried it, and seems to be working fine... You didn't use decorators?
 Did you look at your html source output? Did you try cleaning up your
 browser history?

Everything is default from ZF.
No decorators.
Yes html source shows the previous order of elements.
Yes in my firefox setting it cleans up everything when I exit browser
I tried in Internet Explorer also and got the same result.


My suspicion is not at the client side but at the server. It seems
like server is caching and serving the same file. I know if I use
smarty template engines, it is possible to compile and cache the
templates for the faster response time. That's why I am asking if ZF's
view template also does that behind the scene by default?

Right now I am very new to ZF and trying to understand its internal
working. In fact the web I am building is based on the quickstart file
in the documentation. I am just expanding (modifying) it to study
different aspects.

Thanks

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Populating Zend_Form_Element_Select from database example

2009-02-01 Thread Deepak Shrestha
 Yes, add a setter method for attaching the model to the form and then do
 this in the controller. The form will then have access to the model to
 retrieve any data it needs.

 You can also populate the element directly in your controller by retrieving
 it from the form and manipulating it e.g. $form-getElement('some
 element')-setMultiOptions(some array).

so what is the use of populate and setDefaults functions?

 both are used to set the values of the elements, there no difference between
 the two.


Ok, this is the type of explanation I am looking for. Now I understand
how to manipulate form from controller. I guess the later method is
suitable for me on what I am trying to do.

Now I understand why we were not able to understand each other. It is
because I was looking for a way to populate the form elements.
Initially I thought of creating the variable in form class and getter,
setter methods but when I dug around a bit, I found the explanation in
the documentation
http://framework.zend.com/manual/en/zend.form.forms.html#zend.form.forms.elements.values
which knocked me off from the right track.

From the documentation, what I understood is $form-populate($data) is
the way to send the data to the form for manipulation (not setting the
value in already populated element).  I thought that it is part of the
ZF's behind the scene magic where form knows what data have been
passed by the controller.

Anyway it is nobody's fault but the documentation is somewhat
misleading. If you think of it naturally, populate is synonymous with
populating database tables (not selecting an particular item).

Now its all clear and I have tried the second method and it works but
with a minor problem which I still don't understand. I will be posting
that problem in next thread since this part is solved already.

Thank you both for being very patient with me.

Regards


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Array Index included question?

2009-02-01 Thread Deepak Shrestha
hi,

I am not sure if this is related to ZF but anyway I am asking it here.

I have a one column table (called location) in my database.

++
| locname |   this is also the primary key
++
|  location 1  |
++
|   location 2 |


and so on


In my model,  I have
==
public function fetchEntries()
{
$table = $this-getTable();
$select = $table-select();
return $table-fetchAll($select)-toArray();  //  THIS IS
MY SUSPECT 

//OR
//return $this-getTable()-fetchAll('1')-toArray(); //
OR THIS ONE 
}
==

In my DBTables, I have
===
?php

class Model_DbTable_LocationTable extends Zend_Db_Table_Abstract
{
/** Table name */
protected $_name= 'location';
protected $_primary = 'locname';

}
===


In my Conroller, I have
=
public function indexAction()
{
$request = $this-getRequest();
$form= $this-_getTestForm();
$modellocation = $this-_getLocationModel();
$locations = $modellocation-fetchEntries();
$form-getElement('adlocation')-setMultiOptions($locations);
...
...
...
=

In my Form, i have

$location = New Zend_Form_Element_Select('location');
$location-setLabel('*Location:');
$location-setRequired(true);
=

Everything goes fine and form renders with the Location populated but
with one problem. Array index is also shown in location listing
although it cannot be selected.

something like this:
=

Location:

 0   ( cannot be selected)

Location 1   (can be selected)
---
1
---
Location 2
---
and so on



To test this, I have created an array in my controller and tried
passing it in the form.

public function indexAction()
{
$request = $this-getRequest();
$form= $this-_getTestForm();
$modellocation = $this-_getLocationModel();
//$locations = $modellocation-fetchEntries();
$locations = array( 'rat', 'cat', 'hat');
$form-getElement('adlocation')-setMultiOptions($locations);
...
...
...
=

and this works fine and renders fine in the form without any index.



So that means I am really getting extra stuff when 'fetchEntries()' is
being called. Can somebody tell me what is wrong? what am I missing?

Thanks


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Array Index included question?

2009-02-01 Thread Deepak Shrestha
 Just for confirmation, is this what I am getting?

 
 array('location1' = 'location1', 'location2' = 'locatino2' ...)
 

 This is what I desired

 instead of
 ===
 array('somevalue' = 'location1', 'somevalue' = 'location2' ...)
 ===

I got he desired result and confirmed

Thanks

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Form layout update didn't get reflected

2009-02-01 Thread Deepak Shrestha
Hi,

I changed the order of few elements inside the Form but whenever I
access the form it is showing me the same Form from previous layout.
My update didn't get reflected.

I tried clearing the browser cache and all still the same.

Is cache working behind the scene somewhere?

Thanks


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Form layout update didn't get reflected

2009-02-01 Thread Deepak Shrestha
On Mon, Feb 2, 2009 at 2:54 PM, PHPScriptor cont...@phpscriptor.com wrote:

 Not that I know. But if you post your code, we can have a closer look...


my Form code:

?php

class Form_PostInfo extends Zend_Form
{

   public function init()
   {

   //create title element
   $title = New Zend_Form_Element_Text('title');
   $title-setLabel('*Title:');
   $title-setAttrib('size', '75');
   $title-setAttrib('maxlength', '75');
   $title-setRequired('true');
   $title-addFilter('StringTrim');
   $title-addValidator('NotEmpty');
   $title-addErrorMessage('Title should not be empty.');
   $title-addValidators(array
   (array('validator' = 'StringLength', 'options' = array(0, 75)
   )));


   // add locations in selectbox element
   // data will be filled up by controller from database
   $location = New Zend_Form_Element_Select('locname');
   $location-setLabel('*Location:');
   $location-setRequired(true);


   // add captcha to verify human

   //first create an captcha image
   $captchaimg = New Zend_Captcha_Image('captchaimg');
   $captchaimg-setFont(../application/captcha/fonts/tahoma.ttf);
   $captchaimg-setImgDir($_SERVER['DOCUMENT_ROOT'] . '/images/captcha/');
   $captchaimg-setImgUrl(/images/captcha/);
   $captchaimg-setWordlen('6');
   $captchaimg-setMessage(Entered value didn't match with the
value shown,
   'badCaptcha');


   //create user input for captcha and include the captchaimg
   $mycaptcha = New Zend_Form_Element_Captcha('adcaptcha', array(
   'captcha' = $captchaimg));
   $mycaptcha-setLabel('Please enter the letters displayed below:');
   $mycaptcha-setRequired(true);


   // add the submit button
   $submit = New Zend_Form_Element_Submit('submit');
   $submit-setLabel('Submit');


   //add the created form elements in this form
   $this-addElements(array($title, $location, $mycaptcha, $submit));


   // set the method for the display form to POST
   $this-setMethod('post');
   $this-setName('post_info');
   $this-setAttrib('id', 'infoform');
   }


}
=

This renders the Form in browser as follows:

Title:
Location:
 [select box]
Captcha Image plus entry box
Submit button
==

If I try to change the order of the elements (supposing Location first
and Title second), it still shows the same form as previous one.

Any suggestion?

===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Populating Zend_Form_Element_Select from database example

2009-01-31 Thread Deepak Shrestha
Hi,

I am confused on how to populate the Select element from database. In
the Select element I need to fill it with location data which is
stored in database as single field table (each item is unique)

location
--
location1
location2
location3
...
... etc.
--

There is very little stated in the documentation about
form-populate($data) so I am confused on which goes where.

Can somebody illustrate its mechanics step by step conceptually? In
particular when I pass the $data variable how do I access that in
the form

1. defined as global variable for this form class? OR
2. directly use that variable when creating form element? something like

===
$location = New Zend_Form_Element_Select('adlocation');
$location-setLabel('*Location:');
foreach($data as $loc)
{
$adlocation-addMultiOption($loc, $loc);
}
===

can somebody suggest me how to fill up this element?


Thanks


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Re: Populating Zend_Form_Element_Select from database example

2009-01-31 Thread Deepak Shrestha
On Sat, Jan 31, 2009 at 9:23 PM, Daniel Latter dan.lat...@gmail.com wrote:
 shoudnt $adlocation be $location?

 Thank You
 Daniel Latter


sorry for that, it is all $location (typo).

When form renders I can see the error message that Invalid argument
supplied for foreach() in TestForm.php at line 45. It seems like
nothing being passed in the form for processing.

Any clue? I have absolutely no idea.

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Populating Zend_Form_Element_Select from database example

2009-01-31 Thread Deepak Shrestha
 It looks like your doing it correct except for the array of data that you're
 using to populate the form. You're not actually populating the select
 element with options, you only want the current Or selected option to be
 selected in the select list on display.

 So in your case it's probably a location id,

 $data = array(
'location_id' = 2
 );
 $form-populate($data);

 Change location_id to whatever the id of the select element is.



Ok, just help me in this part

As I mention i my first post, I have table called location with field
locname as only field and also the primary key for that table (there
is no locationid, locname).

so If I retrieve data from that table (to array) I will have array of locations.
e.g. $data = array('location1', 'location2', ... and so on);

in my form, if I have to hand code to fill the select, I will be doing
something like this:

   $location= New Zend_Form_Element_Select('location');
   $location-setLabel('*Location:');
   $location-setMultiOptions(array('location1' = 'location1',
'location2' = 'location2'  and so on));

My question is how do I do the same thing with the previous method (
controller passes the retrieved data to form and form will iterate to
populate data in select element).

I guess it is clear now.
- Hide quoted text -

Thanks

--
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Populating Zend_Form_Element_Select from database example

2009-01-31 Thread Deepak Shrestha
On Sat, Jan 31, 2009 at 10:37 PM, gerardroche bullfrogbl...@live.com wrote:

 you would just do this

 try this first:

 $data = array(
'location' = 'location1'
 );
 $form-populate($data);


 when the form is displayed it should show a select list of location options
 with location1 selected.



I tried it but I don't see any value in my select element (it's empty)
plus it still shows the same error message at the bottom of the form
[Invalid argument supplied for foreach()]. My question is how to
populate the select element (before selecting anything from it).

Thanks for your valuable time!

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Populating Zend_Form_Element_Select from database example

2009-01-31 Thread Deepak Shrestha
On Sat, Jan 31, 2009 at 10:48 PM, Daniel Latter dan.lat...@gmail.com wrote:
 Are you sure your setting $this-data variable in the form class?, and
 if so var_dump it to see what it contains?


My sample trial code

in my controller
==
$data = array('location1' = 'location1');
$form= $this-_getTestForm();
$form-populate($data);
...

==

in my form
===
$location = New Zend_Form_Element_Select('location');
$location-setLabel('*Location:');
foreach($this-data as $loc)  //
{
 $adlocation-addMultiOption($loc);
}
...
...
===

Now I expect that the select element in the form be pouplated with a
value showing 'location1' but nothing gets in there instead error
message is shown at the bottom of the form [Invalid argument supplied
for foreach()]

I have another select element in the form, which is hand coded.
$myopts-setMultiOptions(array('option1' = 'option1', 'option2' = 'option2'));

This second select gets rendered correctly in the form.

so what's going on?

Thank a lot

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Populating Zend_Form_Element_Select from database example

2009-01-31 Thread Deepak Shrestha
 no.

 Change in my controller to the following

 in my controller
 ==
 $data = array('location' = 'location1');
 $form= $this-_getTestForm();
 $form-populate($data);
 ...
 
 ==

 all i did was change the array

 from

 $data = array('location1' = 'location1');

 to


 $data = array('location' = 'location1');


 does it work now?


Is this what you mean? the name I gave to select element is what it
should be in the $data array's index?

===
$data = array('location' = 'location1');
   \-\
  \
$location = New Zend_Form_Element_Select('location');
==

I did as you said and still got the same error message.

Thank you both for being patient with me. As you can see I am
completely newbie in this subject.


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Populating Zend_Form_Element_Select from database example

2009-01-31 Thread Deepak Shrestha
On Sat, Jan 31, 2009 at 11:46 PM, gerardroche bullfrogbl...@live.com wrote:

 you keep moving the goal posts.

 put this in your form, to the letter:

 $location= New Zend_Form_Element_Select('location');
 $location-setLabel('*Location:');
 $location-setMultiOptions(array('location1' = 'location1', 'location2' =
 'location2'));


 And in your controller:

 $data = array('location' = 'location1');
 $form= $this-_getTestForm();
 $form-populate($data);


 does it work? (location1 should be selected)

 if yes try this in controller:

 $data = array('location' = 'location2');
 $form= $this-_getTestForm();
 $form-populate($data);

 does it still work? (locations2 should now be selected in the select list)

 working?


Yes that works! and I understand what you mean about this but that is
not my question. If you read my very first post, my question was how
to populate the select element in the form from database rows? not
how to select the item in the already populated select element.

that means instead of doing by hand like this
-
$location-setMultiOptions(array('location1' = 'location1',
'location2' = 'location2'));
-
I want to fill this $location automatically from database. How do I do that?

what I understood from the link you provided me is

1. I am going to manipulate the model from the form class itself (is
this true?) so that means there is no controller involved and form
have the knowledge of how to manipulate tables directly (which should
not be if we follow the MVC pattern).


But instead

1. I want to separate the datasource itself from the form.
2. What I wanted to do is Controller will be responsible for fetching
the data from the model and pass an array to the form. Form have no
knowledge of how that data arrives there but knows that something have
been provided by controller for it to manipulate. So in my case
controller provides the location array to form and form will populate
the Zend_Form_Element_Select before showing it.
3. The part I wanted to know is how this mechanism works (or how to
make that happen)?

That's why I asked in my first post:

a) Do I need to declare global variable in my form class plus getter,
setter methods so that Controller can set that variable through those
methods and I can use the data provided in that variable?

b) or when controller uses $form-populate(some array), the form
already have knowledge of what's being passed to it? If so how the
form will knows what to reference?

If I understand this then I know what I am looking for and can figure
out how to write the code I need.

Please correct me if I am wrong about my concept.

Now can you explain how this works and how to make that happen in
plain English (no code involved)

Thanks

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] Populating Zend_Form_Element_Select from database example

2009-01-31 Thread Deepak Shrestha
On Sun, Feb 1, 2009 at 12:37 AM, Daniel Latter dan.lat...@gmail.com wrote:
 a) Do I need to declare global variable in my form class plus getter,
 setter methods so that Controller can set that variable through those
 methods and I can use the data provided in that variable?

 yes.

so what is the use of populate and setDefaults functions?

Thanks again


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Re: Zend_Captcha custom error message question

2009-01-28 Thread Deepak Shrestha
On Wed, Jan 28, 2009 at 3:23 PM, Deepak Shrestha d88...@gmail.com wrote:
 Ok,

  I found a Warning displayed at top of my form after validation.

 The Message:
 =
 Warning: htmlspecialchars() expects parameter 1 to be string, array
 given in C:\WEB\myweb\library\Zend\View\Abstract.php on line 804
 

 What does this mean?


If custom message is removed, form displays the error message Captcha
value is wrong. I have tried addErrorMessage() and setErrorMessages()
with no luck.

Thanks again
-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Re: Zend_Captcha custom error message question

2009-01-28 Thread Deepak Shrestha
Hi, me again

it is solved now by doing this

==
$captchaimg-setMessage(My Custom Message, 'badCaptcha');
==

This came to my mind only after I did some digging around and had a
look at the code
'Zend/captcha/Word.php' (ancestor class)

Where the message template and keywords are defined

=
const MISSING_VALUE = 'missingValue';
const MISSING_ID= 'missingID';
const BAD_CAPTCHA   = 'badCaptcha';
/*...@-*/

/**
 * Error messages
 * @var array
 */
protected $_messageTemplates = array(
self::MISSING_VALUE = 'Empty captcha value',
self::MISSING_ID= 'Captcha ID field is missing',
self::BAD_CAPTCHA   = 'Captcha value is wrong',
);

==

Thanks anyway


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Zend_Captcha custom error message question

2009-01-27 Thread Deepak Shrestha
Hi,

Breaking from previous post, I am posting this as a new subject.

I am using Zend_From to display captcha with custom error message.
When I make a wrong entry (intentionally), my custom error message is
not shown when form validates.

Sample code:

//first create an captcha image
$captchaimg = New Zend_Captcha_Image('captchaimg');
$captchaimg-setFont(../application/captcha/fonts/tahoma.ttf);
$captchaimg-setImgDir($_SERVER['DOCUMENT_ROOT'] . '/images/captcha/');
$captchaimg-setImgUrl(/images/captcha/);
$captchaimg-setWordlen('6');

//create user input for captcha and include the captchaimg in form
$adcaptcha = New Zend_Form_Element_Captcha('adcaptcha', array(
'captcha' = $captchaimg));
$adcaptcha-setLabel('Please enter the letters displayed below:');
$adcaptcha-setRequired(true);
$adcaptcha-addErrorMessage('Entered value did not match with
displayed image.');   this part 

===

I have checked the HTML code through view source (after validation).
My error message is nowhere to be found in final HTML.

Question:

1. Is my way of setting custom error message correct?
2. If yes, why it is not shown? what else needs to be considered?
===

Thanks


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Re: Zend_Captcha custom error message question

2009-01-27 Thread Deepak Shrestha
Ok,

 I found a Warning displayed at to of my form after validation.

The Message:
=
Warning: htmlspecialchars() expects parameter 1 to be string, array
given in C:\WEB\myweb\library\Zend\View\Abstract.php on line 804


What does this mean?

Thanks

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Re: How to use Image based Captcha?

2009-01-26 Thread Deepak Shrestha
Hi,

I found out that image is being generated. Also because of
$captchaimg-generate(); command its being generated twice.
So I replaced the 'generate()' with $captchaimg-setWordlen('5');

Now I can see that every time I display the form page, new image is
generated in the 'captcha/images' folder (which are valid images) but
its not displayed inside the form.

What is wrong?

Thanks


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Zend_Form or Captcha bug?

2009-01-26 Thread Deepak Shrestha
Hi,

Didn't get any help from my last post so I went through documentation
and tried to understand as much I can but can't find a way to display
captcha image in Zend_Form using default behavior of Zend Framework's
MVC. AFAIK (with my current knowledge), my code is correct.

This is the code snippet in  my [application/forms/myform.php]
===

//first create an image type captcha
$captchaimg = New Zend_Captcha_Image('captchaimg');
$captchaimg-setFont(../application/captcha/fonts/tahoma.ttf);
$captchaimg-setImgDir(../application/captcha/images);
$captchaimg-setImgUrl(../application/captcha/images);
$captchaimg-setWordlen('6');

//create user input for captcha and include the captchaimg in form
$adcaptcha = New Zend_Form_Element_Captcha('adcaptcha', array(
'captcha' = $captchaimg));
$adcaptcha-setLabel('Please enter the 5 letters displayed below:');
$adcaptcha-setRequired(true);
$adcaptcha-addErrorMessage('Entered value did not match with
displayed image.');

$this-addElements( array($adcaptcha));
=

My view script:

?= $this-form ?



dirctory structure for captcha image is:
=
application
- captcha
- fonts
- images (for genreated images)
=


My Observation
===
1. There is no captcha image when form renders. However, I can see
image being generated in 'application/captcha/images' folder.

2. Trying to post the empty form (expecting that my custom error
message will be displayed) gives me empty error message string with
just a round bullet list in the captcha section but other text input
fields show the correct error messages.

3. Using view source in the browser, i got this about captcha

*
dd
img alt= 
src=../application/captcha/images/641aa987b887cbefb441f33e194a45b9.png/br/
input type=hidden name=adcaptcha[id]
value=641aa987b887cbefb441f33e194a45b9 helper=formText
id=adcaptcha-id /
input type=text name=adcaptcha[input] id=adcaptcha-input
value= helper=formText //dd

**
===


My Questions:

1. The image url was passed to the brower but why it didn't get
rendered in the form?
2. Is this the bug or feature? If it is the feature, how do I make the
image appear in my form using the code I have posted above? what are
the additional things I need to consider?



Partial answer (best guess) to my own question:

1. Probably form is forgetting to call some default rendering function
of Zend_Captcha to render it (or ???).  However custom approach (with
custom form) as shown in zend documentation
[http://framework.zend.com/manual/en/zend.captcha.operation.html] and
the one I found in recent blog [http://www.tfountain.co.uk/] works
because it explicitly calls echo $captcha-render($view); method.



But I want to stick with ZF's default MVC behaviors and want to
understand how these pieces fit together before I can understand and
do customized stuffs. So I need to show the captcha image suing zend
form.

Can somebody guide me about whether it is bug/feature? and any workaround?

Thanks a lot


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Re: Zend_Form or Captcha bug?

2009-01-26 Thread Deepak Shrestha
On Tue, Jan 27, 2009 at 3:24 PM, Deepak Shrestha d88...@gmail.com wrote:
 Hi,

 Didn't get any help from my last post so I went through documentation
 and tried to understand as much I can but can't find a way to display
 captcha image in Zend_Form using default behavior of Zend Framework's
 MVC. AFAIK (with my current knowledge), my code is correct.

 This is the code snippet in  my [application/forms/myform.php]
 ===

//first create an image type captcha
$captchaimg = New Zend_Captcha_Image('captchaimg');
$captchaimg-setFont(../application/captcha/fonts/tahoma.ttf);
$captchaimg-setImgDir(../application/captcha/images);
$captchaimg-setImgUrl(../application/captcha/images);
$captchaimg-setWordlen('6');

//create user input for captcha and include the captchaimg in form
$adcaptcha = New Zend_Form_Element_Captcha('adcaptcha', array(
'captcha' = $captchaimg));
$adcaptcha-setLabel('Please enter the 5 letters displayed below:');
$adcaptcha-setRequired(true);
$adcaptcha-addErrorMessage('Entered value did not match with
 displayed image.');

 $this-addElements( array($adcaptcha));
 =

 My view script:
 
 ?= $this-form ?
 


 dirctory structure for captcha image is:
 =
 application
- captcha
- fonts
- images (for genreated images)
 =


 My Observation
 ===
 1. There is no captcha image when form renders. However, I can see
 image being generated in 'application/captcha/images' folder.

 2. Trying to post the empty form (expecting that my custom error
 message will be displayed) gives me empty error message string with
 just a round bullet list in the captcha section but other text input
 fields show the correct error messages.

 3. Using view source in the browser, i got this about captcha

 *
 dd
 img alt= 
 src=../application/captcha/images/641aa987b887cbefb441f33e194a45b9.png/br/
 input type=hidden name=adcaptcha[id]
 value=641aa987b887cbefb441f33e194a45b9 helper=formText
 id=adcaptcha-id /
 input type=text name=adcaptcha[input] id=adcaptcha-input
 value= helper=formText //dd

 **
 ===


 My Questions:
 
 1. The image url was passed to the brower but why it didn't get
 rendered in the form?
 2. Is this the bug or feature? If it is the feature, how do I make the
 image appear in my form using the code I have posted above? what are
 the additional things I need to consider?
 


 Partial answer (best guess) to my own question:
 
 1. Probably form is forgetting to call some default rendering function
 of Zend_Captcha to render it (or ???).  However custom approach (with
 custom form) as shown in zend documentation
 [http://framework.zend.com/manual/en/zend.captcha.operation.html] and
 the one I found in recent blog [http://www.tfountain.co.uk/] works
 because it explicitly calls echo $captcha-render($view); method.
 


 But I want to stick with ZF's default MVC behaviors and want to
 understand how these pieces fit together before I can understand and
 do customized stuffs. So I need to show the captcha image suing zend
 form.

 Can somebody guide me about whether it is bug/feature? and any workaround?

 Thanks a lot



Sorry I forgot to mention that I am using current version of ZF 1.7

Thanks


-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] How to use Image based Captcha?

2009-01-25 Thread Deepak Shrestha
Hi,

I am absolutely new to ZF. Right now I am playing around with the
Quickstart files. So far I am bit comfortable with the concepts. Now
I want to change the provided zend captcha (figlet) into image type
but can't find any example of this in the zend documentation.

This is what I came up with

$mycaptcha = New Zend_Form_Element_Captcha('mycaptcha');
$mycaptcha -setLabel('Please enter the 5 letters displayed below:');
$mycaptcha -setRequired(true);
$mycaptcha -setCaptcha('Image', array(
'font' = 'C:\WINDOWS\FONTS\TAHOMA.TTF',
'imgdir' = APPLICATION_PATH . '/images/captcha'
));


I have created the images/captcha folder inside the application path
and expecting to show up the label and image but instead it shows an
unrelated error.

Error message:
==
An error occurred
Application error
Exception information:

Message: Invalid validator provided to addValidator; must be string or
Zend_Validate_Interface
==

if I remove the captcha element from the form it works fine.

What is wrong with my code? and where should I look for more
information on this?

Any suggestions/guidance?

Thanks!

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] Re: How to use Image based Captcha?

2009-01-25 Thread Deepak Shrestha
After reading the list archive
http://www.nabble.com/Zend_Captcha-td20300142.html#a20300142 , I
figured out my mistake. Now I have made changes and code looks like
this

...
...
...
//first create an image type captcha
$captchaimg = New Zend_Captcha_Image('captchaimg');
$captchaimg-setFont(APPLICATION_PATH . '/captcha/fonts/tahoma.ttf');
$captchaimg-setImgDir(APPLICATION_PATH . '/captcha/images');
$captchaimg-generate();

//create user input for captcha and include the captchaimg in form
$adcaptcha = New Zend_Form_Element_Captcha('adcaptcha', array(
'captcha' = $captchaimg));
$adcaptcha-setLabel('Please enter the 5 letters displayed below:');
$adcaptcha-setRequired(true);
...
...
...


As you can see, i have copied the font to application itself. Now form
displays with Please enter the 5 letters displayed below but no
image is shown.

Checking in '/captcha/images' shows no image have been generated.
Isn't that this folder should have generated images?

What is wrong now?

Please can somebody guide me.

Thanks

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


[fw-general] quickstart tutorial create layout help

2009-01-07 Thread Deepak Shrestha
Hi,

I am completely new to ZF and following the quickstart guide. It was
doing OK until I reached the part Create Layout section
(http://framework.zend.com/docs/quickstart/create-a-layout) my page
start to show something unusual. I cannot understand this yet.

Things that might help:
-
1) I am using Apache 2.2.11, PHP 5.2.8, latest ZF 1.7 in windows xp
2) quickstart is hosted as virtual host
-

[http://quickstart] shows:
===
doctype() ?  headLink()-appendStylesheet('/css/global.css') ?
ZF Quickstart Application
Guestbook
layout()-content ?
===

Cannot find any error logged by apahce.

Any explanation/suggestion is greatly appreciated.

Thanks

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===


Re: [fw-general] quickstart tutorial create layout help

2009-01-07 Thread Deepak Shrestha
On Wed, Jan 7, 2009 at 4:48 PM, keith Pope mute.p...@googlemail.com wrote:
 Looks like you dont have short tags enabled for your php install. In
 your .htaccess use

 php_value short_open_tag on

It works now. Can move on with tutorials
Thanks

-- 
===
Registered Linux User #460714
Currently Using Fedora 8, 10
===