Category Archives: CakePHP

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 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

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

Filtering component for your tables

Update: The version of the component here could be outdated. Please get the actual version of the component from GitHub

Well, probably you wont believe me, but I wrote whole 3 pages while I realized that it’s so long and probably this is not the right way /and definitely it’s not easy/, so I scratched everything and start over.

It’s been quite long time since I post an article for CakePHP so here it is – shiny brand new post πŸ™‚

This post is more a method how to make filtering, rather a rocket science component, because it’s possible to be used even without extra classes /helpers and components/, but I will post a component which will tune the functionality.

So what is all about? Have you ever miss a filtering functionality in your index actions? Well I really miss it πŸ™‚

What is the best technique to make filter?
In this example there is a controller Countries which handle the countries in the application. table contain 3 columns, ID, NAME and CODE. Code column is numeric in this example and it’s not following any real naming or country convention.
Continue reading

11 Things which every developer would do when starting a new project

For every project which is going to be started there are at least 11 things which you need to do before. Here is my list of things which need to be happen before starting any project. During my work experience I’ve started many projects and I think that these are the most important issues which you need to do before start the project.
Continue reading

CakePHP and Oracle – Handling CLOB fields

New year – new behaviour πŸ˜€

Everyone who had experience in Oracle and some frameworks /or at least ADO libs/ experienced the problem of ORA-01704: string literal too long. For the people who hadn’t pleasure to work with oracle – Oracle accept strings in SQL to be not longer than 4000 characters. I always had problems with this issue, because when the sting is too long you need to treat it with oracle variables and binding them in strange way /at least not with ordinary SQL/. The only way found so far is the solution of ADOdb library.
Continue reading

Using different Date and Datetime format in CakePHP 1.2

This is a really old post. I’ve wrote a new one which you can find it here.

Here I would like to show you a behaviour which will help you to handle different date format than yyyy-mm-dd supported from the database. The reason why I created this behaviour is because in most of my projects I had a requirement to display the date format in human readable format.

So, without extra words here is the behaviour class /Update: thanks to Shark from the comments below we have datetime support as well/:

Continue reading