Action call from button

Hello all,

Is it possible to call an action in my controller from a button in the corresponding view?

Sorry if this is a bit of a newbie question.

Thanks

your question is not a newbe one but incomplete one. What do you mean call an action from button? Do you mean submit form to an action? if that is so then please define the action property of your form to point to the action you want to hit

I would like to call one of the action methods in my Controller class when a button in the view is pressed. As of right now there is no form (maybe there should be).

so for example I want a button imagine a view with a button and a controller with the following action


public function actionView($id)

	{

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

			'model'=>$this->$model,

		

		));

	}

so when the button is clicked I want actionView to be called and I want view to render

thanks

Couldn’t get your question properly.But think this may help you some what.


<?php echo CHtml::submitButton('CSV Report', array('submit'=>'getReport')); ?>

[color="#FF0000"]getReport [/color] = The action name in the controller.

In here the button will call tho the action in controller and execute what need to be done in that action… :)

Thanks CPzee

Sorry for the poorly worded question but your solution was exactly what I needed.

Hi all,

I’m sorry to post you here, i would like some helps:

I would like to create a button for modification a page if this page isn’t modified before and after modification, this button will disapear:

dashcontroller.php

public function actionIndex(){

	&#036;this-&gt;setPageTitle(Yii::t('backoffice', 'Dashboard'));


	&#036;promoterPage = PromoterPage::model()-&gt;findByPk(Yii::app()-&gt;session['promoter']-&gt;id);


	&#036;this-&gt;render('index', array(


		'event' =&gt; EventController::getSearchable(),


		'promoterPage' =&gt; &#036;promoterPage

index.php

<div class="button-row">

&lt;?php if (&#036;promoterPage=1): ?&gt;


		&lt;a class = &quot;btn btn-validation btn-large&quot; target = &quot;_blank&quot; href = &quot;&lt;?php echo &#036;this-&gt;createUrl('/backoffice/promoterpage/edit'); ?&gt;&quot;&gt;


			&lt;?php echo Yii::t('backoffice', 'Change the look of your promoter pages');?&gt; 


		&lt;/a&gt;


&lt;?php endif ?&gt;

Hope to get some help… thanks in advance

Hi sopheak13

A few things:

  1. use the code tags to make your code more readable (its the ‘<>’ button on the toolbar above)

  2. As for your question, I am not sure what you are asking but check this page out it might be the answer to what you are looking for: