Re: how to access other models from non parent controller
Well usually in controller you work only with default model for the controller binded by conventions and its related models, but in some situation you would like to create a dummy controller which is not using any model, or attach a non-related models for using in the controller. There is where a $uses variable comes handy. d. On 14. Júl, 03:18 h., ビシャルfrom Nepal [EMAIL PROTECTED] wrote: Thank You very much for your help. It really worked for me. Anyways I was thinking why was cakephp using this $uses when other similar frameworks like Rails doesnt impose such syntax. On Jul 13, 3:18 am, duRqoo [EMAIL PROTECTED] wrote: Hey, you need to tell C1 to use M2 model using the $uses public attribute of controller, which is an array of class names of models that a certain controller will use. So in this case just add var $uses = array('M2'); to your C1 controller. If Models are somehow related to each other you dont need to include them using $uses variable, just touch the related model through default controller model. Like $this-M1-M2-find(...); Hope that helps. d. On 12. Júl, 05:08 h., ビシャルfrom Nepal [EMAIL PROTECTED] wrote: Suppose we have two controllers C1 and C2, Similarly M2 is the corresponding models to controller C2.Controller C1 is not using any models. How should I fetch table rows from M2 remaining in controller C1. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: how to access other models from non parent controller
Hey, you need to tell C1 to use M2 model using the $uses public attribute of controller, which is an array of class names of models that a certain controller will use. So in this case just add var $uses = array('M2'); to your C1 controller. If Models are somehow related to each other you dont need to include them using $uses variable, just touch the related model through default controller model. Like $this-M1-M2-find(...); Hope that helps. d. On 12. Júl, 05:08 h., ビシャルfrom Nepal [EMAIL PROTECTED] wrote: Suppose we have two controllers C1 and C2, Similarly M2 is the corresponding models to controller C2.Controller C1 is not using any models. How should I fetch table rows from M2 remaining in controller C1. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: HABTM Relations and additional info in the rlation table
Hey XuMiX, with cake u are able to save meta data within join table, but it's somehow a tricky part. I suggest you to read (http://cricava.com/blogs/ index.php? blog=6title=modelizing_habtm_join_tables_in_cakephp_more=1c=1tb=1pb=1) to get the point. First of all when saving habtm related data the join-table is auto- modelized for you. If you aim to save meta data in the join table, you will surely like to validate it as well, so good start is to create model for your join table (in your case GroupsPerson, note: convention is person = people), where you can define belongsTo associations to habtm related models so as validation for the meta-data and one more important thing which i will cover later. Now when you have your join-table model i assume you are familiar with saving habtm data without meta data in join table (reminder: $this- data['RelatedModel'] = array of associated ids). In case of meta-data thing you just have to format that passed array other way so for your example if you are saving new Group and it's associated people it would be like this: array( 0 = array( person_id = XYZ, year = 123541, amount = 123123 ), 1 = array( person_id = ABC, year = 1212, amount = 123 ) ... ); Last and most important thing is when workin with meta data in join table. You have to change the database structure of it. Basicaly join- table is a weak entity type consisting of foreign keys of related tables which are together creating primary key of the join table. Unfortunatelly cake don't know how to handle multicolumn primary keys so you have to create a autoincrementing ID primary key for your join table, and the associated foreign keys, well they just stay FKs. For your case it will be groups_people ( PK(id), FKs(group_id, person_id) ) This way everything will work ok and cakes sqls will be generated properly. Remember the one important thing i've noticed up there ? Ya you now have to ensure that the changed join-table still works as it should, that means it have correct data. The fact the primary key is now ID it allows you to save multiple same associations which is not good. You can avoid this by adding a beforeSave callback to the join-table model and aborting the save process if you find already existing combination of FKs in the join table. Hope that helps. d. On 11. Júl, 09:19 h., XuMiX [EMAIL PROTECTED] wrote: and one more thing according to this code in model.php if (!empty($newValues)) { $fields = join(',', array( $db-name($this-hasAndBelongsToMany[$assoc]['foreignKey']), $db-name($this-hasAndBelongsToMany[$assoc] ['associationForeignKey']) )); $db-insertMulti($this-{$join}, $fields, $newValues); } there is no way to save additional data On 2 июл, 23:23, James K [EMAIL PROTECTED] wrote: CakePHP has no problem reading extra fields in your join table. As long as you're naming your join table correctly and have a hasAndBelongsToMany relationship to the model on the other side of the join table, it'll pull the extra fields from a find automatically. On Jul 2, 5:35 am,XuMiX[EMAIL PROTECTED] wrote: i have a habtm relation, persons, groups, and a relation table groups_persons i need to add some more info into the relation table, for instance year of presence, role, etc. how do i get that info within cake ? Or how do i organize my tables and models? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Saving multiple associations in HABTM
Hi, in your case try setting $this-data['Group']['Group'] = (array of ids), before save. That should work, there is an explanation about how to save related model data (HABTM) in the cake cookbook. (http://book.cakephp.org) cheers On 1. Júl, 11:15 h., lysd [EMAIL PROTECTED] wrote: Hi This has probably been asked before, but I couldn't find any docs or posting on how to save multiple associations in a HABTM setup. I have Groups HABTM Users. When I create a new user, I want to be able to associate multiple groups with this new user, but I can't seem to get it. The association is created properly if I assign 1 group with 1 user... $this-data['User']['id'] = 11; $this-data['User']['username'] = 'beth'; $this-data['User']['password'] = $this-Auth-password('beth'); $this-data['Group']['id'] = 3; $this-User-save($this-data); The corresponding record will appear properly in groups_users table. But what about multiple groups? I've tried $this-data['Group']['id'] = array(2,3) to associate with groups 2 and 3, but it didn't work. any help please thanks L. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Sending Newsletter problems
Hello, i've was solving similar functionality not so far ago, but it worked without problems. It's really strange that your emails size is growing, but one thing i've noticed from your code is that you are sending mails to each address separately. Try using $cc or $bcc attribute, so u can send same mail to more then one address at once. So get all addresses to an array assign them to $cc or $bcc variable and execute the send method just once, maybe that will help solve your issues in case you don't have any crazy text stacking loop in mail template :). Note: You will have to split mail addresses to smaller array parts and send those through loop anyway. Depends on mail server restrictions how many CC or BCC addresses are allowed for one mail, otherwise you will get 'to many recipients' error. Cheers, hope it helps. duRqoo On 6. Máj, 15:55 h., mbavio [EMAIL PROTECTED] wrote: Hi bakers, I have a little problem and I cant fint a decent solution, so I thought that here someone would delight me with some brilliant solution... I´m sending massive mails (Newsletter) to about 300 people. After the first sent, some users complained that the mail was producing an Outlook error of memory, and they cant open the email. After that, I tested the app sending the Newsletter to my email boxes, in a massive way. After doing that, I´ve seen that the email size increases after every sent. First I have mails of 18kb, and the last mails are about 50kb. I´m going to show my code now: function sendEmails(){ set_time_limit(0); $this-edition = $this-Mail-whatNewsIs(); $this-newsData = $this-Mail-Newsletter-getNewsData($this-edition); $sends = $this-Mail-find('all', array('order' = 'Mail.id ASC', 'limit' = $this-limit, 'restrict' = array('Mail'))); $this-Email-replyTo = 'Acep News [EMAIL PROTECTED]'; $this-Email-from = Acep News [EMAIL PROTECTED]; $this-Email-sendAs = 'html'; $this-Email-template = 'newsletter'; $this-Email-layout = 'newsletter'; $this-set('edition', $this-edition); $this-set('narticles', $this-newsData); if(!empty($sends)): foreach ($sends as $send): if ($send['Mail']['newsletter_id'] != $this-edition) { $this-_changeNew($send['Mail']['newsletter_id']); } $this-Email-subject = 'Newsletter Edición ' . $this-edition; $this-Email-to = $send['Mail']['email']; if($this-Email-send()) $this-Mail-del($send['Mail']['id']); endforeach; $this-Email-reset(); $this-Email-to = [EMAIL PROTECTED]; $this-Email-subject = Tiempo tardado; $this-Email-from = AcepNews [EMAIL PROTECTED]; $this-Email-template = null; $this-Email-sendAs = 'text'; $content = date('d-m-Y H:i:s'); $this-Email-send($content, null, null); endif; } As you can see, I´m using template and layout, and no, I havent proved yet to send the mail without the use of template and layout. Well, anybody has been in some similar situation? Any kind of help is apreciated. Thanks! mbavio --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
modRewrite issues on subdomain
Hello, I've finished project(1.2.0.6311) for a client and now i'm trying to run it on production host(shared-server). Unfortunately after setting all up i'm not able to make the site working. On the development server everything works perfectly, but the production server is giving me some unexpected errors. If i try to load root page i get an error that there is no webroot action in app controller, because it's trying to load app/webroot extracted from REQUEST_URI as controller/action. If i add a parameter to the URL, i get expected site and results (see below). I've made a test code which i uploaded to both servers (development and also production), to see how the rewrite engine handles url requests. Both are running as subdomain, php5, modRewrite working, everything is in it's place. I use these .htaccess files: in / RewriteEngine on RewriteBase / RewriteRule^$ app/webroot/[L] RewriteRule(.*) app/webroot/$1 [L] in /app RewriteEngine on RewriteBase / RewriteRule^$webroot/[L] RewriteRule(.*) webroot/$1[L] in /app/webroot RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] I've run two URL requests for both servers. First withou parameters, just to load root page, and Second with paramater so i'll be accessing some inner page. And here are the results: Without Parameter = Root page + DEVEL SERVER (http://test.binary-love.sk/) [DOCUMENT_ROOT] = /services/www/www.binary-love.sk [QUERY_STRING] = [REQUEST_URI] = / [SCRIPT_NAME] = /app/webroot/index.php + PRODUCTION SERVER (http://reality.biely-dom.sk/) [DOCUMENT_ROOT] = /data/web/biely-dom.sk/sub/reality [QUERY_STRING] = [REQUEST_URI] = /app/webroot/ [SCRIPT_NAME] = /app/webroot/index.php With Parameter = Inner page + DEVEL SERVER (http://test.binary-love.sk/skuska) [DOCUMENT_ROOT] = /services/www/www.binary-love.sk [QUERY_STRING] = url=skuska [REQUEST_URI] = /skuska [SCRIPT_NAME] = /app/webroot/index.php + PRODUCTION SERVER (http://reality.biely-dom.sk/skuska) [DOCUMENT_ROOT] = /data/web/biely-dom.sk/sub/reality [QUERY_STRING] = url=skuska [REQUEST_URI] = /app/webroot/skuska [SCRIPT_NAME] = /app/webroot/index.php As you can see production server is always prepending /app/webroot to the [REQUEST_URI], which is smth that causes error described at the beginning. I think i know the reason why it ends like this. When i request root page, rewriteRule in /.htaccess sends me to /app/webroot. The [REQUEST_URI] already contains /app/webroot which don't pass the rewriteCond in /app/webroot/.htaccess, because it will treat the URL request as directory and the rewriteRule in there is skipped. After that dispatcher parse the [REQUEST_URI] and i'm getting my error. Any1 knows what could cause this? or better to ask how can i get rid of that /app/webroot prefix on production server. Must be smth with configuration mod_rewrite or doc_root or vhost or apache i don't know. I've deployed 3 other cakephp projects without problems, but here i'm lost. Thanks for advice, d. --~--~-~--~~~---~--~~ 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?hl=en -~--~~~~--~~--~--~---
Re: Image as Title in Paginator prev and next
Sure u can do that, just add 'escape'=false to the options array. On 11. Feb, 00:08 h., Tomka [EMAIL PROTECTED] wrote: Hello, I'm using Version 1.2. Is it somehow possible to use an image or another html-content as title in the paginator's prev- and next-methods? Unfortunately my html is escaped. I'm looking for a parameter like in link ($title, $url=null, $htmlAttributes=array(), $confirmMessage=false, $escapeTitle=true) the last one. Thanks for answers. Tomka --~--~-~--~~~---~--~~ 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?hl=en -~--~~~~--~~--~--~---
Re: user authentication example...login redirects
var $validate = array( 'name' = array( 'rule' = array('custom', VALID_NOT_EMPTY), 'message' = 'Can\'t be empty' ) ); This is how i deal with not empty values. VALID_NOT_EMPTY may be deprecated, but still it's just a constat so i can replace it with whatever regexp i want. AFAIK 'allowEmpty' is false by default and it's checked before rule description, and if u dont specify rule key in field validation array it will default to 'blank'. In your example Zoe field name will always invalidate because it can't be empty, thanks to 'allowEmpty', but rule defaulted to 'blank' expecting it to be empty. On 9. Feb, 09:36 h., MonkeyGirl [EMAIL PROTECTED] wrote: The 'allowEmpty' key should be assigned a boolean value. Ah, thank you. That makes sense. So I've replaced this: var $validate = array( 'name' = array( 'required' = VALID_NOT_EMPTY ) ); With this now: var $validate = array( 'name' = array( array( 'message' = 'required', 'allowEmpty' = FALSE ) ) ); Is that right? (I know it technically works, I just want to make sure I'm doing it the proper way). Thank you, Zoe. --~--~-~--~~~---~--~~ 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?hl=en -~--~~~~--~~--~--~---
Re: Is there a good solution for this?
AFAIK you can't use variable after LIMIT so u can't get your result set in one call. I would make model function which at first will retrieve visiblecomments number and then use it as value for 'limit' key in options array for find function. On 9. Feb, 03:18 h., freespac [EMAIL PROTECTED] wrote: I have to tables, stories and comments. They have a relationship story has many comments. comment belongs to story. In stories, I have a field named visiblecomments (yes it's long ;) I want to return only a number of comments (that is defined in visiblecomments) in every story. Example: Story 1: id: 1 title: this is first story. visiblecomments: 2 has 4 comments. Story 2: id: 2 title: this is second story visiblecomments: 1 has 5 comments. I want it to return the following: 2 comments from the first story and 1 comment from the second story. hope that made any sense.. -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?hl=en -~--~~~~--~~--~--~---
Re: Issue with allowEmpty and required in multiple validation rules (1.2)
Hello Benjamin, this should work: 'password' = array( 'notNull' = array( 'rule' = array('custom', VALID_NOT_EMPTY), 'required' = true, 'message' = 'Please enter a password.' ), 'between' = array( 'rule' = array('between', 4, 12), 'message' = 'Please check the number of characters in your password.' ) allowEmpty defaults to false so u don't need to specify it unless u want to change it. I think allowEmpty and required options are checked before the rule specification. So if allowEmpty is false and u submit no data, cake won't check the rule because validation will return false anyway. When you are using multiple validation rules per field, cake will check all of those rules. That means, in your case, if your first rule fails, your second rule will fail too and u'll get 'between' rule error msg even when the password was empty. If you want to change this behaviour you can simply add 'last'=true option to desired rules, which will force cake to stop further validation for certain field if one of them invalidates. Cheers. On 3. Feb, 11:06 h., cisbrh [EMAIL PROTECTED] wrote: Hi everybody, first of all thank you for the really good work you've doing on cake. I've used it 2 years ago for a massive application and I had to write my own postgresql layer... The work done since then especially on 1.2 is amazing. Anyway. I am trying to use multiple validation rules (1.2) with allowEmpty and required but I just can't get it working. I've look at the sources and it looks like the 2 keys must be included in their own rule declaration ie: 'password' = array( 'notNull' =array( 'allowEmpty' = false, 'required' = true, 'message' = 'Please enter a password.' ), 'between' = array( 'rule' = array('between', 4, 12), 'message' = 'Please check the number of characters in your password.' ). But that does not work because model will default the keywords value for 'rule' to 'blank' !!! So what value should I give to 'rule'. If I put allowEmpty and required outside a rule declaration it breaks completely ie: 'password' = array( 'allowEmpty' = false, 'required' = true, 'message' = 'Please enter a password.', 'between' = array( 'rule' = array('between', 4, 12), 'message' = 'Please check the number of characters in your password.' ). so I am a bit stuck. I guess I could use a custom rule which always return true and let required and allowEmpty to invalidate if needed but surely there is a better way ? Thanks in advance. Benjamin --~--~-~--~~~---~--~~ 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?hl=en -~--~~~~--~~--~--~---
Re: Order validation check and order message error
When you use multiple rules per field you can add 'last'=true option to desired validation rule. It will force cake to stop validating other rules for current field if a rule with that option invalidates. On 29. Jan, 12:56 h., Reny [EMAIL PROTECTED] wrote: Hi all, I have question about validation I have a 'email' text input field, I check in my model that this field isn't empty and it's unique in my db. It's work but I'd like that when the first rule is not satisfied it don't try to check the second rule. Now it check first rule (if blank it set required), so it check second rule and it overwrite my first message and it display unique myview: ?php echo $form-input('email', array('error' = array( 'required' = 'Please specify a valid email', 'unique' = 'Please insert a unique email' ))); ? mymodel: var $validate = array( 'email' = array( 'required' = VALID_NOT_EMPTY, 'unique' = array( 'rule' = 'checkUnique', 'email')) ); function checkUnique($data, $fieldName) { $valid = false; if(isset($fieldName[0]) $this-hasField($fieldName[0])) { $valid = $this-isUnique(array($fieldName[0] = $data)); } return $valid; } thanks all!!! --~--~-~--~~~---~--~~ 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?hl=en -~--~~~~--~~--~--~---
Re: Model with no data source / database - how to do this in CakePHP 1.2?
You still have to have database.php file in your /app/config. Content of the file is list of data sources u will use in your app. Default one must be there, otherwise it will throw you those fatal errors. So your database.php file should at least look like this (copied from database.php.default). class DATABASE_CONFIG { var $default = array( 'driver' = 'mysql', 'persistent' = false, 'host' = 'localhost', 'port' = '', 'login' = 'user', 'password' = 'password', 'database' = 'database_name', 'schema' = '', 'prefix' = '', 'encoding' = '' ); } --~--~-~--~~~---~--~~ 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?hl=en -~--~~~~--~~--~--~---