Hey guys,

I'm in the case of a model without a table, and in particular a
contact form.
I'm using the last alpha cakePHP 1.2.0.54727alpha.

Despite using var $useTable = false; in my contact model I had to add
a loadInfo() method in the contact model.

my Contact Model looks as follows:
------------------------------------------------------------------------------------------------------------
class Contact extends AppModel {

        var $name = 'Contact';
        var $useTable = false;
        var $validate = array(
                    'nome' => array('required' => VALID_NOT_EMPTY),
                    'cognome' => array('required' => VALID_NOT_EMPTY),
                    'e-mail' => array('required' => VALID_NOT_EMPTY,
'validEmail'=>VALID_EMAIL),
                    'oggetto' => array('required' => VALID_NOT_EMPTY),
                    'messaggio' => array('required' =>
VALID_NOT_EMPTY),
                );

   function loadInfo(){
        if ($this->useTable === false)
        {
            $defaults = array(
            'null' => false,
            'default' => null,
            'length' => null
            );

           $campi = array('nome'=>'string',

                          'cognome'=>'string',

                          'e-mail'=>'string',

                          'oggetto'=>'string',

                          'messaggio'=>'text');

            foreach($campi as $field => $type)
            {
                $fields[] = am(array('name'=>$field,
                'type'=>$type), $defaults);
            }

            return new Set($fields);
        }

        return parent::loadInfo();
    }


}
------------------------------------------------------------------------------------------------------------

My contacts controller looks as follows:
------------------------------------------------------------------------------------------------------------
class ContactsController extends AppController
{
    var $name = "Contacts";
    var $layout = 'single_news';
    var $uses = 'Contact';
    var $components = array('Email');


    //-----------------------------------------
    function index(){

        $this->set('title_for_layout', 'Contatti');

        if(isset($this->data)) {

            if($this->Contact->create($this->data) && $this->Contact-
>validates()){

                //send e-mail
                $this->_sendMail();
            }
            else{
                $this->Session->setFlash('correggi gli errori
sottostanti');
                //$this->redirect('/contacts');
            }
        }
    }

    function _sendMail() {

        $senderEmail = $this->data['Contact']['e-mail'];

        $this->Email->layout = 'email';
        $this->Email->to = '[EMAIL PROTECTED]';
        $this->Email->subject = $this->data['Contact']['oggetto'];
        $this->Email->from = $senderEmail;
        $this->Email->template = 'text';
        //Send as 'html', 'text' or 'both' (default is 'text')
        $this->Email->sendAs = 'text';
        //Set view variables as normal
        $this->set('nome', ucfirst($this->data['Contact']['nome']));
        $this->set('cognome', ucfirst($this->data['Contact']
['cognome']));
        $this->set('email', $senderEmail);
        $this->set('oggetto', $this->data['Contact']['oggetto']);
        $this->set('messaggio', $this->data['Contact']['messaggio']);
        //Do not pass any args to send()
        if ( $this->Email->send() ) {
            $this->Session->setFlash('La tua e-mail è stata
spedita con successo');
            $this->redirect('/');
            exit;
        } else {
            $this->Session->setFlash("Ci sono stati dei problemi
nell'inviare l'e-mail. Ti invitiamo a riprovare");
            $this->redirect('/contacts/index/');
            exit;
        }

    }

}
------------------------------------------------------------------------------------------------------------

with PHP5 everything fine.

with PHP4 I get the following error:

Fatal error: Call to undefined function: set__() in /home/intellig/
cake_1.2.0.5427alpha/cake/libs/overloadable_php4.php on line 162

Anybody encountered the same problem?

Is there a better way to use models without DB tables?

Dan


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to