There is no set function in the Model class so the line $this->Contact-
>set( $this->data) is obviously not going to work.
The controller has a Controller::set function for sending data to the
views. If you want to load the Contact model and prefill it with data
use $this->Contact->read( $this->data[ 'Contact' ][ 'id' ] ) or
similar.

On Jul 20, 11:31 am, leafchild <[email protected]> wrote:
> Thanks euromark!!!
>
> I added code these code to my controller then its start working as I
> expected!!
>
> ===============================================
>         function beforeFilter() {
>           parent::beforeFilter();
>                 $this->Contact = ClassRegistry::init('Contact');
>         }
> ===============================================
>
> Actually I changed file name(model, controller, view) to all something
> else to test because
> I thought Cake didn't like "contact" but I got same error so still not
> sure why
> I had these error. If I end up find the error I will post it again.
>
> Thank you for your help!
>
> lc
>
> On Jul 20, 4:55 am, euromark <[email protected]> wrote:
>
>
>
>
>
>
>
> > seems like Contacts does not inflect to Contact as singular form
> > have you overridden the inflections with custom settings? maybe you
> > put "Contact=>Contact" in there
> > otherwise I don't know whats wrong. your code looks good.
>
> > taking a closer look..
> > for some reason $this->Contact does not exist
> > this has nothing to do withvalidation. the model simply isn't loaded.
> > try to debug $this->Contact
> > at what point it is missing
>
> > you could manually load it:
> > $this->Contact = ClassRegistry::init('Contact')
>
> > but I would suggest you try to find the source for this problem.
> > maybe the file name of your model is incorrect? or the location
> > somewhere cake can't find it?
>
> > On 20 Jul., 01:51,leafchild<[email protected]> wrote:
>
> > > Getting these error and I can not find a away to fix:
> > > ----------------------------------------------------------------------
> > > ----------------------------------------------------------------------
> > > Notice (8): Undefined property: ContactsController::$Contact [APP/
> > > controllers/contacts_controller.php, line 18]
>
> > > Fatal error: Call to a member function set() on a non-object in /home/
> > > www/........./cakephp_1.3.1/app/controllers/contacts_controller.php on
> > > line 18
> > > ----------------------------------------------------------------------
> > > ---------------------------------------------------------------------
>
> > > The erro is generated with this line - $this->Contact->set($this->data);
>
> > > and if I hide this section this line ( if( $this->Contact-
>
> > > >validates() ){ ) creates same error
>
> > > I have FORM page that user can enter name, email and some comment and
> > > submit.
> > > I just send email and not using database (I want to use just
> > >validationat controller).
>
> > > It seems likevalidationis not working properly and I don't know why.
>
> > > I look at this 
> > > page:http://book.cakephp.org/view/1182/Validating-Data-from-the-Controller
>
> > > contact.php
> > > ============================
> > > <?php
> > > class Contact extends AppModel {
> > >         var $name = 'Contact';
> > >         var $useTable = false;
>
> > >         var $validate = array(
> > >                 'name'=>array(
> > >                         'no_empty'=>array(
> > >                                 'rule'=>VALID_NOT_EMPTY,
> > >                                 'message'=>'Please enter name')
> > >                 )
> > >                 'email'=>array(
> > >                         'no_empty'=>array(
> > >                                 'rule'=>VALID_NOT_EMPTY,
> > >                                 'message'=>'Please enter email'
> > >                         ),
> > >                         'emailchk'=>array(
> > >                                 'rule'=>VALID_EMAIL,
> > >                                 'message'=>'Please enter valid email 
> > > address'
> > >                         )
> > >                 )
> > >         );}
>
> > > ?>
> > > ============================
>
> > > controller file- contacts_controller.php
> > > ============================
> > > <?php
> > > class ContactsController extends AppController {
> > >         var $name = "Contacts";
> > >         var $helpers = array('Form', "Session");
> > >         var $components = array("Email");
>
> > >         function index(){
> > >                  if(!empty($this->data)){
> > >                        $this->Contact->set($this->data);
>
> > >                         if( $this->Contact->validates() ){
> > >                                 //   sending email code here
> > >                                 $this->redirect(array('controller' => 
> > > 'contacts', 'action'
> > > => 'thank_you'));
> > >                         }
> > >                    }
> > >         }
>
> > >         function thank_you(){}}
>
> > > ?>
> > > ============================
>
> > > view - index.ctp
> > > ============================
> > >  <?php echo $form->create("Contact", array("action"=>"index",
> > > "type"=>"post", "name"=>""))?>
>
> > >  Name: <?php echo $form->input('Contact.name', array('type'=>'text',
> > >                                                                          
> > > 'label' => false,
> > >                                                                           
> > > 'size'=>30))?>
> > > Email: <span>*</span></label></th><td><div class="inputWrap">
> > >             <?php echo $form->input('Contact.email', array('label' =>
> > > false,
> > >                                                                           
> > >         'size'=>100))?>
> > >              <?php echo $html->submit('submit'); ?>
>
> > >  <?php echo $this->Form->end();?>
> > > ============================
>
> > > Could someone can tell why ? this is not working??
>
> > > Thanks

-- 
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
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to