Welcome Guest, Not a member yet? Register   Sign In
Cake's functionality in CI?
#1

[eluser]Unknown[/eluser]
Hello,

I have developed a few projects in CakePHP and really liked it. But I also want to learn CI and finally pick up the best framework for me. Cake had functions like Save, beforeSave, afterSave. $this->data variable being populated by model info when a form is submitted. There is a way to assign relationships between tables (foreign keys) in the model. created_at and updated_at get populated by themselves, etc.

Can someone point me to right direction where I can find this info? Looking into the user_guide, forums and Googling has shown me generic "Hello World" type examples. I am pasting my Model from Cake, I'd highly appreciate if someone can throw a light on how to achieve these functionalities in CI in the most elegant way.

Thanks

Code:
<?php
class News extends AppModel {

        var $name = 'News';
        var $validate = array(
                'news_title' => VALID_NOT_EMPTY,
                'news_body' => VALID_NOT_EMPTY,
                'tag_line' => VALID_NOT_EMPTY,
                'news_type_id' => VALID_NOT_EMPTY,
        );

        var $belongsTo  = array(
                        'Album' =>
                                array('className' => 'Album',
                                                'foreignKey' => 'album_id',
                                                'conditions' => '',
                                                'fields' => '',
                                                'order' => '',
                                                'counterCache' => ''
                                ),
                        'NewsType' =>
                                array('className' => 'NewsType',
                                                'foreignKey' => 'news_type_id',
                                                'conditions' => '',
                                                'fields' => '',
                                                'order' => '',
                                                'counterCache' => ''
                                ),
                        'CUser'=>
                                array('className' => 'User',
                                                'foreignKey' => 'created_by',
                                                'conditions' => '',
                                                'fields' => '',
                                                'order' => '',
                                                'counterCache' => ''
                                ),
                        'UUser'=>
                                array('className' => 'User',
                                                'foreignKey' => 'updated_by',
                                                'conditions' => '',
                                                'fields' => '',
                                                'order' => '',
                                                'counterCache' => ''
                                )
        );
        function beforeSave()
    {
        if (empty($this->id))
        {
            $this->data[$this->name]['url'] = $this->getUniqueUrl($this->data[$this->name]['news_title'], 'url');
        }
        return true;
    }
}
?>
#2

[eluser]GSV Sleeper Service[/eluser]
take a look at [url="http://www.doctrine-project.org/"]Doctrine ORM[/url], it plays nicely with CI, and is quite easy to pick up.




Theme © iAndrew 2016 - Forum software by © MyBB