Category Archives: Frameworks

Building cake application (Part V)

Friday (day 5)

Constructing SQL statement for the search
Yep, today I need to finish the Profile search for the admin part. As I mentioned, the search is only by fields of experience, so there is no big and scary where clause /especially if you want to cover all cases, like splitting the words with AND, OR etc. will cause huge where with all possible combinations/.

There are 2 specific requirements here: The results need to be ordered by relevance and the report need to show fields of competence which are match to the search criteria next to each row /user/.

What does it means? Let’s say there are 2 users. First one has following skills like Java, PHP, MySQL, HTML and JavaScript, the second one knew only JavaScript and HTML, so when we search for users matching criterion PHP and HTML, the search results need to be ordered like this:

User1 – matching fields: PHP, HTML – relevance 2 criteria matched
User2 – matching fields: HTML – relevance: 1 criteria matched
and so on.

At first glance it look like I had to build huge SQL including few sub queries or functions for fetching the fields of relevance and matching fields and I was prepared for at least one day to accomplish this task, but in fact it was very fast.
Continue reading

Building cake application (Part IV)

Thursday (day 4)

Today I need to go downtown again. I am quite unhappy, because this mean that I need to work extra later on, but there are priorities, as you probably know. Here is what I’ve done today.

Working on the administration part
Today, I’ve worked on the administration part. There are some small bugs and glitches which I needed to clear in the Key look-up tables such as, stripping down the Categories functionality – this application requires only 2 levels of nesting in the Fields of experience, so allowing the extra levels will confuse the customers.

fixing some bugs in the front end as well
I’ve still have troubles with the redirects in the Auth component. I know it’s all my fault but it’s really annoying. I need to check what exactly is the problem with this. πŸ™

Adding delete all related records to the external user’s profile
Back to the admin part. I needed to implement delete all related records interface – if an admin user decide to remove an External user profile – let’s say someone try to test the application, or just an appropriate user /spammer/ this action should delete all relative records to that profile.

The problem was that I thought that key node is ‘dependent’ while the right one is ‘exclusive’. So, it’s set to true in the hasMany, hasOne etc. and if the parent record is deleted all records in the child tables are deleted too.
Continue reading

Building cake application (Part III)

Wednesday (day 3)

Adding dynamic pages
Today, I’ve decided to add some extra functionality to the application by adding a dynamic pages functionality. The main reason why I did this was because this system needed an “About the application” page as well as other pages and I’d preferred to leave this task to the clients. I also think that with small effort I am giving good impression to the client.

Instead of replacing fully the pages controller, I’ve decided to leave them due to use them for some system pages such as, “Thank for registration” and some other simple pages which are required.

Simple horizontal menu
Added a very light horizontal menu. I like it because it’s really small and works perfect for 1-2 level menus.

Using textile for formatting
I’ve decided to use textile for the formatting of the dynamic page’s content. There is a solution with behavior class, but I found a helper solution, so the installation and configuration was quite easy. I’ve also find a nice help description which briefly explains how to use textile format which I placed above of the page content field.
Continue reading

Building cake application (Part II)

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. πŸ™‚
Continue reading

Building cake application (Part I)

Monday (day 1)

In that post these posts I am going to describe my working process and problems which I’ve met during the development of small CakePHP application. I am not going to go in details neither I will post any code snippets. It will be something like diary of the working process. So, let’s start.

The scope
It’s an Experts database with 2 parts:

  • External part – where all users could register and fill their resumes and field of qualifications
  • Administration part – administrators could provide the search in the resumes and mainly in the field of knowledge.

Continue reading

Check your settings while migrating Cake projects

Today I decided to restart the work of a project. The restart includes migration on the other machine as well as updating the Cakephp lib with the final version on the server.

So I copied the whole directory of the project on the second computer /which meant to be the server from now on/ and after this in the cake directory and typed “svn update”. There were some changed files and I received the latest version on the server. So far, so good.

Then I migrated the DB as well, but I decided to follow a new name convention for databases – all database names to follow the full server name i.e. for mydomain.com I would have a mydomain_com /because MySql doesn’t allow dot in the name I replaced dot with underscore/. on the old computer the database was called “mydomain”.

Ok, I changed /app/tmp permission and I decided to see what was the impact of all these actions.

Surprisingly I’ve seen blank screen instead of application screen. I said myself “sh*t, what’s happened? Does the svn update ruin everything? Am I using too old code style?”. Start digging into the code, but whatever I made there wasn’t any change on the screen. Really odd situation. do I found the second “BIG” bug in the cakePHP lib :D, well not true. Here is the explanation.

Finally after 1/2 hour I realized that I’ve changed the name of the database and the old database name doesn’t exist on the server :D. I agree, it’s stupid error and it’s all my fault, but I am wondering why there is no error message telling, that there is no such DB on the server or similar?

I know that on the home.ctp page, which is the default page when you checkout cake from the repository where you can see if the app is connected or not, but what’s happen, when you don’t use this page? Or even as it is in my other project when I rewrite the page controller and I cannot access the default start up page at all?

I think there should be a way which could notify the developers for such stupid “error” or misconfiguration. At lease if the debug level is set to 2 or 3 it should warn I guess.

The dummy mistake while coding

No body is insured from stupid mistakes while writing code. I am not insured, but subscribed for such things. πŸ™‚

Here is the story:
Yesterday, while I was working for a small project I lost 1 hour to detect the stupidest mistake I ever made. Here I will explain what happened and how dummy I fee after that.

I am writing an application where users insert records into the database, and after that on every show of the record, there is a counter field which need to add up the number in it. Simple and easy situation.

While I was working I noticed that only one record /from 5 in the database/ got updates on his counter fields. All other had 0, while I was petty much sure that I’ve seen all these records on the screen. Well, I forced showing the 0 rows but the result was the same. Then I start investigating what could be the problem, but in the database everything was just fine. I deleted all records and started inserting texts /because there are some text fields important in this story/ one by one. Strangely, but again some of the records got update, some not. Finally /by accident/ I noticed, that counter changes when there is a space before or in the end of the value of the text I entered.
Continue reading

Yet Another Multicolumn Layout (YAML)

Today I found a nice CSS framework which claim to solve the multi-column layout issues which everyone of us meet during the construction of the web site design.

Actually I am speaking about YAML – Yet Another Multicolumn Layout. At first time I mix it with Yaml.org, but actually it’s a different thing. It’s a set of CSS files + few image files which would sort the issues with multi-column layouts.

The benefit is the availability of good documentation and nice examples.

Hope you found it helpful.

Using more than one database connection in CakePHP

Probably is pretty obvious for most of the advanced users, but when I started my experience with CakePHP I read a lot of configuring a database, but not multiple ones. There are articles how to use database for development and for production without changing anything but rewriting a function in DATABASE_CONFIG class.

These days we need to choose way of splitting the functionality and we have to decide: Shall we use different databases or shall we put a prefix for every table. So far we choose to use prefix, but I dig into this and I realized that every model could be attached to different database.

Here is the example how to do this:
Continue reading

Security Issue in CakePHP

I notice this recently when we start creating the security component of a project. The best way to explain the issue is to give an example:

Imagine that in your application you create an action “edit profile” where each user can change his personal details for the account. If course there will be fields for changing user’s real name, password, email etc., but the username field should be readonly.

The direct approach to create such page is to reuse “edit” action of the user’s controller, but instead of getting the ID from the url, it need to be fetched from the session’s auth variable. The second thing which you have to do is to remove “username” field from the view and you are done. πŸ™‚ Well, fast and easy, but not very secured…
Continue reading