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"');


1 comment:

Unknown said...

Usefull ariticle.......