Wednesday, December 30, 2009

Re: Count column in index view

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

Tuesday, December 29, 2009

Re: Nested Models

You could do http://www.application.com/message/add/contract:1 using
named parameters.

Or setup a route for www.application.com/contract/1/message/add

On Dec 28, 11:09 pm, otisjs01 <jerem...@jeremiahotis.com> wrote:
> OK, so I'm asking lots of questions today...but I really want to
> learn! :)
>
> Anyway, I'm trying to create messages that can be left with a
> contract.
>
> So, I have a Contract model that has the following fields: id, some
> other contract pertinent info. And, a Message model that has the
> following fields: id, contract_id, title, message_text. A Contract has
> many message, and a message belongs to a given contract.
>
> Now, when I display a contract, I want a link that takes the user to a
> page full of messages specific to that contract. Once at the message
> page, they should be able to add a new message, or view existing
> messages. Viewing existing messages is easy, as far as I understand
> it. I'm already doing the same thing all over my application! But,
> creating new messages from this page is something I'm unsure of. How
> do I go about that? How do I store the contract_id in the view so that
> whenever I click "Add new contract" it automatically associates the
> message with the contract. And, so that the user can't accidentally
> add the message to a different contract.
>
> I'm thinking that a url that looks like: <a href="#">http://www.application.com/contract/1/message/add</a> where 1 is the
> contract_id) makes the most sense. I could do this in rails in a few
> seconds...but I can't seem to find a way to do it in CakePHP. The only
> thing I can come up with is: <a href="#">http://www.application.com/
> message/add/1</a> (where 1 is the contract_id).
>
> Am I missing something?
>
> Any help would be appreciated!
>
> Thanks,
>
> Jeremiah

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

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

Out of office reply

Hi,

I am out the office until the 14th of January. If you require urgent assistance then please contact pete@citadelsecure.com or call him on 07890 592198 - otherwise I will answer your email on my return.

Regards

Jim


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: Cookie in Models

Couldn't you just use app_model.php to make the data available to all
your models?

On Dec 28, 2:18 am, dyutiman <dyutiman.chaudh...@gmail.com> wrote:
> Hi Nabil,
> thanks for your reply and suggestion. It'll really help.
> I thought about getting the cookie value in controller and pass it to
> model. But for this I have to rewrite every model functionality
> provided by cake by default.
> I am still thinking of a good solution of the problem. But in the mean
> time the cookie method will work for us.
>
> thanks
> Dyutiman
>
> On Dec 24, 9:53 pm, Nabil Alsharif <bli...@gmail.com> wrote:
>
> > Pulling the client_id from thecookiein themodelreally isn't a good
> > idea IMO. The only way I can think of doing it is straight up with php's
> > basiccookiefunctions or doing something like
> > ClassRegistry::init('CookieComponent') and hoping it doesn't bomb out on
> > you.
>
> > OTOH you can easily get to the cookies in the controller and pass it in
> > to yourmodelwhen it's needed.
>
> > On Thu, 2009-12-24 at 07:59 -0800, dyutiman wrote:
>
> > > Hi,
>
> > > I am building an application with multiple database. Database gets
> > > selected based upon clients. Now the client_id is saved in acookie. I
> > > have to read thecookievalue in my /app/app_model.php page to select
> > > respective database.
>
> > > Is there a way to retrieve thecookievalue in that page !!!
>
> > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp 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 athttp://groups.google.com/group/cake-php?hl=en

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: design suggestion request

OK, thanks. And it makes sense to test it in the test case for a
controller that uses it, right?

cheers
Lorenzo

edwingt wrote:
> You have to includ it in the vendors directory and load it as
> App::import
> More info here http://book.cakephp.org/view/538/Loading-Vendor-Files
>
> On 29 dic, 10:53, Lorenzo Bettini <bett...@dsi.unifi.it> wrote:
>> Hi
>>
>> I've just started using cakephp and I'm porting an older application.
>>
>> I need to use a bibtex parser, so I was wondering "where to put" such
>> parser... in a model? in a component? what else?
>>
>> Or is it still good to use it as a standalone php code? In that case,
>> how can I use it, say, inside a controller?
>>
>> thanks in advance
>> Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com

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: design suggestion request

You have to includ it in the vendors directory and load it as
App::import
More info here http://book.cakephp.org/view/538/Loading-Vendor-Files

On 29 dic, 10:53, Lorenzo Bettini <bett...@dsi.unifi.it> wrote:
> Hi
>
> I've just started using cakephp and I'm porting an older application.
>
> I need to use a bibtex parser, so I was wondering "where to put" such
> parser... in a model? in a component?  what else?
>
> Or is it still good to use it as a standalone php code?  In that case,
> how can I use it, say, inside a controller?
>
> thanks in advance
>         Lorenzo
>
> --
> Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
> HOME:http://www.lorenzobettini.itMUSIC:http://www.purplesucker.com
> BLOGS:http://tronprog.blogspot.com http://longlivemusic.blogspot.com

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