Thank you!!

On 2 jun, 16:23, SergeyPo <ser...@zarealye.com> wrote:
> This also looks like Ruby on Rails approach, however you can write
> your own classes in web2py, put them to models dir and use them as you
> have used to. E.g. you have an sql table 'users' in DAL, and you can
> write a class
> class Users:
>     def findUser(login):
>         u = db(db.users.login==login).select()
>         return u[0] or None
>
> Your model definitions will  be automatically loaded if your class
> file name is alphabetically 'lower' than 'db' (you can always use
> underscores etc. tricks to achieve that).
>
> On Jun 2, 6:03 pm, JohnMc <maruadventu...@gmail.com> wrote:
>
> > salbefe,
>
> > I understand your point coming from a CakePHP utilization. But most of
> > the PHP based frameworks naturally gravitate to using a lower level of
> > abstraction when operating on the DB with a global namespace. What you
> > will find with many Python based frameworks that they use an ORM (DAL,
> > SQLAlchemy) the definitions are in the ORM. The actions on the dataset
> > are in the controllers. The namespace is limited to the controller (ie
> > python module)
>
> > You could approximate your previous experience with PHP frameworks by
> > construction of SQLQuery stored in vars in the models page itself.
> > Then use those vars in the controllers/DAL to get your results. I have
> > done that once as I knew the basis of the query was common and only
> > the select differed across several controllers. You could probably go
> > as far as writing a series of def's in the model py page to mimic the
> > PHP style. But I have never tried it.
>
> > But all that manipulation tends to fly in the face of good practice.
> > One of which is to contain the actions in as small a namespace as is
> > practical to get the job done.
>
> > JohnMc
>
> > On Jun 2, 6:14 am, salbefe <salb...@gmail.com> wrote:
>
> > > Hello,
>
> > > To explain what I'm trying to say I will put an example.
>
> > > For people that come from PHP frameworks like Zend or Code Igniter we
> > > use the models on the following way:
>
> > > First, we write each model on a file (like web2py) for example:
>
> > > <?php
> > > class Usermodel extends Model {
>
> > >     function Usermodel()
> > >     {
> > >         // Call the Model constructor
> > >         parent::Model();
>
> > >         $this->load->database();
>
> > >     }
>
> > >    function findUser($login)
> > >    {
> > >         $sql = "select * from users where login_name='$login'";
> > >         $query = $this->db->query($sql);
>
> > >         $result = $query->result_array();
> > >         return $result;
> > >    }}
>
> > > ?>
>
> > > And second, we use that model on the controller like this:
>
> > > <?php
> > > class Login_user extends Controller
> > > {
> > >     function Login_user()
> > >     {
> > >         parent::Controller();
>
> > >         $this->load->model('Usermodel');
> > >     }
>
> > >     function index()
> > >     {
> > >       ...............
> > >       $id_user = $this->Usermodel->findUser($login);
>
> > >     }}
>
> > > ?>
>
> > > What I'm trying to say is that on these frameworks we use the models
> > > to put all the related stuff with the sql queries. We call from the
> > > controllers functions that are implemented on the models avoiding to
> > > write sql queries on the controllers.
>
> > > I said that because on web2py documentation I have seen models that
> > > only describe the tables, fields, and other things related to the
> > > database and in some examples I have seen on the controllers code
> > > related to queries that in my opinion it should be on a model.
>
> > > I do not if it's clear what I'm saying but could some one put an
> > > example of how could I use the models in web2py on the same way that
> > > for example in codeIgniter.
>
> > > Thanks a lot
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to