Re: Distinct query and paginator

2009-12-16 Thread E T
Hi, I've managed to get the solution for my need.

So, I thought I'd share here hopefully can help anyone with the same
problem.

Just put this inside your controller (no need to create *paginate* function)
---
$recursive = -1;
$order = '';
$limit = 20;
$fields = array('DISTINCT No', 'Name', 'Expiry', 'Batchcode', 'Type');
$this->paginate = array(
'limit' => $limit,
'fields' => $fields,
'conditions' => $conditions,
'recursive' => $recursive,
'order' => $order,
);

$list_member = $this->paginate('Member');
---

You'll need the *paginateCount* function:

---
function paginateCount($conditions = null, $recursive = 0) {
  $recursive = -1;
  $fields = array('DISTINCT No', 'Name', 'Expiry', 'Batchcode', 'Type');
  $params = array(
  'conditions' => $conditions,
  'recursive' => $recursive,
  'fields' => $fields,
   );
   $results = $this->Member->find('all', $params);
   return count($results);
}
---

and override the pagination value with some hacks.

---
$ttl_page = round($this->paginateCount($conditions)/$limit);
$this->params['paging']['Member']['pageCount'] = $ttl_page;
if($ttl_page==$this->params['paging']['Member']['page']){
$this->params['paging']['Member']['nextPage'] = '';
}
---

I know, this may not be the best solution, but it works out for me. If
anyone have a better solution, please share. Thanks.

On Mon, Dec 14, 2009 at 12:45 AM, E T  wrote:

> Hi all,
>
> I'm trying to display a list of records in my view and limiting the records
> to 20. However, there are duplicate data in the model. So the view is not
> displaying properly. I've tried this method (
> http://www.littlehart.net/atthekeyboard/2008/03/04/custom-cakephp-12-pagination-queries/)
> but when I override the paginate method, I cannot use $paginator in my view
> (the one that says Showing page x of x).
>
> I used this method in my controller:
>
> function paginate($conditions, $fields, $order, $limit, $page = 1,
> $recursive = null) {
>   $recursive = -1;
>   $fields = array('DISTINCT ID', 'Name', 'Expiry', 'Type');
>   $params = array(
>   'conditions' => $conditions,
>   'recursive' => $recursive,
>   'fields' => $fields,
>   'order' => $order,
>   'limit' => $limit,
>   'page' => $page
>);
>return $this->Member->find('all', $params);
> }
>
> and call it using: $list = $this->paginate($conditions, '', '', $limit, 2);
>
> This will give me the correct data, but nothing in $paginator->counter().
>
> Any help is appreciated. Thanks.
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Distinct query and paginator

2009-12-13 Thread E T
Hi all,

I'm trying to display a list of records in my view and limiting the records
to 20. However, there are duplicate data in the model. So the view is not
displaying properly. I've tried this method (
http://www.littlehart.net/atthekeyboard/2008/03/04/custom-cakephp-12-pagination-queries/)
but when I override the paginate method, I cannot use $paginator in my view
(the one that says Showing page x of x).

I used this method in my controller:

function paginate($conditions, $fields, $order, $limit, $page = 1,
$recursive = null) {
  $recursive = -1;
  $fields = array('DISTINCT ID', 'Name', 'Expiry', 'Type');
  $params = array(
  'conditions' => $conditions,
  'recursive' => $recursive,
  'fields' => $fields,
  'order' => $order,
  'limit' => $limit,
  'page' => $page
   );
   return $this->Member->find('all', $params);
}

and call it using: $list = $this->paginate($conditions, '', '', $limit, 2);

This will give me the correct data, but nothing in $paginator->counter().

Any help is appreciated. Thanks.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Export to CSV using Helper, resulting error

2009-11-25 Thread E T
Hi FrederickD,

The new approach works really well. Thank you for your help :D

On Thu, Nov 26, 2009 at 12:03 PM, FrederickD
wrote:

> I just had a similar problem and post here:
>
> http://groups.google.com/group/cake-php/browse_thread/thread/f9d8203a3acb0e8f#
> .
>
> I solved the issue a few hours ago using this approach:
> http://www.dnamique.com/cakephp-export-data-to-excel-the-easy-way/. No
> helper needed. It was done in 15 minutes. I could not believe it. I
> was even able to access the action in CakePHP from a button on an
> ExtJS grid.
>
> I would highly recommend taking a look at this approach. It is the
> simplest approach I have found, and a very clear explanation.
>
> Hopefully it helps...
>
> On Nov 24, 10:03 pm, E T  wrote:
> > Hi all,
> >
> > I am trying to put a download link on one of my view, so when user click
> on
> > that link it will automatically generate a csv file and pop up for user
> to
> > download.
> >
> > I followed the instruction herehttp://
> blog.allmythingstodo.com/tag/cakephp/usingthe helper from Adam
> > Royle (http://bakery.cakephp.org/articles/view/csv-helper-php5)
> >
> > However, when I click on my link.. this is shown:
> >
> > Notice (8): Undefined variable: csv
> > [APP\controllers\dispatches_controller.php, line 158]
> >
> > Fatal error: Call to a member function addRow() on a non-object in
> > C:\xampp\htdocs\cake\app\controllers\dispatches_controller.php on line
> 158
> >
> > Please help. Thank you.
> > **
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.comFor
>  more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Export to CSV using Helper, resulting error

2009-11-24 Thread E T
Hi all,

I am trying to put a download link on one of my view, so when user click on
that link it will automatically generate a csv file and pop up for user to
download.

I followed the instruction here
http://blog.allmythingstodo.com/tag/cakephp/using the helper from Adam
Royle (
http://bakery.cakephp.org/articles/view/csv-helper-php5)

However, when I click on my link.. this is shown:

Notice (8): Undefined variable: csv
[APP\controllers\dispatches_controller.php, line 158]

Fatal error: Call to a member function addRow() on a non-object in
C:\xampp\htdocs\cake\app\controllers\dispatches_controller.php on line 158

Please help. Thank you.
**

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Cake PHP Form validation

2009-11-18 Thread E T
Wow, amazing!! You are a genius.. hehe thank you so much.

It is working now, and yes you are right, I forgot to make changes in the
view.

BTW, just one curious question.. so to create input fields in form, it is
better to use '$form->input' rather than something like '$form->password' ?
What is the difference?

Thank you.

On Wed, Nov 18, 2009 at 11:09 PM, jburns  wrote:

> First, change the inputs in the view to:
>
> echo $form->input('password1', array('label'=>'Password'));
> echo $form->input('password2', array('label'=>'Please confirm your
> password'));
>
> See what happens then.
>
> On Nov 18, 2:57 pm, E T  wrote:
> > Hi jburns,
> >
> > Thanks a lot for the reply. I've tried adding your code but it's still
> not
> > working.
> >
> > This is what happened:
> > - if name, email or username is empty, it will give an error message,
> > something like "Alphabets and numbers only" or "This field cannot be left
> > blank". However, there is no error message for password1 / password2.
> > - then I try to input everything. And when I click on save, the page
> doesn't
> > load anything. It's still on the same page, and my 'users' table is not
> > updated.
> > - if I remove the validation for password1 & password2 in the model's
> > $validate, it saves the data to db and redirect to other page (working
> > fine).
> >
> > I'm not sure what's wrong with this.
> >
> >
> >
> > On Wed, Nov 18, 2009 at 10:10 PM, jburns  wrote:
> > > I forgot something...you need to clear out the password1 and password2
> > > fields before saving. Use this:
> >
> > > function beforeSave() {
> > >if (isset($this->data['User']['password1'])):
> > >$this->data['User']['password'] =
> > >  Security::hash($this->data
> > > ['User']['password1'], null, true);
> > >unset($this->data['User']['password1']);
> > >endif;
> >
> > >if (isset($this->data['User']['password2'])):
> > >unset($this->data['User']['password2']);
> > >endif;
> >
> > >return true;
> > > }
> >
> > > On Nov 18, 2:06 pm, jburns  wrote:
> > > > First, a general point. Rather than having separate entries for label
> > > > and the input, try:
> > > > echo $form->input('xxx', array('label'=>'Xxxx'));
> > > > (where xxx is the name of your field and Xxxx is your label).
> >
> > > > This works for me when confirming that passwords match:
> >
> > > > 'password1'=>array(
> > > > 'password_1'=>array(
> > > > 'rule'=>'notEmpty',
> > > > 'message'=>'Please enter a
> password.',
> > > > 'required'=>true,
> > > > 'last'=>true),
> > > > 'password_2'=>array(
> > > > 'rule'=>array('between', 8, 20),
> > > > 'message'=>'Your password must be
> between
> > > 8 and 20 characters
> > > > long.'),
> > > > ),
> > > > 'password2'=>array(
> > > > 'match'=>array(
> > > > 'rule'=>'validatePasswdConfirm',
> > > > 'required'=>true,
> > > > 'allowEmpty'=>false,
> > > > 'message'=>'Your passwords do not
> match')
> > > > )
> >
> > > > You'll notice that the rule for validating password2 is
> > > > 'validatePasswdConfirm'. Place this function in your model:
> >
> > > > function validatePasswdConfirm($data) {
> > > > if

Re: Cake PHP Form validation

2009-11-18 Thread E T
Hi jburns,

Thanks a lot for the reply. I've tried adding your code but it's still not
working.

This is what happened:
- if name, email or username is empty, it will give an error message,
something like "Alphabets and numbers only" or "This field cannot be left
blank". However, there is no error message for password1 / password2.
- then I try to input everything. And when I click on save, the page doesn't
load anything. It's still on the same page, and my 'users' table is not
updated.
- if I remove the validation for password1 & password2 in the model's
$validate, it saves the data to db and redirect to other page (working
fine).

I'm not sure what's wrong with this.

On Wed, Nov 18, 2009 at 10:10 PM, jburns  wrote:

> I forgot something...you need to clear out the password1 and password2
> fields before saving. Use this:
>
> function beforeSave() {
>if (isset($this->data['User']['password1'])):
>$this->data['User']['password'] =
>  Security::hash($this->data
> ['User']['password1'], null, true);
>unset($this->data['User']['password1']);
>endif;
>
>if (isset($this->data['User']['password2'])):
>unset($this->data['User']['password2']);
>endif;
>
>return true;
> }
>
> On Nov 18, 2:06 pm, jburns  wrote:
> > First, a general point. Rather than having separate entries for label
> > and the input, try:
> > echo $form->input('xxx', array('label'=>'Xxxx'));
> > (where xxx is the name of your field and Xxxx is your label).
> >
> > This works for me when confirming that passwords match:
> >
> > 'password1'=>array(
> > 'password_1'=>array(
> > 'rule'=>'notEmpty',
> > 'message'=>'Please enter a password.',
> > 'required'=>true,
> > 'last'=>true),
> > 'password_2'=>array(
> > 'rule'=>array('between', 8, 20),
> > 'message'=>'Your password must be between
> 8 and 20 characters
> > long.'),
> > ),
> > 'password2'=>array(
> > 'match'=>array(
> > 'rule'=>'validatePasswdConfirm',
> > 'required'=>true,
> > 'allowEmpty'=>false,
> > 'message'=>'Your passwords do not match')
> > )
> >
> > You'll notice that the rule for validating password2 is
> > 'validatePasswdConfirm'. Place this function in your model:
> >
> > function validatePasswdConfirm($data) {
> > if ($this->data['User']['passwd'] !==
> $data['passwd_confirm']):
> > return false;
> > endif;
> >
> > return true;
> > }
> >
> > For the role field, it looks as if your syntax is a bit muddled. Try
> > something along these lines:
> >
> > echo $form->input('role', array('type'=>'select', 'empty'=>true,
> > 'options'=>$roles, 'label'=>'Role'));
> >
> > $options is the array that contains the allowed values and can be set
> > in the controller - particularly useful if you are extracting them
> > from a table.
> >
> > Hope this helps.
> >
> > On Nov 18, 10:44 am, Code Buzz  wrote:
> >
> >
> >
> > > Hi all,
> >
> > > I'm a newbie at cakePHP, and still at the learning phase.
> >
> > > I was trying to make a user management system with cakephp, where we
> > > can add/edit/delete user. But I am stuck in the validation part. I
> > > hope someone can help me on this.
> >
> > > I have this 'users' table:
> > > =
> > > CREATE TABLE `users` (
> > >   `id` int(11) NOT NULL AUTO_INCREMENT,
> > >   `username` varchar(255) NOT NULL,
> > >   `password` varchar(32) NOT NULL,
> > >   `email` varchar(80) NOT NULL,
> > >   `name` varchar(255) NOT NULL DEFAULT '',
> > >   `designation` varchar(255) DEFAULT NULL,
> > >   `role` varchar(30) NOT NULL,
> > >   `print_perm` int(1) NOT NULL,
> > >   `disabled` int(1) NOT NULL DEFAULT '0',
> > >   PRIMARY KEY (`id`)
> > > ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
> >
> > > and I have this form to add the user:
> > > =
> > >   echo $form->create('User');
> > >   echo $form->input('username');
> > >   echo $form->input('email');
> > >   echo $form->input('name');
> > >   echo $form->input('designation');
> > >   $options=array('admin'=>'Administrator','user'=>'User');
> > >   echo $form->label('Role');
> > >   echo $form->select('role',$options);
> > >   echo $form->label('Password');
> > >   echo $form->password('password1');
> > >   echo $form->label('Confirm Password');
> > >   echo $form->password('password2');
> > >   echo "";
> > >   echo $form->checkbox('print_perm');
> > >   echo " Can Print?";
> > >   echo $