Help with button and link

Hello,

I am using yii version 1.1.13 that a developer used to build an online reservation system for our company. I am no programmer by any stretch of the imagination, but have been slowly learning about the yii framework.

I am having a problem understanding/figuring out a piece of code that I have where I want to display a button that, when pressed, will display a static php page (about.php->located in the pages folder. Here is the code:


<p><?php $image = CHtml::image(Yii::app()->request->baseUrl.'/images/EventButton.png'); 

echo CHtml::link($image,array('Event/index')); ?> <b>to view our upcoming events.</b></p>

</ br>

<p><?php $image = CHtml::image(Yii::app()->request->baseUrl.'/images/EventButton.png'); 

echo CHtml::link($image,array('pages/About')); ?>About Us</p>

</ br>

<p><?php $image = CHtml::image(Yii::app()->request->baseUrl.'/images/EventButton.png'); 

echo CHtml::link($image,array('Event/index')); ?>This is a test</p>

</ br>

There are three buttons on top of each other (I just copied and pasted). The first button works and ā€˜points’ to the correct page/function…however, the second button is the one I am having issues with. What am I missing in the code of the second button to ā€˜point’ it to display the about.php page? It is driving me crazy because I know it is probably something simple (I hope).

Thanks for all your help and expertise.

What are U getting from this second button, asking cause this looks like bad formed URL. Also how U paste it here (ā€˜pages/About’) is pointing to PagesController/actionAbout, but action name should be lowercase like ā€˜pages/about’.

1 Like

Thanks for the reply…

All I am trying to accomplish is a ā€˜simple’ button link to a static php page I have placed where all static php pages should reside(according to what I have read): ../protected/views/site/pages/about.php

The standard HTML code of what I’m trying to do would look like: <a href=ā€œthe-page-i-want-button-to-link-toā€><img src=ā€œbutton_image_file.jpgā€></a>

Thanks.

There is very good wiki about this sort of thing - By Example CHtml, http://www.yiiframework.com/wiki/48/by-example-chtml/ .

In this case you would want something like…

$path = Yii::app()->request->baseUrl.’/images/’;

$button = CHtml::image($path.ā€œbutton_image_file.jpgā€, ā€˜ALT’);

echo CHtml::link($button, array(ā€˜site/page’, ā€˜view’=>ā€˜about’));

This is the url you’re trying to get

http://localhost/test_app/index.php?r=site/page&view=about

and you can get it from a code line like this

ā€˜url’=>array(’/site/page’, ā€˜view’=>ā€˜about’)),

I agree with newbiedo find that wiki and read it cause these are fundamental issues to write a good code

I hope this can be a help for you… Don’t stop communicating… bring some feedback to the forum

Thank you everyone who replied…thanks for the link to the YII resource, I’ll use it. Thanks again for the help I do appreciate everyone’s expertise.