Re: Save in differents models

2011-06-17 Thread Stefano Salvatori
try with $this-TurisSit-saveall($this-data);

S.
 TuristSit


On Jun 17, 2011, at 12:17 AM, csoria wrote:

 Hi i'm new in cakephp
 
 I'm starting to do an application and i'm wondering if i can save in
 different models from one form.
 
 For more specific:
 
 I have three models
 TuristSite: Has One Contact
 Contact: Belongs To a TuristSite, Has Many Telephones
 Telephone: Belongs To a Contact
 
 I want to put all the information for this three models in one form in
 the action turist_sites/add
 
 
 In the add.ctp of turist_sites
   echo $this-Form-input('TuristSite.name');
   echo $this-Form-input('TuristSite.logo', 
 array('type'='file'));
   echo $this-Form-input('TuristSite.website');
   echo $this-Form-input('TuristSite.address');
   echo $this-Form-input('TuristSite.description');
   echo $this-Form-hidden('TuristSite.votes', 
 array('value'='0'));
   echo $this-Form-hidden('TuristSite.views', 
 array('value'='0'));
   echo $this-Form-input('TuristSite.User');
 
echo $this-Form-input('Contact.name');
echo $this-Form-input('Contact.last_name');
echo $this-Form-input('Contact.email');
echo $this-Form-hidden('Contact.turist_site_id');
 
echo $this-Form-input('Thelephone.0.number);
echo $this-Form-hidden('Thelephone.0.contact_id);
echo $this-Form-input('Thelephone.1.number);
echo $this-Form-hidden('Thelephone.1.contact_id);
echo $this-Form-input('Thelephone.2.number);
echo $this-Form-hidden('Thelephone.2.contact_id);
 
 And this i have controller's add action
 
$turistSiteData = $this-data['TuristSite'];
$contactData = $this-data['Contact'];
 
   if ($this-TuristSite-save($turistSiteData) {
if ($this-TuristSite-Contact-
 addContactTuristSite($this-TuristSite-id, $contactData)) {
$this-Session-setFlash(__('The
 turist site has been saved', true));
$this-redirect(array('action' =
 'index'));
}
else {
$this-TuristSite-delete($this-
 TuristSite-id, false);
$this-Session-setFlash(__('The
 contact of the turist site could not be saved. Please, try again.',
 true));
}
 
   }
 
 And i have a function in the Contact Model
 
 
function addContactTuristSite($id = null, $data = null) {
if ($id == null  data == null){
return false;
}
else{
$data['Contact']['turist_site_id'] = $id;
return $this-save($data);
}
}
 
 When i run this, just save the information for the TuristSite and
 insert a row in the Contacts table but just with the id and the
 turist_site_id.
 
 I don't know if you understand my problem. And if this the best way to
 do this. Any answer will be apreciate.
 
 -- 
 Our newest site for the community: CakePHP Video Tutorials 
 http://tv.cakephp.org 
 Check out the new CakePHP Questions site http://ask.cakephp.org and help 
 others with their CakePHP related questions.
 
 
 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

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Display data from specific data in the Home Page

2010-12-26 Thread Stefano Salvatori
Hi

In one controller add some like that

$uses = array('Post','User');

function myfunction() {

$this-set('users',$this-User-find('all'));
$this-set('users',$this-Post-find('all'));
}

then in router.php

Router::connect('/', array('controller' = 'yourcontroller', 'action'
= 'myfunction'));



On Mon, Dec 27, 2010 at 12:52 AM, Amit Badkas amit.sanis...@gmail.com wrote:
 Hi,
 Please follow http://book.cakephp.org/view/1528/Blog to build a basic blog
 application in CakePHP so that you will get familiar with CakePHP working.
 Amit Badkas
 PHP Applications for E-Biz: http://www.sanisoft.com


 On Sun, Dec 26, 2010 at 7:38 PM, Ahmed - CakePHP ahmed.amo...@gmail.com
 wrote:

 Hello Everybody,

 As you know, I am a beginner in CakePHP.
 I trying to do a blog, simple blog, just as a training in how to build
 a websites using CakePHP.

 I created few Controllers, such as (users, posts, comments and
 categories).
 Also I designed the Home Page, which is empty now.

 I want to know:
 How can I display data from the Tables in the database in the Home
 Page.

 For example:
 - I want to display the latest posts.
 also, may be, the latest registered users
 or whatever


 Can you please tell me how CakePHP deals with this.



 Thank you in Advance,
 Ahmed

 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

 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




-- 
Stefano Salvatori M.
http://stefano.salvatori.cl/

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: Validation (Check If username Exists Display Error Message)

2010-12-17 Thread Stefano Salvatori
cakephp 1.3 has isUnique

http://book.cakephp.org/view/134/Core-Validation-Rules#isUnique-472

On Fri, Dec 17, 2010 at 2:19 PM, John Maxim goog...@gmail.com wrote:
 Hi everyone,

 I have a problem with validation script here:

 ***The first script I used*

 function beforeValidate() {
    if (!$this-id) {
        if ($this-findCount(array('User.username'
                                = $this-data['User']['username']))  0) {
            $this-invalidate('username_unique');
            return false;
        }
    }
    return true;
 }

 ***The second script I used*

 function beforeValidate() {
 if (!$this-id) {
 if ($this-find('count',array('conditions' =array('User.username' =

 $this-data)))  0) {
 $this-invalidate('username_unique');
 return false;
 }
 }
 return true;
 }

 ***
 Error I get:
 Warning (512): SQL Error: 1062: Duplicate entry 'James5' for key
 'username' [CORE\cake\libs\model\datasources\dbo_source.php, line 684]

 ***

 It was supposed to display the error msg stating the username already
 taken. I don't know where went wrong... Anyone can shed some light
 here ?



 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




-- 
Stefano Salvatori M.
http://stefano.salvatori.cl/

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