HABTM queries (join stuff)

2006-07-12 Thread ginstrom

I want to query a HABTM relationship, with two relationships.

Say I have tables
players
positions
players_positions

And I want to find players who are both shortstops (Position.id=1) and
pitchers (Position.id=3).

Is there a cake way to do this?

--
Thanks,
Ryan


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



RE: tinymce and CakePHP

2006-07-09 Thread Ryan Ginstrom

 Has anyone successfully integrated tinymce with CakePHP?
 
 I'm putting tiny_mce.js in webroot/js/ and my layout is 
 written up like
 this:
 
 [code]
   script language=javascript type=text/javascript
 src=/js/tiny_mce.js/script
   script language=javascript type=text/javascript
   tinyMCE.init({
   mode : textareas,
   theme : simple
   });
   /script
 [/code]

I was able to do this. I think you are missing a view heirarchy levels.
My setup: 
/js/tinymce/jscripts/tiny_mce/tiny_mce.js

I think that was all I needed.

--
Regards,
Ryan Ginstrom


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



RE: CakePHP Built-in Webservices?

2006-07-04 Thread Ryan Ginstrom

 [mailto:[EMAIL PROTECTED] On Behalf Of Mika
 Actually I'm quite interested in this too. Could you maybe please give
 a proper working example with using soap?

As I understand it, this is just a convenience for pretty URLs.

So for instance, 

http://example.com/rss/events

calls
events_controller::rss_index()

And

http://example.com/rss/events/tokyo

Calls
events_controller::rss_tokyo()

You could then select which content to put into the rss feed based on the
called function

I have made a simple RssComponent (using RSSWriter as a vendor), if you are
interested in the code.

--
Regards,
Ryan Ginstrom


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



RE: association - foreach

2006-07-03 Thread Ryan Ginstrom

 [mailto:[EMAIL PROTECTED] On Behalf Of ShepherdWeb
 That makes sense.  My current implementation is the other way around
 though:
 
 (my url looks like this: /products/color/color_id)

So...

In colors_controller:

function getById( $id )
{
   $this-Color-id = $id ;
   return $this-Color-read() ;
}

In products_controller:

function color( $id )
{
   $this-set( 'data', $this-requestAction( /colors/getById/$id ) ) ;
}

// view same...

And you're good to go g

--
Regards,
Ryan Ginstrom


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



RE: association - foreach

2006-07-03 Thread Ryan Ginstrom

 [mailto:[EMAIL PROTECTED] On Behalf Of ShepherdWeb
 Thanks g.

No problem. 

Just thought I'd mention that in addition to being prettier, getting the
color data from the color controller has another advantage. What happens if
there are no products of that color? Keying off the product model will get
you an empty set, and now you don't know what color you were looking for.

If you go from the color model, you will get a color entry, and an empty set
of products, so you will be able to tell the user, Sorry, no mauve
products.

--
Regards,
Ryan Ginstrom


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



RE: association - foreach

2006-07-03 Thread Ryan Ginstrom

 [mailto:[EMAIL PROTECTED] On Behalf Of ShepherdWeb
 ?php
 class ColorsController extends AppController
 {
 var $name = 'Colors';
 }
 ?
 
 in file : app/controllers/colors_controller.php

Do you have this class? You need it. And put that getById function inside it.
You will also need to create a Color model, if you don't have one.

You could start with this:
?php
class ColorsController extends AppController
{
   var $name = 'Colors';

   var $scaffold = true ;

   function getById( $id ) { return $this-Color-findById( $id ) ; }
}
?

--
Regards,
Ryan Ginstrom


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



RE: requestAction crashes Apache

2006-07-01 Thread Ryan Ginstrom

 From: cake-php@googlegroups.com 
 function memberLoggedIn()
 {
 if ($this-Session-check('memberLoggedIn'))
 {
 $member_session = $this-Session-read('memberLoggedIn');
 if($member =
 $this-requestAction('/members/getMember/'.$member_session['id'])) {
$this-set('member', $member);
 }
 else $this-Session-delete('memberLoggedIn');
 }
 }
 
 This function is called on every page using the beforeFilter.

I suspect that requestAction is the source of your problems, then, since
beforeFilter will also be called on requestAction 

The simple way around this would be to check if the action on
members_controller is getMember, and if so exiting beforeFilter

--
Regards,
Ryan Ginstrom


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Can i get $webroot for a vendor library?

2006-06-24 Thread ginstrom

Logan wrote:
 Because i need to used in the view and/or the controller. Probably i'm
 missing something.
 I'm kind of new to MVC.

If I'm not mistaken, you can access components from the view (just not
helpers from the controller).

If you are serving an image generated on the fly, you could also set a
null layout and simply have the component output the headers, create
the image, and read() it or whatever, then call exit.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



RE: Proof of concept: Custom validation using beforeValidate

2006-06-13 Thread Ryan Ginstrom

 [mailto:[EMAIL PROTECTED] On Behalf Of RosSoft
 invalidate() sets a row in an array with a value of 1. Change
 invalidate() to set the string as value (then the errors will be
 available in your controller and helpers)

Nice. So I could override invalidate in app_model:

/*  +++  */
function invalidate( $field, $errMsg = null ) 
{
   if (!is_array($this-validationErrors)) 
   {
   $this-validationErrors = array();
   }
   if ( $errMsg == null )
   {
  $bits = explode('_', $field) ;
  $nameBits = array() ;
  foreach( $bits as $bit )
  {
 $nameBits[] = ucfirst( $bit ) ;
  }
  $name = join( ' ', $nameBits ) ;
  $msg = Invalid $name value ;
   }
   else
   {
  $msg = $errMsg ;
   }

   $this-validationErrors[$field] = $msg ;
}
/*  +++  */

Then in my beforeValidate():

/*  +++  */
 function beforeValidate()
 {
   $this-invalidate( 'username', 'User name already taken' ) ;
   return false ;
 }
/*  +++  */

Then, using ErrorHelper::tagErrorMsg as a drop-in replacement for
HtmlHelper::tagErrorMsg :

/*  +++  */
class ErrorHelper extends Helper 
{
   var $helpers = array( 'Html' ) ;
   
   function tagErrorMsg( $field ) 
   {
  $this-Html-setFormTag($field) ;
  $msg = $this-Html-tagIsInvalid($this-Html-model,
$this-Html-field) ;
  if ( !$msg )
  {
 return null ;
  }
  return sprintf('div class=error_message%s/div', $msg ) ;
   }
}
/*  +++  */

// 

How does that look?

--
Regards,
Ryan Ginstrom


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



RE: Proof of concept: Custom validation using beforeValidate

2006-06-13 Thread Ryan Ginstrom

 [mailto:[EMAIL PROTECTED] On Behalf Of gwoo
 you can do most of this without any other helpers or changes to the  
 core code.
 
 function beforeValidate() {
 
  $this-invalidate('username_taken');
  return false ;
 }
 
 the in your view
 $html-tagErrorMsg('User/username_taken', 'This username is already  
 taken. Please choose another');

I had thought about this approach, but I saw a couple problems. First, your
views need to know about your business logic so they know the types of errors
that can occur. And every time your business logic changes, you need to go
mucking about with your views to change the possible error messages. Having
this all in the model allows you to encapsulate error handling.

Also, when you localize your site, I think it will be easier to have all your
error-message logic in one place, so you can more easily retrieve and set
localized error messages from the database.

--
Regards,
Ryan Ginstrom


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



RE: Uploaded Form Helper: FormationHelper

2006-06-12 Thread Ryan Ginstrom

 [mailto:[EMAIL PROTECTED] On Behalf Of RosSoft
 I repeat, use $value=$this-Html-tagValue($fieldName)   for maximum
 compatibility

Thanks for the pointer.

I actually ended up copying the HtmlHelper code into FormationHelper and
modifying it, because tagValue was calling h() (AKA htmlspecialchars() ) on
the value, which escapes HTML entities. Since I am using my database to store
HTML text, that's not what I wanted.

But the latest version of my posted code supports both $this-params['data']
and $this-data.

Regards,
Ryan

---
Ryan Ginstrom
[EMAIL PROTECTED] / [EMAIL PROTECTED] 
http://ginstrom.com 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



RE: Uploaded Form Helper: FormationHelper

2006-06-12 Thread Ryan Ginstrom

 [mailto:[EMAIL PROTECTED] On Behalf Of brandags
 Wait - but don't I still need to send the validation rules, 
 etc. to the
 view? Can you change what parameters are sent to the 
 startup() function?

Well, here is your init function:

function init($validations=null, $data=null)
{
   $formData = array('validations' = $validations, 'data'=$data);
   $this-controller-set('formData', $formData);
}

And you are calling it like this:

function beforeFilter()
{
   $this-Myform-controller = $this;  
   $this-Myform-init($this-User-validate, $this-data);
}

So you should be able to do this:
// seemed to work with preliminary testing...
function startup( $controller )
{
   $validations = array() ;
   foreach( $controller-modelNames as $model )
   {
  $validations += $controller-$model-validate ;
   }

   $this-controller = $controller ;
   $this-controller-set( 'formData', array( 
'validations' = $validations,
'data' = $this-controller-data ) ) ;
}

--
Regards,
Ryan Ginstrom


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Proof of concept: Custom validation using beforeValidate

2006-06-12 Thread ginstrom

I really like the idea of custom validation error messages. For
example, for a password field you could check that the password was
entered the same way twice, contains at least two numbers, no illegal
characters, etc., and give a different error message for each.

I think that validation should live in the model, so error messages
should as well. Thus, I put together a quick proof of concept using
beforeValidate(). Comments/critiques appreciated.

First, in the model, define a beforeValidate function:

function beforeValidate()
{
   $this-valMessages = array() ;
   $this-valMessages['modelValidationErrors'] = array(
  'username' = 'This username is already taken. Please choose
another' ) ;
   return false ;
}

Then, in app_controller, the following function:

function validatingSave( $model )
{
   if ( $model-save( $this-data ) ) return true ;

   $this-Session-setFlash( 'p class=errorSorry, but we cannot
process your form. Please make the changes indicated below, and try
again./p', '' );
   $this-data += $model-valMessages ;
   return false ;
}

Next, in the controller's edit function, change the save line to this:

if ( $this-validatingSave( $this-Attachment ) )
{
$this-Session-setFlash( 'p class=successYour profile has been
updated./p', '' );
$this-redirect( /users );
}

Now in your ErrorHelper, you should have access to
$this-data['[modelValidationErrors]']
If it's set and the field is set, you can show the custom error message
for that field, or if not, the fallback validation error message from
HtmlHelper.

Does this sound like a good direction to take my validation? Thanks for
any feedback.

--
Regards,
Ryan Ginstrom


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



RE: Having trouble with session checking.

2006-06-02 Thread Ryan Ginstrom

 [mailto:[EMAIL PROTECTED] On Behalf Of radioflyer
 In the models that I completely shutdown with:
 var $beforeFilter = array('checkSession');
 everything is hunky-dory.

How about:

function beforeFilter( )
{
if ( in_array($this-action, array( 'edit', 'add', 'delete' )))
{
$this-checkSession() ;
}
return true ;
} 


Regards,

--
Ryan Ginstrom


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Variables in routes

2006-05-24 Thread ginstrom

First I would like to say that I am really enjoying using cake. It
makes site development much easier and more fun.

I am using cake 1.0.xx, PHP 4.4.3-dev (PHP 5 available, by default used
for .php5 extension)

I am trying to figure out how to handle my url structure. I am
developing a site for an annual conference. Since most of the pages for
each conference will be the same, I want to do something like:

/conf-1/presentations/
/conf-1/presentations/view/1
/conf-2/presentations/
...
and so on, where conf-? is a variable that I pass to the appropriate
controller, so it knows which conference to retrieve the information
for.

What I would really like is to match /conf-(\d)+/, and use that as the
first param. So for instance,

/conf-1/presentations/view/1

would call
PresentationsController::view( $conf, $id )
with $conf = 'conf-1' and $id = 1

I hope someone can tell me a way to do this, or a better way to do what
I want to do. I also apologize in advance if this has been covered
before. I have done a search, and found the tantalizing reference to
dealing with i18n by AD7six, e.g. in routes.php:

$Route-connect ('/en/:controller/:action/*',
array('controller'='pages', 'action'='view', language=en));

But here the languages are hard coded.
Thanks in advance for any help.

--
Ryan Ginstrom


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---