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 6680413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:28:20+00:00 2026-05-26T04:28:20+00:00

I have a simple setup in Yii with a Model, View and a Controller

  • 0

I have a simple setup in Yii with a Model, View and a Controller to manage a DB table. (created with Gii)

When the user presses the delete button I want to validate this request with some rules of my own and if there is an error display this to the user.

Should I put validation method in the Model, call this validation from the controller delete method. But then I am not sure how I get a popup to appear on the webpage.

  • 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-05-26T04:28:21+00:00Added an answer on May 26, 2026 at 4:28 am

    I can’t speak specifically for Yii, but in general with PHP 5.3 a good practice would be to throw errors from models (mind you, human readable ones) and then catch them when you call the models in your controllers. The controllers can then pass along a list of errors to the views, which would be responsible for displaying the error(s) to the users.

    <?php
    class Model {
        public function doImportantStuff() {
            //Do stuff
            if(true) {
                throw new Exception('Important stuff could not be completed due to this important error.');
            }
        }
    }
    
    class Controller {
        public function index() {
            $data = array();
            $crucial = new Model();
    
            try {
                $crucial->doImportantStuff();
            } catch(Exception $e) {
                $data['errors'][] = $e;
            }
        }
    }
    
    //And in the view
    <?php if($data['errors']): ?>
    <?php foreach($data['errors'] as $error): ?>
        <p><?= $error->getMessage(); ?></p>
    <?php endforeach; ?>
    <?php endif; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A simple question: I have a Model-View-Controller setup, with Models accessing a SQL database.
I have a simple model setup in my Ruby on Rails app. (User {name,
In my Yii application I have a pretty simple model setup. I've used the
I have a simple setup to allow a user to change his content on
So I have a simple setup here where I make a button, place a
I have a simple PartialView setup in my MVC3 Project using the Razor View
I have what looks to me to be a pretty simple setup of model,
I have a simple setup, a table whose cells have checkboxes within them. I
I have a simple VS setup project. On the first screen user inputs database
I have a very simple Setup project that copies three dlls into the GAC.

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.