Tuesday (day 2)
I really hate to start working early in the morning. I’ve always trying to delay this step by reading some news, checking mails, etc. But job need to be done and I had to go downtown, so I’ve started early today.
Building external user interface
I’ve started with the external user interface, incl. login, logout, change passwords, I’ve also decided to move fields Name and E-mail from this page to the profile page etc. Most of the things went quite well, but there were some “problems” with autoRedirect var in the Auth component. Well they weren’t real problems, but wrong redirects while the user switch from profile to another /i.e. admin to regular user/. To avoid this I’ve decided to set that variable to false, and the login redirect will be fixed to a landing page. Anyway, the application is not so big and keeping the last place is not very critical. 🙂
Working with HABTM interface
Today I had some of these thoughts like “hm, this should work, but why it doesn’t?”. I am working with CakePHP from some time /look like almost 2 years :)/, but I didn’t notice that the table names in HABTM relations are so critical when it’s used Cake Bake script.
What was the problem?
As I mentioned in the previous post, I need to do HABTM relation between profiles and languages as well as profiles and fields of knowledge, so I’ve created these 2 tables, but instead of plural names I’ve set plural only the second table, so the table names were like profile_categories and profile_languages.
Well, at first glance everything was ok, but the HABTM detection in bake script was only between categories and profile_categories. I thought that the order was the problem, so I switched the names and I had category_profiles and language_profiles. The result was that HABTM wasn’t detected and I’ve been surprised. Well it can’t be, so simple, I thought, and the third attempt give me the proper results. The right syntax for HABTM tables should be plural_plural, so in my case it was languages_profiles and categories_profiles.
Point taken: you need to stick to Cake convention if you want less work 🙂
Creating the Profile form and problem with the security component
Building the many-to-many interface lead me to building the whole profile page. I’ve decided to split the form into four sensible parts /well, it was required in the specification of the project, so I just need to do it/. The tabs are:
- Common contact information
- Fields of knowledge
- Additional information
Back to the PHP coding…
Surprisingly, but when I’ve submit the profile form, I’ve got the blank page result. It was quite strange, because I couldn’t run any debugging code in the controller /like print_r, echo etc./ – I’ve got totally blank page. Look like the problem is somewhere in the core.
Digging into it I’ve remembered that I had the same problem in the past with the Security component and I decided to comment it in the app_controller file. Voilà the form get submitted successfully! I’ve commented some of the $form->input helpers – these which I transformed from select to radio and it was working again.
I don’t know where is the problem, but it’s strange. For me security component should look and should create the key pairs from the helper and not from the database fields. I need to dig into this problem, but so far I had to skip it. For now I’ve decided to leave the security component enabled for the User’s controller only, because it’s most important there /once the user is logged you can track his activities/ and I will leave all other interfaces without it.
Today, I’ve also build a helper which drawing the categories – fields of experience, as well as I’ve transformed the languages_profiles HABTM multiselect box to checkbox set. The form requires some styling, validation and most of the work for the external part is done.
Conclusion of the day:
Although these problems I am progressing quite good.
You can see also:
Building cake application (Part I)