Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Scaffolding in CakePHP

. Monday, June 9, 2008
9 comments

What is scaffolding?
Its something that you will find very useful in production apps. When you begin, you may want to throw up stuff real quick in order to get started. Ultimately, its a built in system for adding, editing, viewing and deleting your database records quickly.

Database table
Suppose we want to work with a table named users, and here is its SQL structure

CREATE TABLE `users` (
`id` bigint(20) NOT NULL auto_increment,
`username` varchar(50) NOT NULL,
`name` varchar(50) NOT NULL,
`email` varchar(96) NOT NULL,
`password` varchar(50) NOT NULL,
`updated` int(11) NOT NULL,
`created` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
)

Model
Now lets create a model file first. It should be placed here: /app/models/user.php
<?
class User extends AppModel
{
var $name = "User";
var $uses = "users" // table name
}
?>


Controller
Create a controller file here: /app/controllers/users_controller.php
<?
class UsersController extends AppController
{
var $name = 'Users';
var $scaffold;
}
?>

View
Not required since the views for scaffolding are generated by CakePHP automatically.

Visit http://yoursite.com/users/ and start scaffolding.
Note: Always visit yoursite.com/controllerName/ to see the visual output of your controller.

I will show you a user registration and logging system in CakePHP soon.

Installing Apache, PHP, MySQL in Windows

. Tuesday, May 27, 2008
1 comments

WAMP
W
indows Apache MySQL PHP. There are a few WAMP installers out there including EasyPHP and WampServer (XAMPP for Mac). I prefer WampServer since it comes with an easy to use service manager as a tray icon. The service manager allows you to choose versions and manage all the extensions (modules) of apache, php, and mysql. This way, you don't even have to edit any configuration files manually. You cant get it any easier!

Download and install WampServer
Download WampServer from their website.
http://www.wampserver.com/en/download.php

WampServer can be downloaded from SourceForge too
http://sourceforge.net/projects/wampserver/

Now run the installer and follow the instructions. Its better if you do not install it in C: drive (where you have Windows installed).

You are now ready to run your php files
Now open your browser, and visit http://localhost. This is the host that runs in your local machine. Click on the WampServer tray icon, then click 'www directory'. Now if you place a file named 'test.php' in that directory, you can run the file from your browser using this link http://localhost/test.php.

For managing your MySQL databases using phpMyAdmin, visit http://localhost/phpmyadmin.

Hope that helps :)

Your Workspace

.
0 comments

I am going to introduce you how to set up a workspace where you will be able to manage your web projects.

Webpage Editor
When it comes to a software to edit your webpages, Dreamweaver is the first choice. The latest version CS3 has got a nice user friendly interface, and its really very easy to use. But you have to pay a few hundreds of bucks for that. If you want a free editor, then I would recommend you to use Notepad++. Its open source as well.

Photoshop
There is nothing as useful as Photoshop. It simply rules. Even though it will cost you a few hundreds, its worth buying it. The latest version Photoshop CS3 Extended even lets you export (slice) your layout in CSS which makes a designers life a lot easier.

Server
If you are a PHP/MySQL developer like me, then you have to install Apache, PHP, and MySQL in your computer for testing your web applications. Its also necessary to install phpMyAdmin for managing your mysql databases. (I will show you how to install them in my next post)