Re: How to raise Auth failed

2012-10-17 Thread Dr. Tarique Sani
On Thu, Oct 18, 2012 at 11:20 AM, Sanjeev Divekar
 wrote:
> Hello,
>
> I want to restrict user doing some action of authentication is not done.
>
> function display($id=1) {
> $page = $this->Page->read(null,$id);
> if(!$this->Session->check('Auth.User') &&
> $page['Page']['authentication_required']) {
> /// What to do here
> }
>// Some other code
> }
>


Put that code in before filter and return true
if($this->Session->check('Auth.User') &&
$page['Page']['authentication_required']) else redirect to permission
denied page

Better read 
http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html
:-)

HTH
Tarique


-- 
=
The Conference Schedule Creator : http://shdlr.com

PHP for E-Biz : http://sanisoft.com
=

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




How to raise Auth failed

2012-10-17 Thread Sanjeev Divekar
Hello,

I want to restrict user doing some action of authentication is not done.

function display($id=1) {
$page = $this->Page->read(null,$id);
if(!$this->Session->check('Auth.User') && 
$page['Page']['authentication_required']) {
/// What to do here
}
   // Some other code
}

Regards,

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: Strange array when moved from test to live server.

2012-10-17 Thread Sanjeev Divekar
Can you post your controller code?

On Wednesday, 17 October 2012 19:34:07 UTC+5:30, PlanoCoder wrote:
>
> Good morning all I build a site on XAMP local server.  There was no 
> problem when testing.  When i Uploaded the files to the live verio server 
> my code no longer works.
> here is what i am talking about
>
> in my view file my code on the test server looks like this
>
> *$key['Member']['username'];*
>
> when i moved to the live server i have to change the code to 
>
> *$key[0]['username'];*
>
> for cake to pull the data.
>
> Any idea why this is?
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Routing Issue

2012-10-17 Thread Advantage+
I have 3 different Admin routes defined. admin / manager / editor

 

Now just testing a few things, so not logged in I try to access a restricted
admin url.

But it redirects me to {url}/admin/users/login

 

How can I get it so it redirects to {url}/users/login? 

I need to drop the admin, or other possible defined admin routes

 

In AppController:

'loginAction' => array('controller' => 'users','action' => 'login', 'admin'
=> false)

 

In the controller:

public function beforeFilter() {

parent::beforeFilter();

$this->Auth->deny();

$this->Auth->redirect();

}

 

Any ideas where I am going wrong?

 

Thanks,

Dave

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: ACL - delete groups?

2012-10-17 Thread Jeremy Burns | Class Outfit
The first thing to fix is referential integrity in your database so that a 
group that has users cannot be deleted. If your db won't support RI (if you're 
using MyIsam instead of InnoDB, for example) then at least put some checks in 
your code before you do the delete. If you don't, the users belong to a now 
vanished group. That will confuse the Acl tables as they do not deploy RI out 
of the box (they should have relations between aros => aros_acos <= acos, but 
they don't), and even then it's hard to restrict group deletes there as the 
foreign key to either groups.id or users.id is stored in the same field in the 
aros table, although you can add RI from aros.parent_id => aros.id. If the 
group that contains the users is removed from the aros table, the parent id 
points to an id that doesn't exist and the code will explode.

Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 18 Oct 2012, at 04:53:25, Vanja Dizdarević  wrote:

> Can you post some code maybe?
> 
> On Thursday, October 18, 2012 1:25:22 AM UTC+2, Adam Strom wrote:
> Hi All -
> 
> I've completed the Acl tutorial in the 2.0 docs and it says: "...anytime you 
> create or delete a user/group the Aro table is updated." 
> 
> Yet when I delete a group that has users assigned to it, any further edits to 
> those users throws an error:
> 
> "Error: [CakeException] AclNode::node() - Couldn't find Aro node identified 
> by "Array
> (
> [Aro0.model] => User
> [Aro0.foreign_key] => 16
> )"
> 
> Even if I assign them to an existing group, the update occurs within the 
> Users table but the aros table never gets a new entry for that user.
> 
> Any thoughts? 
> 
> Thanks!
> 
> Adam
> 
> -- 
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>  
> --- 
> 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+unsubscr...@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>  
>  

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: how can i route /size to /size.html

2012-10-17 Thread Vanja Dizdarević
Modifying .htaccess almost renders the solution "outside of CakePHP" scope, 
doesn't it?

A 301 permanently redirects to size.html, I'm guessing Murray is trying to 
have a pretty URL, so this should do it:

#add this line above Cake's rewrites in app/webroot/.htaccess
RewriteRule ^size$ size.html

#Cake's rewrites...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

Otherwise just leave it as-is and use /size.html

On Thursday, October 18, 2012 5:45:00 AM UTC+2, ibejohn818 wrote:
>
> Mod Rewrite /size to 301 to size.html
> No need to be hosting duplicate content.
>
> On Oct 17, 2012, at 8:42 PM, Vanja Dizdarević 
> > 
> wrote:
>
> +1 on that.
>
> An example:
>
> Move it from *app/webroot/size.html* to *app/View/Pages/size.ctp*
> Add *Router::connect('/size', array('controller'=>'pages', 
> 'action'=>'display', 'size'));* to the routes.php
> This would of course render this page inside your default layout, which 
> might not be what your are trying to achieve.
>
> A way around that is to add an action to the PagesController:
> Move from *app/webroot/size.html* to *app/View/Pages/size.ctp*
> Add *Router::connect('/size', array('controller'=>'pages', 'action'
> =>'size'));* to the routes.php
> In your PagesControler create a function:
> public function size(){
> $this->layout = 'empty';
> }
> create an empty layout:
> //app/View/Layouts/empty.ctp
> fetch('content'); ?>
>
> (or divide your file into layout + content)
>
> This way you avoid creating a new random controller to, basically, serve a 
> single static page.
>
>
>
> On Thursday, October 18, 2012 5:09:28 AM UTC+2, thatsgreat2345 wrote:
>>
>> You should NOT be doing this. If you want to, then create a controller, 
>> and a view then you can use cakephp routes to route the way you want it to.
>>
>> On Wednesday, October 17, 2012 7:20:55 PM UTC-7, Murray wrote:
>>>
>>> I just have a static html file which is app/webroot/size.html. I can 
>>> access it by the url "/size.html".
>>> But how can i route /size to /size.html?
>>>
>>> -- 
>>> Rui WANG(王瑞)
>>> Murray
>>> School of Electronics Engineering and Computer Science,
>>> Peking University
>>>  
>>
> -- 
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>  
> --- 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to cake...@googlegroups.com
> .
> To unsubscribe from this group, send email to 
> cake-php+u...@googlegroups.com .
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>  
>  
>
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: ACL - delete groups?

2012-10-17 Thread Vanja Dizdarević
Can you post some code maybe?

On Thursday, October 18, 2012 1:25:22 AM UTC+2, Adam Strom wrote:
>
> Hi All -
>
> I've completed the Acl tutorial in the 2.0 docs and it says: "...anytime 
> you create or delete a user/group the Aro table is updated." 
>
> Yet when I delete a group that has users assigned to it, any further edits 
> to those users throws an error:
>
> "Error: [CakeException] AclNode::node() - Couldn't find Aro node 
> identified by "Array
> (
> [Aro0.model] => User
> [Aro0.foreign_key] => 16
> )"
>
> Even if I assign them to an existing group, the update occurs within the 
> Users table but the aros table never gets a new entry for that user.
>
> Any thoughts? 
>
> Thanks!
>
> Adam
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: how can i route /size to /size.html

2012-10-17 Thread John Hardy
Mod Rewrite /size to 301 to size.html
No need to be hosting duplicate content.

On Oct 17, 2012, at 8:42 PM, Vanja Dizdarević  wrote:

> +1 on that.
> 
> An example:
> 
> Move it from app/webroot/size.html to app/View/Pages/size.ctp
> Add Router::connect('/size', array('controller'=>'pages', 
> 'action'=>'display', 'size')); to the routes.php
> This would of course render this page inside your default layout, which might 
> not be what your are trying to achieve.
> 
> A way around that is to add an action to the PagesController:
> Move from app/webroot/size.html to app/View/Pages/size.ctp
> Add Router::connect('/size', array('controller'=>'pages', 'action'=>'size')); 
> to the routes.php
> In your PagesControler create a function:
> public function size(){
> $this->layout = 'empty';
> }
> create an empty layout:
> //app/View/Layouts/empty.ctp
> fetch('content'); ?>
> 
> (or divide your file into layout + content)
> 
> This way you avoid creating a new random controller to, basically, serve a 
> single static page.
> 
> 
> 
> On Thursday, October 18, 2012 5:09:28 AM UTC+2, thatsgreat2345 wrote:
> You should NOT be doing this. If you want to, then create a controller, and a 
> view then you can use cakephp routes to route the way you want it to.
> 
> On Wednesday, October 17, 2012 7:20:55 PM UTC-7, Murray wrote:
> I just have a static html file which is app/webroot/size.html. I can access 
> it by the url "/size.html".
> But how can i route /size to /size.html?
> 
> -- 
> Rui WANG(王瑞)
> Murray
> School of Electronics Engineering and Computer Science,
> Peking University
> 
> -- 
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>  
> --- 
> 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+unsubscr...@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>  
>  

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: how can i route /size to /size.html

2012-10-17 Thread Vanja Dizdarević
+1 on that.

An example:

Move it from *app/webroot/size.html* to *app/View/Pages/size.ctp*
Add *Router::connect('/size', array('controller'=>'pages', 
'action'=>'display', 'size'));* to the routes.php
This would of course render this page inside your default layout, which 
might not be what your are trying to achieve.

A way around that is to add an action to the PagesController:
Move from *app/webroot/size.html* to *app/View/Pages/size.ctp*
Add *Router::connect('/size', array('controller'=>'pages', 'action'
=>'size'));* to the routes.php
In your PagesControler create a function:
public function size(){
$this->layout = 'empty';
}
create an empty layout:
//app/View/Layouts/empty.ctp
fetch('content'); ?>

(or divide your file into layout + content)

This way you avoid creating a new random controller to, basically, serve a 
single static page.



On Thursday, October 18, 2012 5:09:28 AM UTC+2, thatsgreat2345 wrote:
>
> You should NOT be doing this. If you want to, then create a controller, 
> and a view then you can use cakephp routes to route the way you want it to.
>
> On Wednesday, October 17, 2012 7:20:55 PM UTC-7, Murray wrote:
>>
>> I just have a static html file which is app/webroot/size.html. I can 
>> access it by the url "/size.html".
>> But how can i route /size to /size.html?
>>
>> -- 
>> Rui WANG(王瑞)
>> Murray
>> School of Electronics Engineering and Computer Science,
>> Peking University
>>  
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: Debugger Class not found - CakePHP 2.1 - PHP 5.4

2012-10-17 Thread Vanja Dizdarević
This thread shows in lots of search results, so just to extend the answer 
just a little bit...

A Component was throwing the same error on Cake 2.2.1 and PHP 5.4.6. I 
figured it was because I added the startup() method, but forgot to 
type-hint the class of the parameter (Controller).

Basically, instead of:

function startup( ){ 

}

you should use:

*public *function startup( *Controller *$Controller) {

}

Without the *public* keyword, method still works for me (the public 
visibility is then inherited). If I use "private", "static", "protected", 
etc., error occurs. If I use "final", the method still works.
Which all makes big sense from OOP point of view.

If I remove the *Controller* type hint in the method property declaration, 
PHP throws error. PHP got really strict on method visibility and overrides 
since 5.2+. 

Further reading about PHP objects: 
visibility, 
inheritance , type 
hinting 

When extending Core classes and writing callbacks (or overriding some other 
methods), it's always good to check (and copy) the methods you're 
overriding. This way you always have strong declarations, visibility and 
parameters are in check (and conventionally named). You also catch a 
glimpse of core code, which is always good. :)


On Friday, August 17, 2012 5:19:51 AM UTC+2, che_anj wrote:
>
> Hi traedamatic,
>
> I have the same problem, how did u resolve this issues. 
>
> thank you very much
>
>
>
> On Friday, March 23, 2012 10:33:24 PM UTC+8, traedamatic wrote:
>>
>> Problem SOLVED! 
>>
>> *php 5.4 needs public and private keywords with function and 
>> attributes!!!*
>>
>> Am Mittwoch, 21. März 2012 10:20:55 UTC+1 schrieb traedamatic:
>>>
>>> Hello,
>>>
>>> I have a strange problem. I run on Cakephp 2.1 App on PHP 5.4 and 
>>> 5.3.10. 
>>> On PHP 5.3.10 is everything fine but on 5.4 i get this error:
>>>
>>> *Fatal error*: Class 'Debugger' not found in *
>>> /***/beta/app/Plugin/Markitup/View/Helper/MarkitupHelper.php *on line 
>>> *161*
>>> *
>>> *
>>> The line 161 is the last line of the file.
>>>
>>> The head of the Helper looks like this:
>>>
>>> App::import('Core', 'Debugger');
>>> App::uses('AppHelper', 'View/Helper');
>>>
>>> class MarkitupHelper extends AppHelper {
>>> ...
>>>
>>> The funny think is that happens although with the DebugKit Plugin. 
>>>
>>> Does anyone have the same problem?
>>>
>>> Does anyone had the same Problem?
>>>
>>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Strange array when moved from test to live server.

2012-10-17 Thread PlanoCoder
Good morning all I build a site on XAMP local server.  There was no 
problem when testing.  When i Uploaded the files to the live verio server 
my code no longer works.
here is what i am talking about

in my view file my code on the test server looks like this

*$key['Member']['username'];*

when i moved to the live server i have to change the code to 

*$key[0]['username'];*

for cake to pull the data.

Any idea why this is?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: 3.0: a peek into CakePHP's future

2012-10-17 Thread Vanja Dizdarević
I consider Cake's model the only drawback of Cake in my daily work.

Since I usually operate with large amounts of complex associations in my 
models, I have developed three relatively painful work patterns:

   1. I use Containable behavior on almost ALL my models (and use it in 
   nearly every query I write)
   2. I bind associations on-the-fly
   3. I write my-own-damn-SQL-join-query myself

This takes up quite a lot of my time to optimize my model queries. 87% of 
the time, I do not want *all *the related data and I consider it redundant. 
Maybe I'm just a lousy programmer, but I find a big need to treat data as 
objects, not just to have them deliver me arrays to cumbersomely fiddle 
with. Not to mention the mental overload of planning to save related data...

This would be a dream:

$article = $this->Article->findBySlug($slug);
$user = $this->Auth->user('id');
if ($user->myOwnCustomAuthMethod('view', $article));
foreach($article->comments as $comment) //comments are not loaded until 
property is requested
{
if ($comment->author->id == $article->id){ 
// $comment->author is also an overloaded property, returns Author instance
   $authorsComments[] = $comment;
}
}
$article->view_count++;
$article->last_viewed = time();
$article->save();

I think Cake Model has some really strong points that should be kept, like 
relation definitions, validation (it's maybe a lot of arrays, but it's 
useful) and error handling. But I just prefer data objects over arrays and 
I think it would sit perfectly into CakePHP. I feel it would offer a simple 
way of adding DRY data logic.

So I say HOORAY for any objectification, even if my example is totally 
off-road.

OR at least having the option to easily choose a database layer similar to 
Doctrine/Propel, if I wanted. Would be very nice.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: Error: Call to a member function find() on a non-object

2012-10-17 Thread PlanoCoder
Pull your Array

you may need to change

''.$address['id'].''.

to

''.$address[0]['id'].''.

or something like that

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




ACL - delete groups?

2012-10-17 Thread Adam Strom
Hi All -

I've completed the Acl tutorial in the 2.0 docs and it says: "...anytime 
you create or delete a user/group the Aro table is updated." 

Yet when I delete a group that has users assigned to it, any further edits 
to those users throws an error:

"Error: [CakeException] AclNode::node() - Couldn't find Aro node identified 
by "Array
(
[Aro0.model] => User
[Aro0.foreign_key] => 16
)"

Even if I assign them to an existing group, the update occurs within the 
Users table but the aros table never gets a new entry for that user.

Any thoughts? 

Thanks!

Adam

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: how can i route /size to /size.html

2012-10-17 Thread thatsgreat2345
You should NOT be doing this. If you want to, then create a controller, and 
a view then you can use cakephp routes to route the way you want it to.

On Wednesday, October 17, 2012 7:20:55 PM UTC-7, Murray wrote:
>
> I just have a static html file which is app/webroot/size.html. I can 
> access it by the url "/size.html".
> But how can i route /size to /size.html?
>
> -- 
> Rui WANG(王瑞)
> Murray
> School of Electronics Engineering and Computer Science,
> Peking University
>  

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




how can i route /size to /size.html

2012-10-17 Thread 王瑞
I just have a static html file which is app/webroot/size.html. I can access
it by the url "/size.html".
But how can i route /size to /size.html?

-- 
Rui WANG(王瑞)
Murray
School of Electronics Engineering and Computer Science,
Peking University

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: Odd array structure when using Model->query()

2012-10-17 Thread bmcelhany
Well, I tried a couple of different things.

First, I tried going the virtual field route and got the same results 
(classification id and name appearing outside of the main array):

--

//create the virtual field
$this->virtualFields['miles'] = "(3956 * 2 * ATAN2(SQRT(POW(SIN..

//filter on classification id
array_push($conditions, array('classification_id' => $classification_id));

//filter on specialty id (if needed)
if(!empty($specialty_id)) {
array_push($conditions, array('specialty_id' => $specialty_id, 'specialty_' 
. $classification_name => 1)); 
}

//perform query
$results= $this->Find('all', array('conditions'=>$conditions, 
'order'=>'miles')); //I also tried 'order'=>'Location.miles' and 
'order'=>'Location__miles'

--

Then, I decided to try adding the fields that I need to filter on 
(classification and specialty) as virtual fields too, and this DID work:

--

//create virtual fields
$this->virtualFields['miles'] = 0;
$this->virtualFields['classification_id'] = 0;
$this->virtualFields['classification_name'] = '';

//build out the sql string
$sql = "SELECT (3956 * 2 * ATAN2(SQRT(POW(SIN((RADIANS(".$lat_lon

//if we need to filter on specialty, add another virtual field at this time 
and append to the sql string
if(!empty($specialty_id)) {
$this->virtualFields['specialty_id'] = 0;
$this->virtualFields['specialty_name'] = '';
$sql .= "AND (specialty_id = $specialty_id) ";
}

//finish off the sql string by adding the ORDER BY clause
$sql .= "ORDER BY Location.miles ASC";

//perform query
$results= $this->query($sql);

--

So, while I'm happy that the 2nd scenario works, I'm completely baffled as 
to WHY I would need to do it that way. It seems like a lot of hoops to jump 
through to do something that *seems* like it should be fairly 
straightforward. I have a feeling that there's something really obvious 
that I'm doing wrong, but I'm at a loss as to what it might be.

On Wednesday, October 17, 2012 1:58:39 AM UTC-7, euromark wrote:
>
> why not using virtual fields?
> then there won't be any odd format returned by find()
>
> Am Mittwoch, 17. Oktober 2012 07:37:15 UTC+2 schrieb Andras Kende:
>>
>> Here is similar query, maybe helpful:
>>
>> $unit = ($unit == 'km') ? 1.609344 : 1 ;
>>
>> $results = $this->Location->find('all', array(
>> 'limit' => 100,
>> 'order' => array(
>> 'distance' => 'ASC',
>> 'Location.name' => 'ASC',
>> ),
>> 'recursive' => -1,
>> 'conditions' => '1 = 1 HAVING `distance` <= 50' ,
>> 'fields' => "*, TRUNCATE((3958 * 3.1415926 * SQRT((`lat` - {$lat}) * 
>> (`lat` - {$lat}) + COS(`lat` / 57.29578) * COS({$lat} / 57.29578) * (`lng` 
>> - {$lng}) * (`lng` - {$lng})) / 180) * 1.609344, 5)  AS `distance`"
>> ));
>>
>>
>> Or you could foreach your results and move from ,classifications to 
>> Locations...
>>
>>
>> Andras Kende
>> http://www.kende.com
>>
>> On Oct 16, 2012, at 6:43 PM, bmcelhany  wrote:
>>
>> Unfortunately, that didn't change anything.
>>
>> On Tuesday, October 16, 2012 5:10:30 PM UTC-7, cricket wrote:
>>>
>>> Try adding the model alias: 
>>>
>>> AND (Location.classification_id = $classification_id) 
>>>
>>> On Tue, Oct 16, 2012 at 7:42 PM, bmcelhany  wrote: 
>>> > Hello, 
>>> > 
>>> > I have a model (Location) that points to a view (locations) in MySQL. 
>>> The 
>>> > view contains address, zip code and latitude/longitude data that I use 
>>> to 
>>> > calculate the distance between two locations (or find all locations 
>>> within a 
>>> > given radius from a particular zip code). 
>>> > 
>>> > In my model, I have a function that takes 3 parameters: a zip code, a 
>>> > classification id and a specialty id. Using those three parameters, I 
>>> > construct a sql string ($sql), call $this->query($sql) and return the 
>>> > resulting array. The reason I simply don't call the model's standard 
>>> > $this->find() method is because, in addition to the fields from the 
>>> database 
>>> > view, I need to perform a huge and ugly calculation to determine the 
>>> number 
>>> > of miles each record's zip code is from the zip code passed in to the 
>>> > function. I'm using this as a virtual field in the model called 
>>> "Miles". 
>>> > 
>>> > At any rate, this is mostly working but I'm noticing some strange 
>>> behavior 
>>> > with how the resulting array is structured. Any time I add something 
>>> to the 
>>> > WHERE clause of my sql statement and have an ORDER BY clause in the 
>>> sql 
>>> > statement, those items are returned in an array that is separate from 
>>> my 
>>> > expected Location array. If I don't add any fields to my WHERE clause, 
>>> > everything is returned as expected (just with no filters applied to 
>>> the 
>>> > result set). Oddly, if I remove the ORDER BY clause everything works 
>>> fine 
>>> > too. It's only when I ORDER BY my Mile

CakeEmail Class on Shell not delivering message.

2012-10-17 Thread GerarD
Hello... The problem I'm facing is that I'm trying to send an email from 
the shell with no success. Here is what I have:

function sendNewDistributor($address, $password, $id) {

App::uses('CakeEmail', 'Network/Email');

$email = new CakeEmail('default');

$email->to($address);

$email->template('distributor_welcome');
$email->subject('Registro');
$email->viewVars(array('password' => $password));
$email->viewVars(array('id' => $id));
if($email->send()){

return true;

}
return false;

}

I have this same function as part of a Model and it works from a HTTP 
request. I use Mercury as my email server, and it shows in the Core Process 
Window that the action has been done as normal, but the email 
never arrives... What could it be.?


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: Themed bootstrap

2012-10-17 Thread Sam Sherlock
Do you want a bootstrap.php within your theme like you have one in
APP/Config/?
Or are you using a php file to 'do more' with a request to a css file?

I think perhaps croogo might be doing something akin to what your doing if
you want per-theme config
croogo 1.3 uses yaml & 1.4 uses json
 - S




On 17 October 2012 07:57, Lucky1968  wrote:

> Hi Paul,
>
> Thanx for this info. I understand how it should work but it doesn't work
> in my system.
>
> Maybe the problem is because $this->Html->css looks for a bootstrap.css
> instead of a bootstrap.php?
>
> On Thursday, October 11, 2012 1:36:19 PM UTC+2, Paulo Henrique wrote:
>>
>> bootstrap.php => https://github.com/**hugodias/cakeStrap/blob/**
>> master/app/Config/bootstrap.**php#L173
>>
>> default.ctp => https://github.com/**hugodias/cakeStrap/blob/**
>> master/app/View/Layouts/**default.ctp#L21
>>
>> Em quarta-feira, 10 de outubro de 2012 03h14min42s UTC-3, Lucky1968
>> escreveu:
>>>
>>> Does anyone know how to integrate a bootstrap.php in a theme and how to
>>> open it dynamically?
>>>
>>> In my bootstrap.php I have certain settings which should change
>>> according to the selected theme so I would like to put a bootstrap.php file
>>> into the theme folder which should be called dynamically according to the
>>> selected theme.
>>>
>>> But how to do this?
>>>
>>  --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> 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+unsubscr...@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: how do I use saveAll()?

2012-10-17 Thread Gustav Persson


I've solved the problem myself now by reading the CakePHP cookbook a little 
better:

Changed in version 2.1: You can now save deeper associated data as well 
with setting $options['deep'] = true;

So for me this was all I needed:

$saveOptions['deep'] = true;
if ($this->Recipe->saveAll($this->request->data, $saveOptions )) {


Den måndagen den 15:e oktober 2012 kl. 21:08:16 UTC+2 skrev Gustav Persson:
>
> Hii,
>
> I'm trying to use the saveAll() method to create and save related data in 
> my CakePHP (2.2.1) app. I have a form where the user can input recipe 
> information and create recipeitems and ingredients. The problem is that I 
> don't know how to store the ingredients data.
>
> I use the saveAll() method in the RecipeController, and this has worked to 
> save the Reipce, Categories and RecipeItems, but NOT the Ingredients or 
> Groceries.
>
> Is it possible to save all this data at once? If so, what should the input 
> data to saveAll look like?
>
> All help is greatly appreciated!
>
>
>
>
> My relationships look like this:
>
> Recipe:
> hasMany: Recipeitem
> hasAndBelongsToMany:Category
>
> Category:
> hasAndBelongsToMany: Recipe
>
> Recipeitem:
> belongsTo: Recipe
> hasMany: Ingredient
>
> Ingredient:
> belongsTo: Grocery, Recipeitem
>
> Grocery:
> hasMany: Ingredient
>
>
> The data I'm passing to saveAll() by 
> $this->Recipe->saveAll($this->request->data):
>
> Array
> (
> [Recipe] => Array
> (
> [title] => Tomato pie
> [description] => A tasty pie
> [cooking] => Mix everything!
>
> )
>
> [Category] => Array
> (
> [Category] => Array
> (
> [0] => 5
> [1] => 3
> )
>
> )
>
> [Recipeitem] => Array
> (
> [0] => Array
> (
> [Recipeitem] => Array
> (
> [name] => Deg
> [order] => 0
> [Ingredient] => Array
> (
> [0] => Array
> (
> [Ingredient] => Array
> (
> [amount] => 2
> [unit] => dl
> [order] => 0
> [grocery_id] => 1
> )
>
> )
>
> )
>
> )
>
> )
>
> )
>
> )
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: Odd array structure when using Model->query()

2012-10-17 Thread euromark
why not using virtual fields?
then there won't be any odd format returned by find()

Am Mittwoch, 17. Oktober 2012 07:37:15 UTC+2 schrieb Andras Kende:
>
> Here is similar query, maybe helpful:
>
> $unit = ($unit == 'km') ? 1.609344 : 1 ;
>
> $results = $this->Location->find('all', array(
> 'limit' => 100,
> 'order' => array(
> 'distance' => 'ASC',
> 'Location.name' => 'ASC',
> ),
> 'recursive' => -1,
> 'conditions' => '1 = 1 HAVING `distance` <= 50' ,
> 'fields' => "*, TRUNCATE((3958 * 3.1415926 * SQRT((`lat` - {$lat}) * 
> (`lat` - {$lat}) + COS(`lat` / 57.29578) * COS({$lat} / 57.29578) * (`lng` 
> - {$lng}) * (`lng` - {$lng})) / 180) * 1.609344, 5)  AS `distance`"
> ));
>
>
> Or you could foreach your results and move from ,classifications to 
> Locations...
>
>
> Andras Kende
> http://www.kende.com
>
> On Oct 16, 2012, at 6:43 PM, bmcelhany > 
> wrote:
>
> Unfortunately, that didn't change anything.
>
> On Tuesday, October 16, 2012 5:10:30 PM UTC-7, cricket wrote:
>>
>> Try adding the model alias: 
>>
>> AND (Location.classification_id = $classification_id) 
>>
>> On Tue, Oct 16, 2012 at 7:42 PM, bmcelhany  wrote: 
>> > Hello, 
>> > 
>> > I have a model (Location) that points to a view (locations) in MySQL. 
>> The 
>> > view contains address, zip code and latitude/longitude data that I use 
>> to 
>> > calculate the distance between two locations (or find all locations 
>> within a 
>> > given radius from a particular zip code). 
>> > 
>> > In my model, I have a function that takes 3 parameters: a zip code, a 
>> > classification id and a specialty id. Using those three parameters, I 
>> > construct a sql string ($sql), call $this->query($sql) and return the 
>> > resulting array. The reason I simply don't call the model's standard 
>> > $this->find() method is because, in addition to the fields from the 
>> database 
>> > view, I need to perform a huge and ugly calculation to determine the 
>> number 
>> > of miles each record's zip code is from the zip code passed in to the 
>> > function. I'm using this as a virtual field in the model called 
>> "Miles". 
>> > 
>> > At any rate, this is mostly working but I'm noticing some strange 
>> behavior 
>> > with how the resulting array is structured. Any time I add something to 
>> the 
>> > WHERE clause of my sql statement and have an ORDER BY clause in the sql 
>> > statement, those items are returned in an array that is separate from 
>> my 
>> > expected Location array. If I don't add any fields to my WHERE clause, 
>> > everything is returned as expected (just with no filters applied to the 
>> > result set). Oddly, if I remove the ORDER BY clause everything works 
>> fine 
>> > too. It's only when I ORDER BY my Miles virtual field AND have stuff in 
>> my 
>> > WHERE clause that things start to break. 
>> > 
>> > I should note too, that when I look at the actual query that is being 
>> run 
>> > and copy it into MySQL, it runs fine and returns the correct results. 
>> > 
>> > Here is the relavant code ($lat_lon['lat'] and $lat_lon['lon'] are from 
>> a 
>> > local array and are returning the correct numbers): 
>> > 
>> > - 
>> > 
>> > $this->virtualFields['Miles'] = 0; 
>> > 
>> > $sql = "SELECT " 
>> > ."Location.classification_id, " 
>> > ."Location.classification_name, " 
>> > ."Location.first_name, " 
>> > ."Location.last_name, " 
>> > ."Location.suffix, " 
>> > ."Location.title, " 
>> > ."Location.specialty_id, " 
>> > ."Location.specialty_name, " 
>> > ."Location.specialty_ame, " 
>> > ."Location.specialty_pr4, " 
>> > ."Location.address_id, " 
>> > ."Location.address, " 
>> > ."Location.city, " 
>> > ."Location.state, " 
>> > ."Location.zip, " 
>> > ."Location.address_ame, " 
>> > ."Location.address_pr4, " 
>> > ."Location.zip_code, " 
>> > ."Location.lat, " 
>> > ."Location.lon, " 
>> > ."(3956 * 2 * ATAN2(SQRT(POW(SIN((RADIANS(".$lat_lon['lat'].") - " 
>> > .'RADIANS(Location.lat)) / 2), 2) + COS(RADIANS(Location.lat)) * ' 
>> > ."COS(RADIANS(".$lat_lon['lat'].")) * 
>> POW(SIN((RADIANS(".$lat_lon['lon'].") 
>> > - " 
>> > ."RADIANS(Location.lon)) / 2), 2)), SQRT(1 - 
>> > POW(SIN((RADIANS(".$lat_lon['lat'].") - " 
>> > ."RADIANS(Location.lat)) / 2), 2) + COS(RADIANS(Location.lat)) * " 
>> > ."COS(RADIANS(".$lat_lon['lat'].")) * 
>> POW(SIN((RADIANS(".$lat_lon['lon'].") 
>> > - " 
>> > ."RADIANS(Location.lon)) / 2), 2 AS Location__Miles " 
>> > ."FROM locations AS Location " 
>> > ."WHERE " 
>> > ."(lat BETWEEN ROUND({$lat_lon['lat']} - (25 / 69.172), 4) " 
>> > ."AND ROUND({$lat_lon['lat']} + (25 / 69.172), 4) " 
>> > ."AND lon BETWEEN ROUND({$this->lon} - ABS(25 / COS({$lat_lon['lat']}) 
>> * 
>> > 69.172)) " 
>> > ."AND ROUND({$lat_lon['lon']} + ABS(25 / COS({$lat_lon['lat']}) * 
>> 69.172)) " 
>> > ."AND 3956 * 2 * ATAN2(SQRT(POW(SIN((RADIANS({$lat_lon['lat']}) - " 
>> > ."RADIANS(Location.lat)) / 2), 2) + COS(RADIANS(Location.lat)) * " 
>> > ."COS(RADIANS({$lat_lon['la