Re: cake cant find model's method!!!
Yes the "join" or "relation" HABTM table uses the AppModel object unless you supply a model name with the "with" option. Ive ran into many problems because of this. On Sep 8, 11:21 pm, Martin Westin wrote: > I am not sure about this but I have a vague memory about reading that > for habtm Cake does not look for any real model unless you specify > "with" in the association. The automagic being that you don't have to > make a real linking model for those simple habtm associations and Cake > does not have to spend time looking for it. > > /Martin > > On Sep 8, 11:18 am, learning_cake_php wrote: > > > WELL WELL..hehe.. nice trick you had ther..i read the manual aboyt > > HABTM's with and kablamm!! it works.. > > so why is cake behaving things like that?they always used the word > > "automagically" but then dont know how to > > automagically interpret the names i used even i followed the > > convention..or maybe i did something wrong somewhere.. > > for now,ill stick with the "with" key..hard to find the bug there(for > > me)... > > thank you guys...deadline is fast approaching..still nid to add auth > > to my project...acos and aros are still > > complicated for me this time..hehe > > > On Sep 8, 12:02 am, Martin Westin wrote: > > > > I agree with the good doctor. > > > One detail you may not realise is that it matters little if if you > > > name the model correctly unless you also specify "with" on the > > > associations... and that you do it from both sides. > > > > Unless you specify "with" and specify the Modelname Cake might be > > > loading AppModel (I believe this happened to me a few months ago even > > > though it shouldn't). > > > > More definite is that you must specify "with" from both sides of the > > > habtm. If you do it only from one side you can be sure the other one > > > is loaded first and Cake chooses AppModel. From that point on there is > > > nothing you can do to bring up the real model since the AppModel will > > > be in the registry. > > > > I noticed this when normal requests worked and shell access was messed > > > up... because the models were loaded in a different order. > > > > /Martin > > > > On Sep 8, 8:33 am, "Dr. Loboto" wrote: > > > > > Output get_class($this->EnrolleesOfferedSubject) in your controller. > > > > If it is AppModel cake cannot find your model file. > > > > > On Sep 8, 10:32 am, learning_cake_php wrote: > > > > > > i already check my model names and codes... > > > > > i have a controller named EnrollmentController and from there > > > > > i used the $uses property for me to user the EnrolleesOfferedSubject > > > > > model.. > > > > > why is it that save,create and delete method works just fine..saves > > > > > and delete to/from > > > > > correct table(enrollees_offered_subjects) but my custom method wont > > > > > work..here is the actual code: > > > > > > //enrollment_controller.php > > > > > > > > > class EnrollmentController extends AppController { > > > > > var $name = 'Enrollment'; > > > > > var $uses = array( > > > > > 'Enrollment', > > > > > 'Student', > > > > > 'EnrollmentPayment', > > > > > 'Enrollee', > > > > > 'OfferedSubject', > > > > > > > > > > 'EnrolleesOfferedSubject', > > > > > 'Major', > > > > > 'Campus', > > > > > 'College', > > > > > 'Course', > > > > > 'Subject', > > > > > 'Program', > > > > > 'Scholarship', > > > > > 'Users' > > > > > ); > > > > > > function subjectView(){ > > > > > $this->setCRUD('subject'); > > > > > > > > > > > $student=$this->Student->isStudent($this->Session->read > > > > > ('Student.id')); > > > > > if(!$student){ > > > > > $this->Session->setFlash(__('Student > > > > > Not Found.', true)); > > > > > > > > > > $this->redirect(array('action'=>'index')); > > > > > } > > > > > > $this->Session->write('Student.id', > > > > > $student['Student']['id']); > > > > > $this->Session->write('Student.full_name', > > > > > $student['Student'] > > > > > ['last_name'] > > > > > > > > > >
Re: cake cant find model's method!!!
I am not sure about this but I have a vague memory about reading that for habtm Cake does not look for any real model unless you specify "with" in the association. The automagic being that you don't have to make a real linking model for those simple habtm associations and Cake does not have to spend time looking for it. /Martin On Sep 8, 11:18 am, learning_cake_php wrote: > WELL WELL..hehe.. nice trick you had ther..i read the manual aboyt > HABTM's with and kablamm!! it works.. > so why is cake behaving things like that?they always used the word > "automagically" but then dont know how to > automagically interpret the names i used even i followed the > convention..or maybe i did something wrong somewhere.. > for now,ill stick with the "with" key..hard to find the bug there(for > me)... > thank you guys...deadline is fast approaching..still nid to add auth > to my project...acos and aros are still > complicated for me this time..hehe > > On Sep 8, 12:02 am, Martin Westin wrote: > > > > > I agree with the good doctor. > > One detail you may not realise is that it matters little if if you > > name the model correctly unless you also specify "with" on the > > associations... and that you do it from both sides. > > > Unless you specify "with" and specify the Modelname Cake might be > > loading AppModel (I believe this happened to me a few months ago even > > though it shouldn't). > > > More definite is that you must specify "with" from both sides of the > > habtm. If you do it only from one side you can be sure the other one > > is loaded first and Cake chooses AppModel. From that point on there is > > nothing you can do to bring up the real model since the AppModel will > > be in the registry. > > > I noticed this when normal requests worked and shell access was messed > > up... because the models were loaded in a different order. > > > /Martin > > > On Sep 8, 8:33 am, "Dr. Loboto" wrote: > > > > Output get_class($this->EnrolleesOfferedSubject) in your controller. > > > If it is AppModel cake cannot find your model file. > > > > On Sep 8, 10:32 am, learning_cake_php wrote: > > > > > i already check my model names and codes... > > > > i have a controller named EnrollmentController and from there > > > > i used the $uses property for me to user the EnrolleesOfferedSubject > > > > model.. > > > > why is it that save,create and delete method works just fine..saves > > > > and delete to/from > > > > correct table(enrollees_offered_subjects) but my custom method wont > > > > work..here is the actual code: > > > > > //enrollment_controller.php > > > > > > > class EnrollmentController extends AppController { > > > > var $name = 'Enrollment'; > > > > var $uses = array( > > > > 'Enrollment', > > > > 'Student', > > > > 'EnrollmentPayment', > > > > 'Enrollee', > > > > 'OfferedSubject', > > > > > > > > 'EnrolleesOfferedSubject', > > > > 'Major', > > > > 'Campus', > > > > 'College', > > > > 'Course', > > > > 'Subject', > > > > 'Program', > > > > 'Scholarship', > > > > 'Users' > > > > ); > > > > > function subjectView(){ > > > > $this->setCRUD('subject'); > > > > > > > > > $student=$this->Student->isStudent($this->Session->read > > > > ('Student.id')); > > > > if(!$student){ > > > > $this->Session->setFlash(__('Student > > > > Not Found.', true)); > > > > > > > > $this->redirect(array('action'=>'index')); > > > > } > > > > > $this->Session->write('Student.id', > > > > $student['Student']['id']); > > > > $this->Session->write('Student.full_name', > > > > $student['Student'] > > > > ['last_name'] > > > > > > > > .", ".$student['Student']['first_name'] > > > > > > > > ." ".$student['Student']['middle_name'] > > > > > > > > ." ".$student['Student']['sur_name'] > > > >
Re: cake cant find model's method!!!
WELL WELL..hehe.. nice trick you had ther..i read the manual aboyt HABTM's with and kablamm!! it works.. so why is cake behaving things like that?they always used the word "automagically" but then dont know how to automagically interpret the names i used even i followed the convention..or maybe i did something wrong somewhere.. for now,ill stick with the "with" key..hard to find the bug there(for me)... thank you guys...deadline is fast approaching..still nid to add auth to my project...acos and aros are still complicated for me this time..hehe On Sep 8, 12:02 am, Martin Westin wrote: > I agree with the good doctor. > One detail you may not realise is that it matters little if if you > name the model correctly unless you also specify "with" on the > associations... and that you do it from both sides. > > Unless you specify "with" and specify the Modelname Cake might be > loading AppModel (I believe this happened to me a few months ago even > though it shouldn't). > > More definite is that you must specify "with" from both sides of the > habtm. If you do it only from one side you can be sure the other one > is loaded first and Cake chooses AppModel. From that point on there is > nothing you can do to bring up the real model since the AppModel will > be in the registry. > > I noticed this when normal requests worked and shell access was messed > up... because the models were loaded in a different order. > > /Martin > > On Sep 8, 8:33 am, "Dr. Loboto" wrote: > > > > > Output get_class($this->EnrolleesOfferedSubject) in your controller. > > If it is AppModel cake cannot find your model file. > > > On Sep 8, 10:32 am, learning_cake_php wrote: > > > > i already check my model names and codes... > > > i have a controller named EnrollmentController and from there > > > i used the $uses property for me to user the EnrolleesOfferedSubject > > > model.. > > > why is it that save,create and delete method works just fine..saves > > > and delete to/from > > > correct table(enrollees_offered_subjects) but my custom method wont > > > work..here is the actual code: > > > > //enrollment_controller.php > > > > > class EnrollmentController extends AppController { > > > var $name = 'Enrollment'; > > > var $uses = array( > > > 'Enrollment', > > > 'Student', > > > 'EnrollmentPayment', > > > 'Enrollee', > > > 'OfferedSubject', > > > 'EnrolleesOfferedSubject', > > > 'Major', > > > 'Campus', > > > 'College', > > > 'Course', > > > 'Subject', > > > 'Program', > > > 'Scholarship', > > > 'Users' > > > ); > > > > function subjectView(){ > > > $this->setCRUD('subject'); > > > > > > > $student=$this->Student->isStudent($this->Session->read > > > ('Student.id')); > > > if(!$student){ > > > $this->Session->setFlash(__('Student Not > > > Found.', true)); > > > $this->redirect(array('action'=>'index')); > > > } > > > > $this->Session->write('Student.id', > > > $student['Student']['id']); > > > $this->Session->write('Student.full_name', > > > $student['Student'] > > > ['last_name'] > > > > > > .", ".$student['Student']['first_name'] > > > > > > ." ".$student['Student']['middle_name'] > > > > > > ." ".$student['Student']['sur_name'] > > > > > > ); > > > > > > > $enrollmentPayment=$this->EnrollmentPayment->isPaid($this->Session- > > > > >read('Student.id')); > > > > if(!$enrollmentPayment){ > > > $this->Session->setFlash(__('Not Yet > > > Paid.', true)); > > > > > > $this->redirect(array('action'=>'paymentAdd')); > > > } > > > > > > > $enrollee=$this->Enrollee->isEnroll
Re: cake cant find model's method!!!
@Dr. Loboto it tried it and unfortunately its AppModel...how can this be?? @Martin Westin: what is "with" in model? is it a model property? how can i use it?(i think i need some further readings) On Sep 7, 11:33 pm, "Dr. Loboto" wrote: > Output get_class($this->EnrolleesOfferedSubject) in your controller. > If it is AppModel cake cannot find your model file. > > On Sep 8, 10:32 am, learning_cake_php wrote: > > > ... > > read more » --~--~-~--~~~---~--~~ 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 cant find model's method!!!
I agree with the good doctor. One detail you may not realise is that it matters little if if you name the model correctly unless you also specify "with" on the associations... and that you do it from both sides. Unless you specify "with" and specify the Modelname Cake might be loading AppModel (I believe this happened to me a few months ago even though it shouldn't). More definite is that you must specify "with" from both sides of the habtm. If you do it only from one side you can be sure the other one is loaded first and Cake chooses AppModel. From that point on there is nothing you can do to bring up the real model since the AppModel will be in the registry. I noticed this when normal requests worked and shell access was messed up... because the models were loaded in a different order. /Martin On Sep 8, 8:33 am, "Dr. Loboto" wrote: > Output get_class($this->EnrolleesOfferedSubject) in your controller. > If it is AppModel cake cannot find your model file. > > On Sep 8, 10:32 am, learning_cake_php wrote: > > > > > i already check my model names and codes... > > i have a controller named EnrollmentController and from there > > i used the $uses property for me to user the EnrolleesOfferedSubject > > model.. > > why is it that save,create and delete method works just fine..saves > > and delete to/from > > correct table(enrollees_offered_subjects) but my custom method wont > > work..here is the actual code: > > > //enrollment_controller.php > > > class EnrollmentController extends AppController { > > var $name = 'Enrollment'; > > var $uses = array( > > 'Enrollment', > > 'Student', > > 'EnrollmentPayment', > > 'Enrollee', > > 'OfferedSubject', > > 'EnrolleesOfferedSubject', > > 'Major', > > 'Campus', > > 'College', > > 'Course', > > 'Subject', > > 'Program', > > 'Scholarship', > > 'Users' > > ); > > > function subjectView(){ > > $this->setCRUD('subject'); > > > > > $student=$this->Student->isStudent($this->Session->read > > ('Student.id')); > > if(!$student){ > > $this->Session->setFlash(__('Student Not > > Found.', true)); > > $this->redirect(array('action'=>'index')); > > } > > > $this->Session->write('Student.id', > > $student['Student']['id']); > > $this->Session->write('Student.full_name', > > $student['Student'] > > ['last_name'] > > > > .", ".$student['Student']['first_name'] > > > > ." ".$student['Student']['middle_name'] > > > > ." ".$student['Student']['sur_name'] > > > > ); > > > > > $enrollmentPayment=$this->EnrollmentPayment->isPaid($this->Session- > > > >read('Student.id')); > > > if(!$enrollmentPayment){ > > $this->Session->setFlash(__('Not Yet > > Paid.', true)); > > > > $this->redirect(array('action'=>'paymentAdd')); > > } > > > > > $enrollee=$this->Enrollee->isEnrolled($this->Session->read > > ('Student.id')); > > > if(!$enrollee){ > > $this->Session->setFlash(__('Student Not > > Yet Enrolled.', true)); > > > > $this->redirect(array('action'=>'enrolleeAdd')); > > } > > > $this->EnrolleesOfferedSubject->recursive = 0; > > //$this->EnrolleesOfferedSubject->unbindModel(array > > ('belongsTo'=>array('Enrollee','OfferedSubject'))); > > > > $this->EnrolleesOfferedSubject->bindModel(array('belongsTo'=>array( > > 'Enrollee'=>array( > > 'foreignKey'=>'e
Re: cake cant find model's method!!!
Output get_class($this->EnrolleesOfferedSubject) in your controller. If it is AppModel cake cannot find your model file. On Sep 8, 10:32 am, learning_cake_php wrote: > i already check my model names and codes... > i have a controller named EnrollmentController and from there > i used the $uses property for me to user the EnrolleesOfferedSubject > model.. > why is it that save,create and delete method works just fine..saves > and delete to/from > correct table(enrollees_offered_subjects) but my custom method wont > work..here is the actual code: > > //enrollment_controller.php > class EnrollmentController extends AppController { > var $name = 'Enrollment'; > var $uses = array( > 'Enrollment', > 'Student', > 'EnrollmentPayment', > 'Enrollee', > 'OfferedSubject', > 'EnrolleesOfferedSubject', > 'Major', > 'Campus', > 'College', > 'Course', > 'Subject', > 'Program', > 'Scholarship', > 'Users' > ); > > function subjectView(){ > $this->setCRUD('subject'); > > > $student=$this->Student->isStudent($this->Session->read > ('Student.id')); > if(!$student){ > $this->Session->setFlash(__('Student Not > Found.', true)); > $this->redirect(array('action'=>'index')); > } > > $this->Session->write('Student.id', > $student['Student']['id']); > $this->Session->write('Student.full_name', > $student['Student'] > ['last_name'] > > .", ".$student['Student']['first_name'] > > ." ".$student['Student']['middle_name'] > > ." ".$student['Student']['sur_name'] > > ); > > > $enrollmentPayment=$this->EnrollmentPayment->isPaid($this->Session- > > >read('Student.id')); > > if(!$enrollmentPayment){ > $this->Session->setFlash(__('Not Yet Paid.', > true)); > > $this->redirect(array('action'=>'paymentAdd')); > } > > > $enrollee=$this->Enrollee->isEnrolled($this->Session->read > ('Student.id')); > > if(!$enrollee){ > $this->Session->setFlash(__('Student Not Yet > Enrolled.', true)); > > $this->redirect(array('action'=>'enrolleeAdd')); > } > > $this->EnrolleesOfferedSubject->recursive = 0; > //$this->EnrolleesOfferedSubject->unbindModel(array > ('belongsTo'=>array('Enrollee','OfferedSubject'))); > > $this->EnrolleesOfferedSubject->bindModel(array('belongsTo'=>array( > 'Enrollee'=>array( > 'foreignKey'=>'enrollee_id', > 'type'=>'INNER' > ), > 'OfferedSubject'=>array( > 'foreignKey'=>'offered_subject_id', > 'type'=>'INNER' > ), > 'Subject'=>array( > 'foreignKey'=>false, > 'type'=>'INNER', > 'conditions'=> array('Subject.id = > OfferedSubject.subject_id') > ) > ) > ) > ); > $this->set('student_full_name',$this->Session->read > ('Student.full_name')); > > $this->set('student_id',$this->Session->read('Student.id')); > $this->set('enrolleesOfferedSubjects', > $this->Enrolle
Re: cake cant find model's method!!!
i already check my model names and codes... i have a controller named EnrollmentController and from there i used the $uses property for me to user the EnrolleesOfferedSubject model.. why is it that save,create and delete method works just fine..saves and delete to/from correct table(enrollees_offered_subjects) but my custom method wont work..here is the actual code: //enrollment_controller.php setCRUD('subject'); $student=$this->Student->isStudent($this->Session->read ('Student.id')); if(!$student){ $this->Session->setFlash(__('Student Not Found.', true)); $this->redirect(array('action'=>'index')); } $this->Session->write('Student.id', $student['Student']['id']); $this->Session->write('Student.full_name', $student['Student'] ['last_name'] .", ".$student['Student']['first_name'] ." ".$student['Student']['middle_name'] ." ".$student['Student']['sur_name'] ); $enrollmentPayment=$this->EnrollmentPayment->isPaid($this->Session- >read('Student.id')); if(!$enrollmentPayment){ $this->Session->setFlash(__('Not Yet Paid.', true)); $this->redirect(array('action'=>'paymentAdd')); } $enrollee=$this->Enrollee->isEnrolled($this->Session->read ('Student.id')); if(!$enrollee){ $this->Session->setFlash(__('Student Not Yet Enrolled.', true)); $this->redirect(array('action'=>'enrolleeAdd')); } $this->EnrolleesOfferedSubject->recursive = 0; //$this->EnrolleesOfferedSubject->unbindModel(array ('belongsTo'=>array('Enrollee','OfferedSubject'))); $this->EnrolleesOfferedSubject->bindModel(array('belongsTo'=>array( 'Enrollee'=>array( 'foreignKey'=>'enrollee_id', 'type'=>'INNER' ), 'OfferedSubject'=>array( 'foreignKey'=>'offered_subject_id', 'type'=>'INNER' ), 'Subject'=>array( 'foreignKey'=>false, 'type'=>'INNER', 'conditions'=> array('Subject.id = OfferedSubject.subject_id') ) ) ) ); $this->set('student_full_name',$this->Session->read ('Student.full_name')); $this->set('student_id',$this->Session->read('Student.id')); $this->set('enrolleesOfferedSubjects', $this- >EnrolleesOfferedSubject->find('all', array( 'conditions' => array( 'EnrolleesOfferedSubject.enrollee_id' => $enrollee['Enrollee'] ['id'], 'EnrolleesOfferedSubject.campus_id' => $this->Enrollment- >campusId, ) ) ) ); } function subjectResult(){ Configure::write('debug', '0'); $this->setCRUD('subject'); $searchKey=trim($this->data['searchKey']); $student=$this->Student->isStudent($this->Session->read ('Student.id')); if(!$student){ $this->Session->setFlash(__('Session has expired. Please click done and try again.', true)); }elseif (!empty($searchKey)){ $this->OfferedSubject->recursive = 1; $this->set('offeredSubjects', $this->OfferedSubject->find ('all',array( 'conditions'=>array(
Re: cake cant find model's method!!!
With such names I better check code and model filename for misspellings. I guess that this model filename should be enrollees_offered_subject.php Remember, that if cake do not find file with model it loads AppModel instead. And if model name is conventional and table exists, all seems normal until use associations / call custom methods -> that obviously do not work. P.S. I can swear that all your long post is completely unrelated and only real name of model have sense. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
cake cant find model's method!!!
well here i am again..actually i removed the original post and edited it so that it will be clearer to all of us: here we go: i just try to explain the problem after theses snippets of code: db structure: 1. model1 -id 2. model2 -id 3. model1_model2 -id -model1_id -model2_id model: class Model1 extends AppModel{ var $name='Model1'; ... ... ... function model1Method(){ } } class Model2 extends AppModel{ var $name='Model2'; ... ... ... function model2Method(){ } } class Model1Model2 extends AppModel{ var $name='Model1Model2'; ... ... ... function model1Model2Method(){ } } controller: class MyController extends AppController{ var $uses=array('Model1','Model2','Model1Model2'); function dispModel1(){ $this->Model1->model1Method(); //works fine } function dispModel2(){ $this->Model2->model2Method(); //works fine } function dispModel1Model2(){ $this->Model1Model2->model1Model2Method(); //doesnt work.. error: SQL Error: 1064: You have an error in your SQL syntax } } --- so the problem is cake cant find the model's method instead cake executes it as an sql query. the actual name of my model is EnrolleesOfferedSubject with a table name of enrollees_offered_subjects.. why is it that cake cant find any method i placed in my EnrolleesOfferedSubject model? is it maybe because of my models name? because other model with only one word on it works just well... and one thing, EnrolleesOfferedSubject's model methods can be executed using EnrolleesOfferedSubjectController only but cant be executed OnAnyOtherController... please help me guys..enlighten me..im really stuck! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---