Display hello world string

Hi,

I am new to Yii,

I am trying to display "Hello World" string using Yii framework(using command prompt,not with gii)

I tried this using chapter 2 of Yii

I created the website, but got stuck in displaying the string("Hello World") on the web page.

When I click on View link the page should display "Hello World" and when I click on Edit link the text

should get edited.

But when i am trying to click on view link a blank page is being displayed…

Can anyone help me out in solving this…

first specify what and where you have code for these .

for showing "Hello World" in your view file do the following ,


echo "Hello World";    // in your view file


and rander that page in controller function actionView() like ,


$this->render('view',array(

			'model'=>$model,

		));

Thank you,

Now I am adding the code of view and controller

please check it out

show.php

<?php

$this->breadcrumbs=array(

'Message'=&gt;array('message/index'),


'Show',

);?>

<?php $this->pageTitle=Yii::app()->name . ’ - Show Message’; ?>

<p><?php echo CHtml::link(‘Back’, array(’/message’)?> </p>

<h1>View Hello World Message</h1>

<p>

<?php echo $message->author; ?>

  • "

<?php echo $message->message;//echo "hai";die;?>

"

</p>

MessageController.php

<?php

class MessageController extends Controller

{

	public function actionShow()


		{


		


			// create a new instance of MessageForm model 


			&#036;message=new MessageForm; 


			


			/* 


			* check to see if the MessageForm fields were filled in 


			*  


			* If they were, then print out the message and author 


			* with the show render - based on what the user inputted 


			*  


			* If not, then print out the default hellow world and  


			* default author with the show render. 


			*/  


				if(isset(&#036;message-&gt;message)) 


								


				&#036;this-&gt;render('show',array('message'=&gt;&#036;message)); 


				else 


					{ 


						


									


						&#036;message-&gt;message = &quot;Hello World&quot;; 							


							


						&#036;message-&gt;author = &quot;Default Author&quot;; 


						


						&#036;this-&gt;render('show',array('message'=&gt;&#036;message));


									


					}


			}





			public function actionError()


				{


					if(&#036;error=Yii::app()-&gt;errorHandler-&gt;error)


						{


							if(Yii::app()-&gt;request-&gt;isAjaxRequest)


								echo &#036;error['message'];


							else


								&#036;this-&gt;render('error', &#036;error);


						}


				}


			


	 public function actionEdit()


		 {


			// create a new instance of MessageForm model 


			&#036;message=new MessageForm; 


			/* 


			* check to see if All the fileds are filled in on the form 


			* if so proceed to assign the values to the variables in the message model (author and message) 


			*  


			* If they validate (no errors) then render the show page with the new data values 


			*  


			* If there's errors, return to the edit form showing the errors 


			*  


			* Finally if the form wasn't set then we render the edit page so that the user can input field values.  


			*/ 


			if(isset(&#036;_POST['MessageForm'])) 


				{ 


					&#036;message-&gt;attributes=&#036;_POST['MessageForm']; 


					if(&#036;message-&gt;validate()) 


						&#036;this-&gt;render('show',array('message'=&gt;&#036;message)); 


					else  


						&#036;this-&gt;render('edit', array('message'=&gt;&#036;message)); 


				}


				else 


					&#036;this-&gt;render('edit', array('message'=&gt;&#036;message)); 


	}


	


	public function actionIndex()


		{


			&#036;this-&gt;render('index');


		}


		public function actionSubmit()


		{


			&#036;this-&gt;render('index');


		}


}

On plank pages (WSOD) you’ll usually want to tap onto your web server’s error log file. On Apache, that would be probably error.log. Check your web server’s configuration for the location of this log file. On Linux, I usually do a [font=“Courier New”]tail -f[/font] on it to see errors as they occur.

Good luck with your project!

Boaz.

K.thanq Boaz

Hi,

I have changed the settings and the error was—

"Error 404"

The system is unable to find the requested action "show"

Hi buddies

I have resolved my Display Hello world string

Everything is fine with my code but there was a simple mistake

I missed one of the closing braces.

Sorry for troubling you and thanks for the replies

For further usage, use code tags when posting PHP code (their icon is the html tags in the editor).

Sure

Thanks for the suggestion