Bookcafe

Showing posts with label CakePHP. Show all posts
Showing posts with label CakePHP. Show all posts

Thursday, October 11, 2012

Upgrading or Migrating From CakePHP 1 to CakePHP 2

It has been long time after my last posts on CakePHP and a lot of latest improvements have been carried out at the latest CakePHP 2. You could find the details regarding the migration especially involving the naming convention and you can read it here http://book.cakephp.org/2.0/en/appendices/2-0-migration-guide.html.To my findings, when doing the basic application using this latest version, do not move or alter the following files or otherwise you will get errors messages:

1. /app/model/AppModel.php
2. /app/controller/PagesController.php

Once you have successfully setting the new version, you will get the screen below:

If you had followed my previous posts on CakePHP version 1.3, in the latest version CakePHP, you must change the following:


1. syarikats_controller.php   to  syarikatscontroller.php

2. var $scaffold;   to   public $scaffold;



Sunday, August 1, 2010

CakePhp : Three Basic Functions

From all my readings, I found out there are three basic codes for functions in CakePhp as to are to add, to edit and to delete data. The codes are all similar in all the books that I have read. All these functions are put into
models_controller.php files.

//To save/add data

function add()
{ if (!empty($this->data)) { $this->Modelname->create(); if(!!$this->Modelname->save($this->data)) { $this->Session->setFlash('Your data is Saved!', true); $this->redirect(array('action'=>'index')); } } }

Wednesday, April 14, 2010

Customise CakePhp View Part 2 - Validation

We need to validate the data sent to the database so that it will be the correct,usefull and required by us and most important thing it will prevent spamming. To do the validation, and again using my example-please refer to the previous post, we could use the following steps:
1) Open syarikat.php file located in Models directory
2) Paste the following codes:

So, what do this code telling us-this question must be pop-up from your mind right now? Actually, this code validate the S_Name (1. the company name) and S_Email (2. the company email address) entered by users as shown below.
If users entered data that are not in accordance with the condition stated by us, the following errors will be generated.
There some other customizations that I have included in the code above. The first one is that I make my own error messages and secondly, in email field, where I have make a requirement that users need to enter a valid email and the users can also left it empty depends on the person choice. If I don't put the allowEmpty in the code, users are forced to enter their email address even though they don't have any email addresses to proceed to the next steps.

Thursday, March 11, 2010

Customise CakePhp View Part 1 - In My Case



As I said ealier, we can customise our CakePhp according to our own needs.
At the picture above, to remove the section that I have given the number 1 and 2. The following are the steps on how you can do that.

1. To remove 1, you need to create a ctp called default.ctp file and place it in app/views/layouts/

Example of a ctp file can be :

2. To remove 2, you need to change the value of 2 to 0 at line begins with Configure::write('debug', 2); to Configure::write('debug', 0); in app/config/core.php
You can find the meaning of the number in this file.

The end result of the CakePhp view will be as follows:

Monday, March 8, 2010

Simple CakePhp Application - Example

There are about three steps in doing this:

Step 1. Create a datebase and tables and dont forget to insert data into the tables->The name for the tables must be in plural form.

Step 2. Create a php file in app/models directory

- for example syarikat.php->the name of the file must be in singular form

- the code:

class Syarikat extends AppModel
{
var $name = 'Syarikat';
}
?>

Step 3. Create a php file in app/controllers

- for example syarikats_controller.php ->the file name must be filenameplural_controller.php

- the code:

class SyarikatsController extends AppController
{
var $name = 'Syarikats';
var $scaffold;
}
?>

Note: the scaffold variable is use when there is no app/view .thtml file.

The scaffold variable automatically create index.thtml, add.thtml, view.thtml and delete.thtml

If you need to create your own view, process or layout, you can ommit the scaffold variable.

To access your application from browser (in my case)

type at your browser:
http://localhost/cakephp/syarikats

If your get this error (in my case):

Notice (8): Undefined index: id

Then, you must name your first field in the table as ID and make it auto increment.
Example when creating your database
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY

The view of my first application from the browser



Of course you can customised this view according to your needs. For that, I will show to you all in the near future.

First Installation Page of CakePhp 1.6

This is the first page of CakePhp 1.6 after installation.


After the installation, you need to change following:

1. 'Security.salt' in app/config/core.php

2. Rename config/database.php.default to config/database.php

Please read the instructions on the first page to what need to be changed.

It doesn't really matter what the value of the 'Security.salt', as long as it's not easy to guess. You could use an online SHA1 hash generator tool to generate a new long key like what is there by default.

After these steps, you can directly access your database (provided you have set up your database before hand).

If you have successfully edited the files, you should get the following:

Wednesday, February 17, 2010

CakePHP 1.2.6 New Release

It is stated in the cakephp.org that the new release of cakephp 1.2.6 is now available for download. This release includes more than 160 commits improving performance and fixing more than 75 related tickets. Visit cakephp.org for details.

Sunday, December 20, 2009

My First CakePhp Application

I finally managed to create my own application using the CakePhp. I had tried using CakePhp 1.3 but it gave me problem at the URL where it changed the parameter from 1 to id:1
With that, I tried using CakePhp 1.25, all problems had gone.

Friday, December 18, 2009

My First Experience with CakePhp

I start with the installation process and then do the configuration.

1. Download CakePhp from http://www.cakephp.org and follow the "Download Now" link.
2. Unpack the contents of the Cake archive into /var/www/html however it depends on what web server you use. For example, if you use WAMP (I have been using it since working in ILP), you must unpack it into /wamp/www/
3. After you unpack you should have the following directories or files:
/cake_1_2
--->/app
--->/cake
--->/vendors
--->/.htaccess
--->/index.php
--->/README
4. Now, lets do the configuration processes.Nothing much steps involve except the mod_rewrite must be set up in the Apache configuration files.

First Kick-Off - CakePhp Initialization:

I got the following errors:

Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\cake_1.2.5\cake\libs\inflector.php on line 131

Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\cake_1.2.5\cake\libs\configure.php on line 136

Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\cake_1.2.5\cake\libs\configure.php on line 226

Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\cake_1.2.5\cake\libs\configure.php on line 906

Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\cake_1.2.5\cake\libs\configure.php on line 946


Now it is time to "Google" ing....keep it up map....

Ok now I know the solution after doing some googling..

Fist solution : Downgrade WAMP to its previous version
Second solution : Upgrade CakePhp from 1.2 to 1.3

So, I choose the second solution since I dont want to mess up with my other PHP Projects in current WAMP version.