#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    29
    Rep Power
    0

    Php class "return" problem


    hi!

    the pagination class that I use has a lot "echo statement".Which I want use with using "return statement"


    This so ...!!!


    PHP Code:

    class pagination extends index 

    function 
    data()
    {

    if()

    {

    echo 
    '';

    }

    else {

    echo 
    '';


    }

    echo 
    '';

    if()  {  echo 
    '';  }


    }



    This code works in my template class...


    PHP Code:


    class val extends index 


    function 
    foo ()




    echo 
    $this->view_load(array("foo"),array($this->load("pagination")->data()),"view.php");


    }




    this code returns the pagination class , but which is not on place that I want.Which appears on the absurd place...


    because...event is because "echo statement"

    how to use with return statement all echo statements on the pagination class?????
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,993
    Rep Power
    9397
    Make the function return the string instead of echo it. That should be the obvious first step. Does that alone not fix the problem?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    29
    Rep Power
    0
    Originally Posted by requinix
    Make the function return the string instead of echo it. That should be the obvious first step. Does that alone not fix the problem?
    requinix hi,
    I couldn't understand you said..

    can you write an example...because I have to print to screen the view_load method
  6. #4
  7. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,101
    Rep Power
    1990
    Instead of
    PHP Code:
    echo ''
    You would use
    PHP Code:
    return ''
    That's all there is to it. As requinix hinted at before, your question answered itself really.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    29
    Rep Power
    0
    Originally Posted by Catacaustic
    Instead of
    PHP Code:
    echo ''
    You would use
    PHP Code:
    return ''
    That's all there is to it. As requinix hinted at before, your question answered itself really.

    if I make return statement instead of echo statement.The code doesn't print to screen the other echo statements after print first echo...

    so,you said is not useful for me.

    PHP Code:

    function foo ()

    {

    return 
    'asa';

    echo 
    'yep';


    you said is this...
  10. #6
  11. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,101
    Rep Power
    1990
    Now you are really confusing me.

    What do you want this to do? Do you want it to print to the screen, or to return the string? You can do both, but you're not making it clear.

    To return the string:
    PHP Code:
    return ''
    To echo the string:
    PHP Code:
    echo ''
    To echo the string and return it:
    PHP Code:
    echo '';
    return 
    ''
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    29
    Rep Power
    0
    no,you dont understand.

    PHP Code:

    function foo()
    {

    if()
    {


    // there is an echo statement for specific if statement
    echo '';

    }

    else { 


    // other echo statement
    echo '';


    }


    // normally echo statement continues in the code snippet

    echo 'blabla';


    if() { 

    echo 
    '';

    }




    I should make return one of which...if I make one return, other echo statements ????????

    I hope I could tell you...
  14. #8
  15. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,101
    Rep Power
    1990
    I think I understand what you are after... maybe.

    Are you trying to return one string depending on the if() statements that are in the function? If that's the case, something like this?

    PHP Code:
    function foo ()  { 
        if (
    $condition1 === true) {
            
    $string "First string";
        }
        else {
            
    $string "Second string";
        }
        
        
    $string.= "blabla"
        
        if (
    $condition2 === true) {
            
    $string.= "next bit";
        }
        
        return 
    $string;

  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    29
    Rep Power
    0
    Originally Posted by Catacaustic
    I think I understand what you are after... maybe.

    Are you trying to return one string depending on the if() statements that are in the function? If that's the case, something like this?

    PHP Code:
    function foo ()  { 
        if (
    $condition1 === true) {
            
    $string "First string";
        }
        else {
            
    $string "Second string";
        }
        
        
    $string.= "blabla"
        
        if (
    $condition2 === true) {
            
    $string.= "next bit";
        }
        
        return 
    $string;




    owww...!!! thanks... this is okey.!!!!!

    very very thanks @cataustic

    also, sorry..I have got angry due from the code...again sorry

IMN logo majestic logo threadwatch logo seochat tools logo