Not signed in (Sign In)
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthorpweil
    • CommentTimeMay 6th 2008
     
    In previous web apps I've had to do a fair amount of string replacements, both in my queries and results.

    For queries: how does incorporate sql functions, such as replace() or concat() into Akelos queries? Do you have to use findBySQL? Or is there a way to include these in a find all? Examples:

    SELECT replace(title, 'the', '') from books
    SELECT concat(first_name, ' ', last_name) AS name from authors

    For query results: can someone provide an example using a str_replace or preg_replace for a particular object? Let's say I want all hyphens in Book titles changed to a ndash; html entity. I assume this would be done in the relevant model. I do see several combined attributes functions in AkActiveRecord, but they seem a bit complicated.
    • CommentAuthorKaste
    • CommentTimeMay 6th 2008
     

    quite a couple of ways to do this. generally you have to decide if you place something in your model or in a view/view-helper.

    class Author...
    function getName()
    {
        return $this->first_name.' '.$this->last_name;
    }
    

    something like

     class Author...
     var $combined_attributes = array(
         array('name', "%s %s", 'first_name', 'last_name')
     );
    

    should be 'relativ ähnlich'.

    I usually prefer the first one.

    • CommentAuthorpweil
    • CommentTimeMay 7th 2008
     
    Thank you Kaste. I am able to get the first method to work -- I can call it in a view like this:

    <?php echo $resource->contact->getName(); ?>

    Is there another or better way to call this?

    I can't get the second method to work; nor can I get this method to work:

    $this->addCombinedAttributeConfiguration('name', "%s %s", 'first_name', 'last_name');

    Perhaps I'm not calling them correctly. How would I do this?
    • CommentAuthorKaste
    • CommentTimeMay 7th 2008
     

    =>

        $A = new Author(array('first_name'=>'Liz','last_name'=>'Taylor'));
    
    
    
        $A->name;
        $A->get('name');
        // = 'Liz Taylor'
    
    • CommentAuthorpweil
    • CommentTime7 days ago
     
    Got it. Thanks!
Add your comments
    Username Password
  • Format comments as