Hi,

Thanks for info David and sorry for not checking archives but
http://dir.gmane.org/gmane.comp.web.agavi.devel was not responding.

I think I'd prefer not to access any framework data from inside model.
I'm using Agavi framework, because I think it's good for keeping bigger
project 'clean'. It's also good when you have to work with many other
developers. Debugging  with several models interfeapplicationring with
any core framework can be very difficult. Just imagine some module
accessing user data directly - lets say $userName  - some other
developer working on core framework could change variable name and
module is not working anymore. Example is trivial, but you probably know
what I mean (I'll learn some more English, I promise :).
Anyway - it should be personal choice of developer, depending probably
on size of project and so on.

I still have some minor issue. Code for getGlobalModel (from cache):

    public function getGlobalModel ($modelName)
    {
        $file = AG_LIB_DIR . '/models/' . $modelName . 'Model.class.php';
            if(file_exists($file)) {
                require_once($file);
            } else {
                $pattern = AG_LIB_DIR . '/' . '*' . '/models/' .
$modelName . 'Model.class.php';
                $files = glob($pattern);
                require_once($files[0]);
            }
        $class = $modelName . 'Model';
        $model = new $class();
        $model->initialize($this->context);
        return $model;
    }

Description in  documentacion:
return: A Model implementation instance, if the model exists, otherwise
null.

This function actually won't return NULL, just break execution on
require if the file does not exist. I think it should be changed into
something like that:

            if(file_exists($file)) {
                require_once($file);
            } else {
                $pattern = AG_LIB_DIR . '/' . '*' . '/models/' .
$modelName . 'Model.class.php';
                $files = glob($pattern);
                if(count($files) == 0)              
                   return null;
                require_once($files[0]);
            }



Tomek


David Zülke wrote:

>initialize() will be called automatically when you retrieve the model using
>Controller::get(Global)Model().
>
>It's fairly interesting that you come up with this - it is exactly what
>we've been discussing here a couple of days ago.
>This is my personal opinion (but some people share this point of view):
>Models are containers for your business logic. There has to be some sort of
>data exchange with the outer framework, and I think you may very well access
>the User, do other stuff with the Context and Controller or whatever from
>inside the Model. If you want maximum portability of your business logic,
>you should place it in an external class and use a Model as a wrapper
>interface to provide the "library's" functionality to the framework.
>
>I don't think we should add this path to include_path by default. That's
>what config.php is there for, after all - customizing stuff like this on a
>per-project basis
>
>- David 
>
>
>  
>
>>-----Original Message-----
>>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
>>Behalf Of [EMAIL PROTECTED]
>>Sent: Monday, August 01, 2005 7:16 PM
>>To: [email protected]
>>Subject: [agavi-dev] custom module initialization & include path
>>
>>Hi,
>>
>>1. I'd like to create module by extending Module class - can I make
>>somehow function initialize to be executed automaticaly ? I'd like to
>>have a code like that:
>>
>>class MyModel extends Model
>>{
>>    public function initialize($context)
>>    {
>>        return parent::initialize($context);
>>    }
>>
>>    public function dump()
>>    {
>>        var_dump($this->getContext());
>>    }
>>}
>>
>>Do you think I should avoid Model accessing some other classess (like
>>User) directly ? Sometimes it comes handy, but I think that reusability
>>of module suffers because of that.
>>
>>2. Should we extend include path for %AG_WEBAPP_DIR%/lib by default ?
>>Wombert's tutorial on how to integrate Agavi & Propel won't work, unless
>>user will set it.
>>
>>
>>    
>>
_______________________________________________
agavi-dev mailing list
[email protected]
http://labworkz.com/cgi-bin/mailman/listinfo/agavi-dev

Reply via email to