Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7835659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:43:57+00:00 2026-06-02T13:43:57+00:00

How to a add a button in the crud _form for actionUpdate? so i

  • 0

How to a add a button in the crud _form for actionUpdate?

so i can delete the saved file, and upload a new one

i had this function in the model

    public function deleteImage()
    { 
        unlink(Yii::app()->basePath.'/../uploads/'.$this->image);
    }

so how to trigger this with a button like this?

<input type="button" value="delete image"/>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:44:00+00:00Added an answer on June 2, 2026 at 1:44 pm

    In MVC, the controller generally takes care of interaction from the user, so the user does not directly access the model, but does it through the controller. The controller intercepts user actions and does the work by calling model(s). Therefore it is best not to call the model function directly, even though it is possible.

    Now, to do what you want to do, we can create a function(action) in the controller which in turn will call the model’s function.

    To call a function(action) in the controller we can associate a url that will be called when the button is clicked, this can be done by using the onclick event. I’m guessing that you don’t want the browser to navigate to a new url, hence we call this url with ajax.

    Example, 1) in controller:

    public function actionMyaction($id){
        $sampleMod=SampleModel::model()->findByPk($id);
        $sampleMod->deleteImage();
        Yii::app()->end();
    }
    

    2) in view with button: instead of <input type="button" value="delete image"/> use CHtml helper class’s ajaxButton.

    echo CHtml::ajaxButton('Delete Image',Yii::app()->createUrl('controllername/actionname',array('id'=>$id)));
    

    Take care in passing the right $id.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to add a button to the current page using html()-function. This
I can not add button to this jquery ui dialog. if possible please give
My C# code is: Button button; button = new Button(); button.Text = B&C; this.Controls.Add(button);
net website, I would like to add button by which user can view the
This thread depends on How to add button to textbox? . Thanks.
I make one tableview in which I add button type cell using custom cell.
I have the following code: $(#tag-add-button).click(function () { var text = $(#tagadd).val(); var tagcounter=0;
I have an activity with an Add and a Delete button. The Add Button
One of the Xtragrid columns is CheckEdit(RepositoryItem). On click of add button I need
Possible Duplicate: how to add button dynamically in android? How can I dynamically create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.