Wednesday, December 30, 2009

Sessions table already in the database

HI,

Is there a way to change the default session handling?

Reason: we have a database of events (conferences, speakers,
attendees, etc... and, sadly, " sessions " !!). This database is used
by some other applications so it would be difficult to change the
table name. However, once the MVCs (thus the " Session controller ")
for this table are created, they cause total confusion to cakePHP !!

What is the best workaround ?

Sorry if it's a noob question... but can't find the answer anywhere !

Thanks
ECote

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Conceptual problem Model on View ..

Hi guys, im don't speak english but ill try to explain my problem for
u. So, sorry for my poor english.

Ok, let imagine that I have an Model named MODEL_A that have an status
field ( OPENED and CLOSED )..
I have an method on MODEL_A named can_close() that return true if i
can close the element..

I want to show a list of MODEL_A elements in the page.. so in the
controller I call a MODEL_A->find(all).. ok.. get all instances...and
$this->set to view... nice!

Ok, now i have all my MODEL_A elements on VIEW... and I want to do
this: foreach element check .. if MODEL_A->can_close() == true...
show button CLOSE .. on the side of element name.. if can_close() ==
false.. hide it.


So... a ill need to import my model to the view.. to call can_close
method.. right? but.. call model on view is the worst sin for MVC
pattern ahn??

So.. what I do now friends?

Thank you for all..

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Re: Multiple Model Pagination

Containable could create multiple queries.

This is the solution I went for:
http://github.com/ionas/sna/blob/master/www/app/controllers/profiles_controller.php#L112

This could be another solution (not tested yet):
http://mark-story.com/posts/view/using-bindmodel-to-get-to-deep-relations

(internally pagination uses find() as well)

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Re: Problem understanding how this model object works

Cake is auto-loading your model, meaning that it cant find the model
you are expecting. Double check your spelling etc for the $uses var to
check your correctly assigning it.

On Dec 30, 6:37 am, edwingt <edwin.al...@gmail.com> wrote:
> I have a model object called "ImpresorasProducto" that belongs to a
> NxM relationship table impresoras_productos.
>
> When I'm in "ImpresorasProductosController" and debug the model object
> it prints this:
>
> ImpresorasProducto Object
> (
>     [name] => ImpresorasProducto
>     [belongsTo] => Array
>         (
>             [Producto] => Array
>                 (
>                     [className] => Producto
>                     [foreignKey] => producto_id
> ....
>
> This is find because I can access al the realational models.
>
> The problem is when I use the "ImpresorasProducto" model in other
> controller.
> I include the model in the controller with the var $uses ....
> I can't acces the objects related to "ImpresorasProducto"  and when I
> debug the model object it prints this:
>
> AppModel Object
> (
>     [useDbConfig] => default
>     [useTable] => impresoras_productos
>     [displayField] => id
>     [id] =>
>     [data] => Array
>         (
>         )
>
>     [table] => impresoras_productos
> ....
>
> I cant uderstand why here I have an AppModel Object instead of a
> ImpresorasProducto Object

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Re: Count column in index view

With the hasOne relationship, the query looks like:
[code]
SELECT `Author`.`id`, `Author`.`name`, COUNT(`Article`.`id`) as
article_count FROM `authors` AS `Author` LEFT JOIN `articles` AS
`Article` ON (`Article`.`author_id` = `Author`.`id`) WHERE
`Author`.`id` IN (1, 2, 13) GROUP BY `Author`.`id`, `Author`.`name`
[/code]

With the hasMany relationship, the query looks like:
[code]
SELECT `Author`.`id`, `Author`.`name`, COUNT(`Article`.`id`) as
article_count FROM `authors` AS `Author` WHERE `Author`.`id` IN (1, 2,
13) GROUP BY `Author`.`id`, `Author`.`name`
[/code]
Contain does not assist in creating a LEFT JOIN, which is why
Article.id is an unknown column!

As far as I remember, the issue is probably not in the Containable
behaviour, but somewhere in DboSource, but I may be wrong here :)

There is another way:
1) Set contain equal false.
2) Define the joins yourself, as in the example below:
[code]
$results = $this->Article->Author->find(
'all',
array(
'contain' => false,
'joins' => array(
array(
'table' => 'articles',
'type' => 'left',
'alias' => 'Article',
'foreignKey' => false,
'conditions' => array('Article.author_id =
Author.id')
)
),
'fields' => array('Author.id', 'Author.name', 'COUNT
(Article.id) as article_count'),
'group' => array('Author.id', 'Author.name'),
)
);
[/code]

But that is also not very simple!

Will keep you updated, should I find a better solution! Enjoy,
John

On Dec 30, 12:07 pm, Jeremy Burns <jeremybu...@me.com> wrote:
> Thank you John - I will try this out. Strikes me as very odd that this
> is not much much simpler!
>
> On Dec 30, 10:05 am, John Andersen <j.andersen...@gmail.com> wrote:
>
> > Hi Jeremy,
>
> > Seems like Contain can't find out to make a join when there is a
> > hasMany relationship between the Author and the Article models. I made
> > changes to Example A, so that Contain makes a LEFT JOIN, which
> > includes Authors with no Articles :)
>
> > 1) Unbind the hasMany relationship.
> > 2) Bind a hasOne relationship.
> > 3) Make the find on the Author model - I have include two author ids
> > with articles and one (13) without articles.
> > [code]
> >       $this->Article->Author->unbindModel( array('hasMany' => array
> > ('Article')));
> >       $this->Article->Author->bindModel( array('hasOne' => array
> > ('Article')));
> >       $results = $this->Article->Author->find(
> >          'all',
> >          array(
> >             'contain' => array('Article'),
> >             'fields' => array('Author.id', 'Author.name', 'COUNT
> > (Article.id) as article_count'),
> >             'conditions' => array('Author.id' => array(1,2,13)),
> >             'group' => array('Author.id', 'Author.name'),
> >          )
> >       );
> >       debug($results);
> > [/code]
>
> > The result is:
> > [result]
> > 28871\controllers\articles_controller.php (line 48)
> > Array
> > (
> >     [0] => Array
> >         (
> >             [Author] => Array
> >                 (
> >                     [id] => 1
> >                     [name] => Hans Christian Andersen
> >                 )
> >             [0] => Array
> >                 (
> >                     [article_count] => 19
> >                 )
> >         )
> >     [1] => Array
> >         (
> >             [Author] => Array
> >                 (
> >                     [id] => 2
> >                     [name] => Terry Prattchet
> >                 )
> >             [0] => Array
> >                 (
> >                     [article_count] => 19
> >                 )
> >         )
> >     [2] => Array
> >         (
> >             [Author] => Array
> >                 (
> >                     [id] => 13
> >                     [name] => Test
> >                 )
> >             [0] => Array
> >                 (
> >                     [article_count] => 0
> >                 )
> >         )
> > )
> > [/result]
>
> > Hope this helps you on the way,
> >    John
>
> > On Dec 30, 6:52 am, Jeremy Burns <jeremybu...@me.com> wrote:
>
> > > Thanks John. Option B does indeed work - sort of! It returns a list of
> > > location types with a count of their locations, but only where there
> > > is a location. In other words, it does not give me the location types
> > > that do not have have any locations.
>
> > > Any more ideas - anyone?
>
> > > On Dec 29, 12:35 pm, John Andersen <j.andersen...@gmail.com> wrote:
>
> > > > A correction, example A gives the author with all the articles, but
> > > > the article count is 1 (one) - so no luck using that!
> > > > Enjoy,
> > > >    John
> > > > [snip]

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Re: i18n and anonymous surfers - bug?

I can confirm this. Just tried it with my development site, which
works well in english and danish, depending on the language
information received from the browser.
With anonymouse.org this completely does not work, nothing is
translated.
Enjoy,
John

On Dec 29, 5:38 am, euromark <dereurom...@googlemail.com> wrote:
> i would have never found that out if i hadnt built myself a bot-
> tracking component
> it basically logs all non-js-browsing and tries to detect if it was a
> known search bot
>
> anyway
> this way i found out that my website has been visited by users usinghttp://anonymouse.org/
>
> i tried it out myself and was really shocked that i18n doesnt work
> anymore
> from my understanding it uses (at least in cakephp1.2 it did and
> should do it in 1.3)
> a) define('MY_DEFAULT_LANGUAGE','de');
> b) Configure::write('Config.language', 'de-de')
>
> right now it does not translate at all if you visit it via services
> like anonymouse.org
> neither english nor german nor any other language
>
> Configure::read('Config.language') returns NULL (and was definitely
> set before)
> which could lead to the false assumption that my website is not german
> (although its the main language - and the only present language in the
> po files!), or even worse: buggy and defect. i mean, the untranslated
> strings are appearing...
>
> after some research i found out that this service scambles the cookies
> before passing them to the cake app
> so this might have something to do with it - it is probably like
> cookies beeing deactivated
>
> right now i intercept any call from this service via 406 error code
> and the message "With such services the page cannot be displayed
> properly"
> but it should probably get fixed somehow
> the "primary" language should always be active - even with cookies off
> etc
> any ideas?

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Re: Count column in index view

Thank you John - I will try this out. Strikes me as very odd that this
is not much much simpler!

On Dec 30, 10:05 am, John Andersen <j.andersen...@gmail.com> wrote:
> Hi Jeremy,
>
> Seems like Contain can't find out to make a join when there is a
> hasMany relationship between the Author and the Article models. I made
> changes to Example A, so that Contain makes a LEFT JOIN, which
> includes Authors with no Articles :)
>
> 1) Unbind the hasMany relationship.
> 2) Bind a hasOne relationship.
> 3) Make the find on the Author model - I have include two author ids
> with articles and one (13) without articles.
> [code]
>       $this->Article->Author->unbindModel( array('hasMany' => array
> ('Article')));
>       $this->Article->Author->bindModel( array('hasOne' => array
> ('Article')));
>       $results = $this->Article->Author->find(
>          'all',
>          array(
>             'contain' => array('Article'),
>             'fields' => array('Author.id', 'Author.name', 'COUNT
> (Article.id) as article_count'),
>             'conditions' => array('Author.id' => array(1,2,13)),
>             'group' => array('Author.id', 'Author.name'),
>          )
>       );
>       debug($results);
> [/code]
>
> The result is:
> [result]
> 28871\controllers\articles_controller.php (line 48)
> Array
> (
>     [0] => Array
>         (
>             [Author] => Array
>                 (
>                     [id] => 1
>                     [name] => Hans Christian Andersen
>                 )
>             [0] => Array
>                 (
>                     [article_count] => 19
>                 )
>         )
>     [1] => Array
>         (
>             [Author] => Array
>                 (
>                     [id] => 2
>                     [name] => Terry Prattchet
>                 )
>             [0] => Array
>                 (
>                     [article_count] => 19
>                 )
>         )
>     [2] => Array
>         (
>             [Author] => Array
>                 (
>                     [id] => 13
>                     [name] => Test
>                 )
>             [0] => Array
>                 (
>                     [article_count] => 0
>                 )
>         )
> )
> [/result]
>
> Hope this helps you on the way,
>    John
>
> On Dec 30, 6:52 am, Jeremy Burns <jeremybu...@me.com> wrote:
>
>
>
> > Thanks John. Option B does indeed work - sort of! It returns a list of
> > location types with a count of their locations, but only where there
> > is a location. In other words, it does not give me the location types
> > that do not have have any locations.
>
> > Any more ideas - anyone?
>
> > On Dec 29, 12:35 pm, John Andersen <j.andersen...@gmail.com> wrote:
>
> > > A correction, example A gives the author with all the articles, but
> > > the article count is 1 (one) - so no luck using that!
> > > Enjoy,
> > >    John
> > > [snip]

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en