Re: 3 table join help?
hm... i'm not sure what you are trying to do. the conventions are http://manual.cakephp.org/appendix/conventions . so you should name the model CarMakeYear and the file car_make_year.php. However, it sounds like you need a Car model, a Make model, and a Year model. Then use cake associations and the {$model}->findAll() function to query the database. The associations you choose really depend on what you are doing and can be overwritten at runtime, but an example might be: Car hasOne Model, Make Model hasMany Car belongsTo Make Make hasMany Car, Model --~--~-~--~~~---~--~~ 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: Model->findAll() based on conditions for an associated HABTM model - any progress?
thanks AD7six, ugly, but works. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How do i use findAll to sort one model by a second?
Hey, i have two models Post and Wiki. A post is a simple table with an 'id' and a 'wiki_id'. The Post table hasMany Wiki. Each of which store all the information about that post revision, including the 'created' field. The UI of my project references the Post 'id' so a simple search might be to five the 5 most recent posts. A direct sql statement would look something like this: SELECT Wiki.* FROM posts Post, wikis Wiki WHERE Post.wiki_id = Wiki.id ORDER BY Wiki.created DESC i've read that you can use the findall to do just about any type of association, but i can't figure out how to properly reference other tables in my models or findall statements. Can someone please help me out? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Model->findAll() based on conditions for an associated HABTM model - any progress?
There was an post a while back about this and a trac ticket https://trac.cakephp.org/ticket/1209 I have a HABTM association between posts and tags. When a user clicks on a tag, only posts associated with that tag should be returned. Furthermore, a user can click on a series of tags to further refine their search. I have custom queries to handle this now, but i am curious where the cake team's progress is on adding this feature? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
using functions in elements
I have a recursive function that i'd like to use to optimize printing data from a multidimensional array. If i put the function in my view or element, then cake tells me that the function doesn't exist. Where should i put this function? --~--~-~--~~~---~--~~ 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: Problem with Methods in AppController!!!
Your controller has an object for each model that you tell it to use with $uses = array('Config', etc); then you need to reference this model to query the database $this->Config->query('statement'); although as John states, your query is simple. I would use the built in field function $this->Config->field('value', 'name='.$name); --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Help with Data Model for findAll querying
Hey, i've been trying to set my data model/database up to use the cake built in querying system, with partial success. I've temporarily written my own queries, except then i need to reformat the returned array to make it useful. I have several tables posts posts_users users wikis tags tags_wikis photos The logic i have setup is: posts HABTM users hasMany wikis wikis belongsTo users belongsTo posts HABTM tags hasMany photos users hasMany posts hasMany wikis tags HABTM wikis photos belongsTo wikis My goal is to do a search on post and it returns (in chunks of 5 for pagination) all the wikis and users, plus for each wiki it returns the tags and photos. The databases seem to communicate okay, but some of the parameters in my associations are completely ignored. For example i use the following statement in the controller: $this->Post->findAll(null, null, null, "5"); var $hasAndBelongsToMany = array( 'User' => array( 'className' => 'User', 'joinTable' => 'posts_users', 'foreignKey' => 'post_id', 'conditions' => '', 'order' => '', 'limit' => '', 'dependent' => true, 'exclusive' => false, 'finderSql' => '', 'deleteQuery' => '' ) ); // only return the most recent wiki var $hasMany = array( 'Wiki' => array( 'className' => 'Wiki', 'conditions' => '', 'order' => 'Wiki.created DESC', 'limit' => '1', 'foreignKey' => 'post_id', 'dependent' => true, 'exclusive' => false, 'finderSql' => '' ) ); Now when i do a find or findall cake returns array( Post = array of post row Wiki = array( 0 = array of 1st wiki row 1 = array of 2nd wiki row 2 = array of 3rd wiki row ... etc) User = array( 0 = array of 1st wiki row 1 = array of 2nd wiki row 2 = array of 3rd wiki row ... etc) ) But in my association, i asked it to only return one wiki. My first question then, is how do i get my association to only return 1 wiki, while returning 5 posts? thanks -matt --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
how do i using routing to pass an array to my action function?
hey, i'm working on a travel site and would like to use routing to change the url string into an array for easier processing in my action function. urls are formatted like this /posts/search/country_id/region_id/location_id/tag_id1/tag_id2/tag_id3/etc and might look like this /posts/search/12/34/23/1/2/3/etc my search action function is function search($country, $region, $location, $tags) i want $tags to be an array of all the tag_ids, otherwise, i have to store the tag_ids in a parsable string format that can be passed as the 4th variable i'd like to use routing to convert all the tags after location_id into an array. /posts/search/country_id/region_id/location_id/* can i do this? please, let me know how. thanks --~--~-~--~~~---~--~~ 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: how do you get beforeRender to work?
Nevermind, something elsewhere wasn't loading right and it was preventing my beforeFilter action from occuring. --~--~-~--~~~---~--~~ 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: how do you get beforeRender to work?
i've tried added $beforeFilter = array('beforeFilter'); and it still does nothing --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
how do you get beforeRender to work?
i've added this function to my appController. as far as i know this should be called automatically by every controller on my site, however, none of them do. what am i doing wrong? -thanks function beforeFilter() { echo "WTF"; $this->set('userID', 0); $this->set('username', ''); $this->set('auth', false); $this->set('query', ''); if (isset($this->HeaderVariable)) { $this->HeaderVariable->controller = &$this; } return true; } --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
What is the best ajax user login solution?
Hi, i've been looking through the different resources off the cake website and around the web over the past week, and i haven't been able to find an elegant ajax user register. I just have 4 fields: email, username, password, confirm. Confirm is not in my data model which has given me some grief. Some of the features i'm looking for are: 1) data validation in javascript and/or model all can't be empty valid email valid username between 4 & 20 alphanumeric valid password between 4 & 12 characters confirm == password 2) real-time data validation the labels updates to inform the user if the field is valid as they fill it out all fields are checked to be valid before submitting the form 3) flexible enough to be used with multiple forms on a single page most of the examples i have found require duplicating code to handle multiple forms 4) compact (many examples have ajaxValadateField1, ajaxValidateField2, etc functions; it would be much better to have a single function that can handle multiple fields from multiple forms) what ajax process do you use? if you can provide a link or explain your setup, i (and i'm sure others) would appreciate it. thanks --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
using find + recursive causes repeated data
When i use the find function to get rows from my database, i've noticed data being recursively repeated when i set the recursion value to 2 or higher. Here is what i mean. I have 2 tables Post and Wiki. A post hasMany Wikis and a Wiki belongsTo a post and a user. A wiki contains the foreign key post_id and is also connected to an image and tag table, so i need to expand to the second level. in Post i have: var $hasMany = array( 'Wiki' => array( 'className' => 'Wiki', 'conditions' => '', 'order' => 'Wiki.created DESC', 'limit' => '1', 'foreignKey' => 'post_id', 'dependent' => true, 'exclusive' => false, 'finderSql' => '' ) ); in WIki i have: var $belongsTo = array( 'Post' => array( 'className' => 'Post', 'conditions' => '', 'order' => '', 'foreignKey' => 'post_id' ), 'User' => array( 'className' => 'User', 'conditions' => '', 'order' => '', 'foreignKey' => 'user_id' ) ); in my controller i use: $post = $this->Post->find('id = ' . $id, null, '', 2); The array that is return contains: post array wiki array [0] post array again And if i wet my recursion to 3 post array wiki array [0] post array again wiki array again It seems to me that this isn't the behavoir that should be happening. i really like the easy of the find function, but i can't use it if it's do all this extra work. does anyone know why/how to fix this. thanks --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How do i validate using the model with ajax
http://wiki.cakephp.org/faq:how_do_i_validate_a_form_with_ajax?s=ajax I built a login validator using the above wiki entry. It works great, but we setup the data validation rules in the controller instead of in the model. I've created a hybrid function that can accept different fields as input instead of creating a slew of function (ajaxValidateUsername, ajaxValidateEmail, etc): function ajaxValidateInput($type) { $this->Session->write($type . '_valid', false); $regex = array( 'username' => '/^[a-z0-9][\w]{2,18}[a-z0-9]$/i', // starts/ends with alphanum; anything in between; 4-20 characters long; no case 'email' => '/^\w(\.?\w)[EMAIL PROTECTED](\.?[-\w])*\.[a-z]{2,4}$/i', // starts with character; before & after '@' has 0 or infinite '.' and characters on both sides; ends with '.' followed by 2-4 letters; no case 'password' => '/.{4,12}/', // case sensitive; 4-12 characters 'confirm' => '/.{4,12}/', // case sensitive; 4-12 characters ); $message = array( 'username' => '4-20 alpha-numeric characters', 'email' => 'not an email address', 'password' => '4-12 characters', 'confirm' => '4-12 characters', ); if (empty($this->data['User'][$type])) { // No value set $this->set('labelText', ucfirst($type) . ' - required'); } else if(! preg_match($regex[$type], $this->data['User'][$type])) { $this->set('labelText', ucfirst($type) . ' - is invalid (' . $message[$type] . ')'); // TODO: FIX isUnique function, isn't properly detecting } else if($type != 'password' && $type != 'confirm' && ! $this->User->unique(ucfirst($type), $this->data['User'][$type])) { $this->set('labelText', ucfirst($type) . ' - is taken, try another'); } else if($type == 'confirm' && $this->Session->read('password_valid') != $this->data['User'][$type]) { $this->set('labelText', ucfirst($type) . ' - passwords do not match'); } else { $this->set('labelText', ucfirst($type) . ' - ok'); $this->Session->write($type . '_valid', $this->data['User'][$type]); } /* if ($this->User->load_validation()) { $this->set('labelText', ucfirst($type) . ' - passwords do not match'); } else { }*/ $this->set('type', $type); $this->render('label', 'ajax'); } I think it would be much cleaner if i could use rules i setup in model instead. Is there a way to use the $validate variable to test only one of the rules in validate (such as just username) and capture the message so that i can use $this->set('labelText', 'message') to pass the message to my label. The validate variable array i've setup is $this->validate = array( 'username' => array( 'required' => array( 'method' => VALID_NOT_EMPTY, 'message' => 'Username - invalid (required)', ), 'format' => array( 'method' => '/^[a-z0-9][\w]{2,18}[a-z0-9]$/i', 'message' => 'Username - invalid (choose 4-20 alpha-numeric characters)', ), 'unique' => array( 'method' => 'unique', 'message' => 'Username - invalid (already in use)', 'parameters' => array('username', $_POST['data'][$this->name]['username']), ), ), 'email' => array( 'required' => array( 'method' => VALID_NOT_EMPTY, 'message' => 'Email - invalid (required)', ), 'format' => array( 'method' => VALID_EMAIL, 'message' => 'Email - invalid (not an email)', ), 'unique' => array( 'method' => 'unique', 'message' => 'Email - invalid (already in use)', 'parameters' => array('email', $_POST['data'][$this->name]['email']),
Re: How do i use $javascript->event ????
Oh... thanks nate, that makes a lot of sense. couple follow up questions: 1) is it considered best practice with the framework to handle events this way? if not, what is? 2) can i use a callback function as the variable in the observer such as event('myid', 'click', 'myFunction'); ?> thanks --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How do i use $javascript->event ????
Hey, i'm relatively new to cake. Prior to this framework I have been using the YUI toolkit for my javascript needs. >From my experience with setting listeners in javascript and YUI I would expect this function to work like: javascript->event('elementID', 'callbackfunction'); However, this doesn't seem to do anything. I can't find any useful information on the cakephp site or the wiki or this group, explaining what this function does or what the inputs really are. event * string $object ??? * string $event ??? * string $observer ??? * boolean $useCapture ??? In my code i have [my link] If anyone could please explain what these values are and how i should use them or point me to where some useful information is, i would really appreciate it. thanks --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---