Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorpweil
     
    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
     

    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
     
    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
     

    =>

        $A = new Author(array('first_name'=>'Liz','last_name'=>'Taylor'));
    
    
    
        $A->name;
        $A->get('name');
        // = 'Liz Taylor'
    
    • CommentAuthorpweil
     
    Got it. Thanks!