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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:46:05+00:00 2026-05-31T09:46:05+00:00

I made this question in this if then else to display 2 views on

  • 0

I made this question in this if then else to display 2 views on one function called thread and i have tried to fix it as what I was suggested but the problem remains. Hope someone could help me…It does both of what has inside the “if” and what has inside the “else” ?

i have got a little problem with redirect function,
I have a controller function named “someview” and I also created a view file of the same name (someview.ctp)
The controller function will do some stuff(query data from the model).
it can be simply described as follows

function someview()
{
    $result=$this->User->getdatafrommodel();
    if(!empty($result))
    {
        //do something
                    sendmail(.....);
    }
    else
    {
        $this->redirect(array('action'=>'usernotexist'));
    }
}

function usernotexist()
{
    $this->loadSkin();
}

I also created a page named “usernotexist.ctp” which I would like to display some information as to when the specified user doesn’t exist in the database system. However, my previous function (someview) always execute “if” and “else” both after it is called. If I eliminate the “else” part in that function, it then works correctly for me; the page named “someview.ctp” is displayed. The $result value returned from the getdatafrommodel function is correct.
Thank you for any help.

UPDATE
this works:

    function someview()
{
    $result=$this->User->getdatafrommodel();
            print_r($result);
            exit();
    if(!empty($result))
    {
        //do something
    }
    else
    {
        $this->redirect(array('action'=>'usernotexist'));
    }
}

function usernotexist()
{
    $this->loadSkin();
}

this prints an empty Array.

    function someview()
{
    $result=$this->User->getdatafrommodel();
            print_r($result);
    if(!empty($result))
    {
        //do something
    }
    else
    {
        $this->redirect(array('action'=>'usernotexist'));
    }
}

function usernotexist()
{
    $this->loadSkin();
}

[UPDATE]

What I SEE after I click a link in a view called “folder/subfolder/someview” to call the controller method as I described above, the page in the “ELSE” is redirected. BUT in the IF part I also include a “Sendmail” function to send an email to my account. The sendmail WORKS. That is the odd thing I would like to understand. Clearly IF then Else both are executed.

What I would like to do is right after the user click the link to activate the controller method (someview), if the query returns an empty record, I will be directed to the page “usernotexist” or I will send him an email otherwise.

For your concern I agree to post the original source code, I am thinking the sendmail function might be making some mistake somewhere I can not at present recognize its place.

Here is it

    function newpassword()
    {
        $this->loadSkinForAction();
        $result=$this->EwtUser->get_user_from_email($_POST['email']);

        if(!empty($result))
        {
            $userid = $result[0]['ewt_users']['id'];
            $password=$this->EwtUser->get_and_change_user_password($_POST['email']);            
            $mail="Your new password is: ".$password."<br/>Please use it for next login.<br/>You are recommended to change this password again in your 'Personal Profile' section.";
            $this->sendmail($userid,$mail,$_POST['email']); 
        }
        else
        {
            //print_r($result);
            $this->redirect(array('action'=>'userexists'));
        }
    }

    function userexists()
    {
        $this->loadSkinForAction();     
    } 

and the model function to query data

function get_and_change_user_password($email)
    {
        $password=$this->genRandStr();
        $sql=sprintf("UPDATE ewt_users SET password='%s' WHERE email='%s'",md5($password),$email);
        $this->query($sql);
        return $password;
    }

And here is the sendmail function,

function sendmail($userid, $reportcontent,$email){
        //if($this->Session->read($this->_userName))
        {
            $this->loadModel('EwtMailtemplate');
            $this->loadModel('EwtUser');
            $this->loadModel('EwtSetting');
            $this->autoRender = false;

            $date = date("Y-m-d");
            $userinfo = $this->EwtUser->read(null, $userid);
            $fullname = $userinfo['EwtUser']['fullname'];
            $lastname = $userinfo['EwtUser']['lastname'];
            $mailtempl = $userinfo['EwtUser']['mailtempl'];
            if ($mailtempl == 0) {
                $mailtempl = 1;
            }

            $setting = $this->EwtSetting->find('first');
            $mailhost = $setting['EwtSetting']['mailhost'];
            $mailuser = $setting['EwtSetting']['mailuser'];
            $mailpass = $setting['EwtSetting']['mailpass'];
            //$reportmail = $setting['EwtSetting']['reportmail'];
            $reportmail=$email;
            $bodymail = $this->EwtMailtemplate->read(null, $mailtempl);
            //$header = $bodymail['EwtMailtemplate']['header'];
            //$footer = $bodymail['EwtMailtemplate']['footer'];
            //$title = $bodymail['EwtMailtemplate']['title'];
            $subject="New login password for working time system";
            //$subject = $lastname . " " . str_replace("[date]", $date, $title);
            //$header = str_replace("[lastname]", $lastname, $header);
            //$header = str_replace("[date]", $date, $header);
            //$footer = str_replace("[lastname]", $lastname, $footer);

            //$content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><html><head><meta http-equiv="Content-Type" content="text/html; charset =utf-8" /></head><body>'.$header ."<br />" . $reportcontent . "<br />" .  $footer . '</body></html>';

            $content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><html><head><meta http-equiv="Content-Type" content="text/html; charset =utf-8" /></head><body>'."<br />".$reportcontent."<br />".'</body></html>';

            $this->Email->to = $reportmail;
            $this->Email->charset = 'UTF-8';
            $this->Email->from = sprintf("%s <%s>", $fullname, $mailuser);
            $this->Email->replyto = sprintf("%s <%s>", $fullname, $mailuser);
            $this->Email->subject = $subject;
            $this->Email->sendAs ='html';
            $smtp = array(
                        'port'=>25,
                        'host'=>$mailhost,
                        'timeout'=>99,
                        'username'=>$mailuser,
                        'password'=>$mailpass
            );
            $this->Email->smtpOptions = $smtp;
            $this->Email->delivery = 'smtp';

            if ($this->Email->send($content)) {
                $this->redirect('newpassword');         
            } else {
                $this->redirect('userexists');
            }

            $smtp_error = $this->Email->smtpError;
            if (strlen($smtp_error)>0){
                $this->Session->setflash($smtp_errors);
            }
        }
    }

Again, it executes both IF and ELSE branches
Thank you for your concern and I’d really love to hear any comments or advice from you 🙂

WOW my post is too long. I soon can make a phylogenetic tree! :-D-D

  • 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-31T09:46:06+00:00Added an answer on May 31, 2026 at 9:46 am

    You are redirecting inside your sendmail function!

    if ($this->Email->send($content)) {
        $this->redirect('newpassword');         
    } else {
        $this->redirect('userexists');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Coming from this question , I have a wxComboCtrl with a custom popup made
In reponse to this question I wrote this function (well, I made it a
I have question quite much related to this one I asked a while ago
In this question , I was made aware of glob()'s GLOB_BRACE option that allows
This is a second-hand question from an OS development site, but it made me
This is more like a question of principle. I made a table with 100%
I made this code with jQuery to fade images ( but not the one
I made this function to verify a user's twitter credentials. Its running on two
I made this bookmarklet: javascript:(function(){var s=document.createElement('script');s.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');document.getElementsByTagName('body')[0].appendChild(s);$('#hldIntMain').hide();$('#fadeBackground').hide();return false;})() Formatted code: // Add in jQuery var
I made this bash one-liner which I use to list Weblogic instances running along

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.