Sunday, January 24, 2010

Basic Stature of CakePHP and rules

Now lets discuss about some rules and mvc framework stature of cakePHP, for create a database application we need to follow bellow things

1) define data model
2) controller file : here we are writing database queries
3) and query results

Table & field name convention

1)create your database
2) table name : lower case, plural, multi-word tables to be separated by underscore
Example : table name articles
3) Each table must have one primary key to named id ( auto increment not null)
4) filed name : lower case can use under score for separation and multi-word field
4) and related table names

Model name convention

Model class name are camelcased and singular ( like article , MyClass etc) it should be database table name
Model file names are lower case, multi – word class is to be separated by underscore
Model files are saved under app/models folder


Saturday, January 23, 2010

Creating Static Pages and Linking in CakePHP

Now i am going to create sub page( statics) and linking each other for that i created about_us.ctp file under "pages" folder and going to give link from home - to about_us and from about_us to home.

and on about_us.ctp use bellow php code
< ? php $this->pageTitle = 'About us page';
? >

It use to select custom title and you can browse that about_us.ctp like " http://localhost/cake/pages/about_us " ( * i am using XAMPP )

Note : when you create other page name try to use "_" underscore like about_us.ctp

Creating Links

Syntax of link
< ? php echo $html->link('Link Text', 'Link URL'); ? >

In html we use < href = " http://www.westwideway.com "> West Wide Way < / a > to create links but in cake it is different.

< ? php echo link('West Wide Way', 'http://www.westwideway.com'); ? > but out put will display like above html link

to apply css in link please use bellow syntax

< ? php echo $html->link('westwideway', 'http://westwideway.blogspot.com', array('class'=>'linkstyle')); ?>

and linkstyle css tag we can add tag in our css put style under that

To link in next page

< ? php echo $html->link('westwideway', 'http://westwideway.blogspot.com', array('class'=>'linkstyle','target'=>'_blank')); ? >

To link in next page with a aleart message box

< ? php echo $html->link('westwideway', 'http://westwideway.blogspot.com', array('class'=>'linkstyle','target'=>'_blank'),"Do you want to visit this website?"); ? >

these are the different types of link now i am going to put links on my two pages

in home.ctp added : < ? php echo $html->link('About Us', 'about_us'); ? >
and in about_us.ctp : < ? php echo $html->link('Home', 'home'); ? >

Now links are working fine can browse each pages through that .

To insert image : $html->image()

$html->image('logo.png', array('width' => 500, 'height' => 300));

If you don’t want to type that much there is a little trick: use a string as second parameter. With that trick the previous example can be shortened to:

$html->image('logo.png', 'width="500" height="300"');


Cook a Custom CakePHP Template

You have seen bellow messages in the welcome screen has changed after each of your action.

Editing this Page

  • To change the content of this page, create: APP/views/pages/home.ctp.
  • To change its layout, create: APP/views/layouts/default.ctp.
  • You can also add some CSS styles for your pages at: APP/webroot/css.
Creating a default home page

To create a default home we need to create a folder named "pages" under app/view/ and put file name "home.ctp" your can write anything on that page it will display there.

use cake php file extension as .ctp use and text editor and save file as .ctp

Creating layout

under under 'app/views/layouts/' folder create a "default.ctp" file
now it will display a blank page - to see content and to give link do following things


Please copy paste above code to defalut.ctp now you can view layout i marked some things in red mark now , Page title is "First Test"

  1. $title_for_layout
  2. $scripts_for_layout
  3. $content_for_layout
  4. $cakeDebug
$title_for_layout : that must comes in between title tag , it is helps you to put default title in all pages amd also can put custom tilte like "First test"

$scripts_for_layout : will come under header part helps you to put scripts

$content_for_layout :that must come under body


$cakeDebug : will put after body

now echo $html->css('style'); : creating a css named style.css file and this file can placed under
APP/webroot/css.

Now you can view bellow layout , and i made it please try your self with differnt design



Framework and CakePHP

Framework and CakePHP

As a programmer I used to develops code in php and many languages but faced lot of security issues in my codes discussed with my friend regarding this he advised me to do codes in framework, ( web application framework is a software framework that is designed to support the development of dynamic websites, Web applications and Web services. )

Architectures of Framework

Model view controller (MVC)

I think most of the framework following MVC ( model view controller ) pattern means data model with business rules from user interface, and it is multiple interface stature.

Advantages
1) Security
2) Data access and mapping
3) URL mapping
4) Web template system
5) Automatic configuration

and i started to learn cake php,

Cake php

CakePHP is an open source web application framework with MVC architecture, you can download frame work from " http://cakephp.org/ " : website .

you will get help notes from : http://book.cakephp.org/ website .

i downloaded from cake php site i am using "XAMPP" for mysql and Apache , and put under "htdocs" folder so i can browse ,


Yellow mark showing errors and green mark showing working fine.

Under yellow mark i got bellow errors

  • Notice (1024): Please change the value of 'Security.salt' in app/config/core.php to a salt value specific to your application [CORE\cake\libs\debugger.php, line 682]
  • Your database configuration file is NOT present.
  • Rename config/database.php.default to config/database.php

Under Green Mark
  • Your tmp directory is writable.
  • The FileEngine is being used for caching. To change the config edit APP/config/core.php

To solve first error : under app /config folder take core.php file we can view a on 165th line bellow code :
Configure::write('Security.salt', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');

Plz change 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi' this code 'ADjsdfssd454asdfsdfsdfsdf' i put above code now , first error solved . it is code some what similar to API codes

Next step is database setup for that : for that create a db in mysql i crated "cakeapplication" named database after rename the file to "database.php.default" to "database.php" open that file and fill the details of dbname, dbhost, and password which you created

Now your cakePHP ready for create application