Re: Validation Problem

2008-04-23 Thread plinto

Thanks, I understand what you are saying but what I need is to be able
to edit mutliple items at once.
For example if I have to edit 20 countries, clicking on every one,
editing it and saving it would take me alot more time then selecting
the ones I need to edit and having them presented in 1 page to be
edited and saved.
I also need to validate them but, for example, being all
Country.name I don't know how to obtain this.

For the part about the parser, Thanks! I'm pretty new to php and
cakephp, but willing to learn.

On Apr 22, 6:49 pm, b logica [EMAIL PROTECTED] wrote:
 You might find it simpler to, instead creating a form, to put links
 around the country names pointing to an edit method. In the edit view,
 create one form to edit the table fields and one form to delete. So
 you have something like:

 h1Edit Canada/h1

 echo $form-create('Country', array('action' = 'delete');
 echo $form-hidden('Country.id', array('value' = $some_var));
 echo $form-submit('delete');
 echo $form-end();

 echo $form-create('Country', array('action' = 'edit');
 ...
 echo $form-submit('edit');
 echo $form-end();

 This way, each action points directly to the corresponding method and
 you only have to deal with one item at a time. I realise that this may
 not be practical but it may work for you.

 Regarding $some_var above, your code appears to assume that the
 country IDs  names are going to line up with your counter var $i. I
 may be missing something but that looks odd to me. I'd think it's be
 better (if your $countries array is constructed as $id = $name) to do
 it with a while like so:

 foreach ($countries as $key = $name)
 {
$html-link($name, countries/edit/${id});

 }

 I've used my link suggestion but it's just as applicable to a form
 setup like you have.

 BTW, in your views, you don't need to put ?php ... ? around every
 line. If you don't have any HTML markup to add then you can just open
 a block:

 ?php
 echo $form-create(array('url'='/countries/process'));

 for($i =0; $i$countries; $i++) {
echo $form-hidden('Country'.$i.'.Country.id');
echo $form-input('Country'.$i.'.Country.name');

 }

 echo $form-submit('Save', array('name'='save'));
 echo $form-end();
 ?

 Otherwise, you're making the parser (and anyone who has to look at
 your code) work a lot harder than necessary ;-)

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Validation Problem

2008-04-22 Thread plinto

Hello, I am making a table that is a form where every item added has a
checkbox and the form has 2 submit buttons, 1 is to edit e 1 to
delete.
_
__|__
   | Italy
X | Us
X | Canada
__
| Edit | Delete |

The problem I am having is, since you can edit more than 1 item, I
don't know how to correctly validate them on the process view.
Here is the code to what I have done.

function process() {
if ( !empty($this-params['form']['del']) ){
$this-delete();
} else if ( !empty($this-params['form']['edit']) ){
$this-edit();
} else if ( !empty($this-params['form']['save']) ){
$this-save();
}
}


function save() {
if(!empty($this-data)) {
foreach($this-data as $country):
if ($this-Country-save($country)) {}
endforeach;
$this-redirect('/countries');
$this-Session-setFlash('spanSaved/
span','default',null,'error');
}
}


 function edit()
{
if (!empty($this-data))
{
$i =0;
foreach($this-data['Country'] as $id=$value):
if ($value == 1) {
$this-Country-id = $id;
$this-data['Country'.$i] = 
$this-Country-read();
$i++;
}
endforeach;
if ($i == 0) {
$this-Session-setFlash('spanNothing 
Selected/
span','default',null,'error');
$this-redirect('/countries');
}
$this-set('countries', $i);
}
}



process.ctp

?php echo $form-create(array('url'='/countries/process')); ?
?php for($i =0; $i$countries; $i++) { ?
?php echo $form-hidden('Country'.$i.'.Country.id'); ?
?php echo $form-input('Country'.$i.'.Country.name')?
?php } ?
?php echo $form-submit('Save', array('name'='save')) ?

?php echo $form-end(); ?

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Different layouts for different groups of users

2007-11-14 Thread plinto

Hi, I am not very good at this Acl, aro and aco stuff and am having a
hard time getting it to work right.
One of my problems is to set a different layout for the differnt types
of users.
My aro table has 2 parents, Administrators and Users, and all the
users, my question is: how can set one layout for the users and one
for the administrators?
I have no idea how to find the parent of user,( if the user logging in
is a user or administrator).

Thanks in advance, hope someone can help me


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Problem with belongsTo

2007-11-01 Thread plinto

Thanks, everything works now

On Oct 29, 11:24 pm, Grant Cox [EMAIL PROTECTED] wrote:
 Don't have a class called Model - this will conflict with the core
 Model.

 Otherwise it looks ok.  Are you sure there are associated records to
 retrieve?  Put your DEBUG to 2 in /app/config/core.php to see what SQL
 is being generated, the query should join across the other two tables.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Problem with belongsTo

2007-10-29 Thread plinto

Hi, I am having a problem with, i think, $belongsTo, it seems set up
right (I do the exact same thing for another model and it works
perfectly) but I am not getting the results of the two tables that are
associated.
If anyone can help, thanks!
Here is the code I use:

Tables
---
models: id, modello, prezzo, codice, version_id, brand_id
versions: id, description
brands: id, description

model.php
---
?php
 class Model extends AppModel
{
var $name = 'Model';
var $validate = array(
'codice' = '/^.{2,20}$/',
'modello' = '/^.{2,20}$/',
'prezzo' = '/^.{2,20}$/',
);
var $belongsTo = array('Version' = array('className' = 'Version'),
'Brand' = 
array('className' = 'Brand')
);
}
?

models_controller.php
---

function index()
{
$this-set('aa', $this-Model-findAll());
.

index.thtml
---

var_dump($aa);
.

Result

array(1) { [0]=  array(1) { [Model]=  array(6) { [id]=
string(1) 1 [codice]=  string(0)  [modello]=  string(0)
 [version_id]=  string(1) 0 [prezzo]=  string(1)
0 [brand_id]=  string(1) 0 } } }


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Problem with belongsTo

2007-10-29 Thread plinto

Hi, I am having a problem with, i think, $belongsTo, it seems set up
right (I do the exact same thing for another model and it works
perfectly) but I am not getting the results of the two tables that are
associated.
If anyone can help, thanks!
Here is the code I use:

Tables
---
models: id, modello, prezzo, codice, version_id, brand_id
versions: id, description
brands: id, description

model.php
---
?php
 class Model extends AppModel
{
var $name = 'Model';
var $validate = array(
'codice' = '/^.{2,20}$/',
'modello' = '/^.{2,20}$/',
'prezzo' = '/^.{2,20}$/',
);
var $belongsTo = array('Version' = array('className' = 'Version'),
'Brand' = 
array('className' = 'Brand')
);
}
?

models_controller.php
---

function index()
{
$this-set('aa', $this-Model-findAll());
.

index.thtml
---

var_dump($aa);
.

Result

array(1) { [0]=  array(1) { [Model]=  array(6) { [id]=
string(1) 1 [codice]=  string(0)  [modello]=  string(0)
 [version_id]=  string(1) 0 [prezzo]=  string(1)
0 [brand_id]=  string(1) 0 } } }


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---