Re: Child model fields
$this-create(); I think, and I've had a bit to drink, should be $this-Game-Score- create(); DaveM wrote: Hi all, I am trying to build a page that uses a parent model (Game) and child models (Score). Game has the following fields: id, game_number, and date. Score has the following fields: player_id, player_finish, player_points, and game_id. In my scenario, there should always be 10 Score(s) per Game. I'd like to have the player_id, player_finish, and player_points rendered on the page when the Add New Game link is clicked. I've defined my Score fields as follows: tr td1/td td?php echo $html-input('Score/player_id', array('size' = '4'))? /td td?php echo $html-input('Score/player_points', array('size' = '4','value' = $valueOne))? /?php echo $html-hidden('Score/player_finish', array('value' = '1')); ? /tr tr td2/td td?php echo $html-input('Score/player_id', array('size' = '4'))? /td td?php echo $html-input('Score/player_points', array('size' = '4','value' = $valueTwo))?/td ?php echo $html-hidden('Score/player_finish', array('value' = '2')); ? /tr I don't think this is correct. In the save, the Game array ($this- data['Game']) does not contain ANY of the score domains. The last Score model defined on my view is being saved. The manual says: These same basic techniques will work if you're saving multiple child models, just place those save() calls in a loop (and remember to clear the model information using Model::create()). I tried this code thinking it would save two Score models, but it simply inserts one record and then updates the same record: $gameID = $this-Game-getLastInsertId(); $this-data['Score']['game_id'] = $gameID; $this-Game-Score-save($this-data); $this-create(); $gameID = $this-Game-getLastInsertId(); $this-data['Score']['game_id'] = $gameID; $this-Game-Score-save($this-data); I'm stuck. Any thoughts would be awesome. --~--~-~--~~~---~--~~ 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: Hidden field update using Ajax
The content that loads into the div could have some javascript that updates the hidden field value. On Jun 25, 3:19 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hello guys, I'm new on Ajax, actually I'm developing my first project using it via cake's ajax helper ... that's why I'm little confused on how to implement this functionality: I have a form which ask for a date, once you select a date it has an observeField for an input field which shows me in a div how many events I have for selected date. This is already done, now I want to pass to a hidden tag the id of the selected date once you choose one date, how can I update a div and a hidden tag at the same time? I hope you can help me ... --~--~-~--~~~---~--~~ 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: Simple association problem
Maybe set DEBUG to 2 and look at the SQL being generated. Does $this-Document-findById(1) return the same thing? --~--~-~--~~~---~--~~ 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: simple relation
Set up a belongsTo relationship in your Project model. var $belongsTo = array('Status'); should be enough. On May 24, 2:27 pm, pete [EMAIL PROTECTED] wrote: hi, i still play around with creating a simple relation, and i don't get it to run. thanks pete TABLES: status id description project id status_id project_title CONTROLLER $this-set('projects', $this-Project-findAll()); every project has one status. how do i create a relation between these 2 tables so i can print the status.description and not only the status.id VIEW project_title: Test status: Open ?? --~--~-~--~~~---~--~~ 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: Why do I have to define this?
Moaning scripts, eh? The list can't hear it. The error message would help us diagnose. Maybe your query returned no results. And I think findBySql is old skool, cuz. By that, I mean it's deprecated, use $this-Model-query() instead. On May 18, 9:22 am, Enchy [EMAIL PROTECTED] wrote: $this-set('telephone',$this-Order-findBySql(SELECT tel FROM suppliers WHERE id='$id')); echo $telephone[0][suppliers][tel]; When I do this it moans that I have to define suppliers and tel --~--~-~--~~~---~--~~ 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: URL problems
How are you setting the action of the form? You might try form action=?php echo $html-url('/users/register')? ... if your not already using a helper function On May 18, 2:03 pm, chrisdaems [EMAIL PROTECTED] wrote: Hi, I installed CAKEPHP yesterday. The installation went OK and I can connect to a database. I also tried to follow the manual provided by IBM. The first example explained a registration form, but I can't get it to work. I don't have a problem with accessing the application by typinghttp://localhost/cake/users/register. The registration form appears and I can start fill in the form. But whenever I fill in the form and try to submit, the program tries to access localhost/users/register and a message file not found appears. My OS is windows XP prof I installed WAMP the mod_rewrite module is enabled directory is as follows Directory / Options FollowSymLinks AllowOverride all Order deny,allow allow from all Satisfy all /Directory Did I missed something or does anyone know how to do a proper installation on Windows XP. Many thanks, Chris --~--~-~--~~~---~--~~ 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: session serialize handler
Maybe you could add a session_id column to your users table. When a user logs in you can store their session_id in the table. Now every time a user requests a page, check the session_id in the table against the current value returned by PHP's session_id(). If it is not the same, log the user out because someone else logged in with their name. I'm not very experienced with sessions, so I could be way off. Russell Austin On May 15, 2:49 pm, jyrgen [EMAIL PROTECTED] wrote: hm. do you mean i should rather store the login state somewhere else, in another table... ? --~--~-~--~~~---~--~~ 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: Associations to reduce # of queries
1. Don't store your results in $this-Product. That is confusing. 2. To expose data to the view use $this-set('variable_name', $data_for_variable); 3. I have never used loadModel. Instead, at the top of the controller I would add the unassociated model to the $uses array. For example in CategoriesController: var $uses = array('Category', 'Product'); /* Product is a unassociated model that we want to access */ 4. Then your code would like like $this-set('catProds', $this-Product-getProductsByCategory($id, $start, $limit, $sort)); $this-set('category', $this-Category-read()); 5. To organize the results of the getProductsByCategory function, loop through and organize the data inside the getProductByCategory before you return. 6. I think you are slightly misunderstanding the concept of a Model. You might read over the manual section again. On May 9, 5:44 am, johnvv [EMAIL PROTECTED] wrote: Ok, I was able to get around the error messages with this: // CategoryController .. function view($id){ .. loadModel('Product'); $p = new Product(); $this-Product = $p-getProductsByCategory($id, $start, $limit, $sort); pr($this); $this-set('category', $this-Category-read()); } Would show that the Category['Product'] object was populated with an array of products. For example ['Category']['Product'][0]['Product'][0]['product_name'] = 'Acme XYZ123' ['Category']['Product'][1]['Product'][0]['product_name'] = 'Acme MZ456' However the view.thtml output did not show any recognition of a Product object and I could not find a way to access it. Do I need to do a Save() call or something? I didn't even get into trying to build the ProductImage model which brings up an important question... With 1 query, can I build 2 or more Models?? For instance, if I call a function in the Product model that joins the product_image table, can I use the output to build both the Product and ProductImage models? On May 9, 12:19 pm, Jon Bennett [EMAIL PROTECTED] wrote: Hmm... ok, I understand setting up the function in the Product model to run the query but I'm confused about the CategoryController. If I try to run: $catProds = $this-Category-Product-getCategoryProducts($categoryId); you have to traverse the associations tree back. If you're working within CategoriesController, then Product is an associated table to Category. try pr($this-Category); // pr is cake shorthand for print_r hth jon --~--~-~--~~~---~--~~ 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: redirection, rendering, or manually setting a view?
You can render the home view with $this-render('../pages/home'); If you would like to set an error message and redirect you can use $this-Session-setFlash('You ain't no user!'); To display the flash message, you need this line in your layout (or view) if($session-check('Message.flash')) $session-flash(); HTH, Russell Austin On May 9, 2:23 pm, Greg Cerveny [EMAIL PROTECTED] wrote: Hello, I've created my default home page (/views/pages/home.thmtl) to include a login form for my application. This works fine, but if the login fails, I am unsure how to handle it. I would like to send the user back to the front page and display an appropriate error message. Here is my existing logic (mostly from the tutorial): function login() { $this-set('error', false); if (!empty($this-data)) { $someone = $this-User-findByUsername($this-data['User']['username']); if(!empty($someone['User']['password']) $someone['User']['password'] == md5($this-data['User']['password'])) { $this-Session-write('User', $someone['User']); $this-redirect('/ideas'); } else { $this-redirect('/'); } } } So, in the else statement... Should (Can?) I tell the controller to display the home.thtml view? Should I redirect with a url param of the error message? Should I render an action? Thanks! -greg --~--~-~--~~~---~--~~ 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: Using styles with ajax-link
If I'm understanding your question you can use $ajax-link('User Profile', '/users/profile/', array('class'='stylemyajax')) or $ajax-link('User Profile', '/users/profile/', array('style'='border: 8px dotted green')) On May 8, 4:49 pm, BigBee [EMAIL PROTECTED] wrote: I have a site that I'm migrating to cakephp. I've successfully used ajax-link for all async, non-stylized links, but I have a number of links that require various css classes for their proper layout. I've almost spent the past day reading posts and the helper document, but no luck. Can someone point me in the direction of some prose to help allow me to continue to stylize my ajax links? 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: Associations to reduce # of queries
I don't think you will have much luck getting cake to produce a similar query. But an easy solution is to wrap your query inside a function in your Product model. Say function getCategoryProducts($categoryId) { return $this-query(/*that query you've written*/); } Then you can use that in your controllers: $catProds = $this-Product-getCategoryProducts($categoryId); Just be sure to use table aliases like FROM products AS Product to make the array nicer. Russell Austin On May 8, 3:04 pm, johnvv [EMAIL PROTECTED] wrote: I'm to new using cake so file this question under 'newbies'... I have the following models: - Product (contains reference to manufacturer_id... and other information) - ProductImage (id,product_id,type [thumbnail,medium,large], image_url) - Manufacturer - Category - CategoryProduct (category_id, product_id) Each Category has many Products Each Product has 3 ProductImages (thumbnail, medium, large) - maybe could be 3 separate hasOne associations with conditions for each type Each Product has 0 or 1 Manufacturer I'd like to minimize the number of queries when viewing the products in a category. I've tried many different associations but each time cake has generated separate queries to obtain the images and manufacturers. Without cake, this can be accomplished with 1 query. It would look something like this: SELECT product.*,product_image.*,manufacturer.* FROM category_product INNER JOIN category ON category.category_id = category_product.category_id INNER JOIN product ON products.product_id = category_product.product_id INNER JOIN product_image ON product_image.product_id = product.product_id AND product_image.type = 'thumbnail' LEFT JOIN manufacturer ON manufacturer.manufacturer_id = product.manufacturer_id WHERE category_product.category_id = $id ORDER BY $sort LIMIT $start, $limit But everything I have tried in cake has resulted in 40-some queries to accomplish the same result. Any ideas? --~--~-~--~~~---~--~~ 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: Benefits of Admin Routing
Much better than my line! As far beforeFilter and beforeRender, you can look at the API for the differences, but I think either would work for this purpose. On May 7, 1:00 pm, jitka [EMAIL PROTECTED] wrote: and that one line of code just changed my entire outlook on admin routing! if (!empty($this-params[CAKE_ADMIN])) --~--~-~--~~~---~--~~ 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: views (layouts and menus)
Layouts: In which action are you setting the variable? In general, it will only be available for the view of that action. Menus: I would put the menu in an element. Or if the structure of your pages allows, put it in the layout file. (no extra data passing) HTH, Russell Austin On May 7, 1:20 pm, Greg Cerveny [EMAIL PROTECTED] wrote: Hello, I'm creating a sample cakephp app just to play with. Question 1: Layouts I want to greet the user and keep that at the top of every page (ie Hi Greg), however none of the variables I set seem to be available to my layout file. Are we able to pass more than the pagetitle into the layout files? Question 2: Menus I want to include a navigational menu for the users. Is this best included in an element or view? I noticed the elements seem to be called from directly views, with arrays passed in. Seems like a bit of extra data pushing to send information to a view, and then into an element, but on the other hand, it seems like a highly reusable component best suited for an element. --~--~-~--~~~---~--~~ 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: Benefits of Admin Routing
From what I know, admin routing is mostly an organizational tool. However, if you are using othAuth, it does simplify access control. You only have to add 'admin' to the $othAuthRestrictions array, and all your admin routes are covered. And as far as layouts go, you could put the following line in beforeFilter() in app_controller.php if(substr($this-params['action'], 0, 6) == 'admin_') $this-layout = 'admin'; Russell Austin On May 6, 4:35 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi all - Cake newbie, first post. Can somebody simply explain the advantages of using Cake's built-in admin routing? I have it enabled and understand the base functionality and it seems to me that it just generates a lot of duplicate code and doesn't necessarily help out with auth or acl. I feel like I'm missing the point. In a nutshell I want to use a different layout, auth and acl for the admin section. I'm just getting the impression that I'm going to have to write my own admin controller... is this the case, or what am I overlooking? Thanks for the help! McFadly gushingLoving Cake so far. Wish I would have realized the power a year ago./gushing --~--~-~--~~~---~--~~ 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: Convert img html tags to cake $html-image code
In the find and replace dialog of Textpad I use Find what: src=images/\(.*\.gif\) Replace with: src=?php echo $html-url('/img/\1')? It assumes your images were in a directory called images, and now you have moved them to img in the cakePHP directory structure. The regular expression is greedy, so you will run into trouble if there is more than one image on a line. Also, you will have to run it again for jpg images. I'm sure some more competent regex users could improve on this. On May 4, 9:22 am, Joel [EMAIL PROTECTED] wrote: I'm converting my site with a lot of img src=... html tags to cakephp. The major problem is convert all these tags to cakephp $html- image helper tags. Is there any tool to automatize this process ou another method to do this without rewrite all these tags? --~--~-~--~~~---~--~~ 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: Redirect (location) from javascript
You can get a cake friendly URL with the $html-url function, eg window.location = '?php echo $html-url('/users/profile/')?'; On May 4, 8:32 am, Romano [EMAIL PROTECTED] wrote: Hi all, A newby question: how do I code a window.location redirect in javascript? I cannot seem to find the correct path to any of my views in the way that the $html-link helper does. Best regards, Romano --~--~-~--~~~---~--~~ 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: two foreign keys referencing the same field in the same table
In a project I'm working on, I have a messages table as well. In the message.php I have the following association var $belongsTo = array( 'Recipient' = array('className' = 'User', 'foreignKey' = 'recipient_id', ), 'Sender' = array('className' = 'User', 'foreignKey' = 'sender_id', ), ); The className is User for both, but the instances of the class have unique names, ie Recipient and Sender. Now if you want to get all the messages sent by user id 2: $sentBy2 = $this-Message-findAll(array('Sender.id' = 2)); //didn't test this Hope that helps, Russell On Apr 9, 8:41 am, erdbeerelse [EMAIL PROTECTED] wrote: hello, I have a question about naming convention with foreign keys. in my first table (users) I have a primary key id, which is the user id followed by username, useradress in my second table (msgs) I save messages from a user to a user. So I want to reference the foreigns keys fromuser and touser to the table users and the field id. the conventions say, that the foreign key in my table msgs should be user_id (=table_fieldname). My problem is, that I need this foreign key twice just like: from_user_id and to_user_id Could anyboldy please help me to figure it out? 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: Multiple databases using same app and cake core
Addendum: The last two items cause PHP to give a notice because those constants are defined later on. I had to define the APP_PATH because cake \bootstrap.php and cake\libs\configure.php use it to find core.php and bootstrap.php. This seems to work, and now when I need to fix bugs in my code I only have to fix them in once place. -- Russell --~--~-~--~~~---~--~~ 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: Multiple databases using same app and cake core
francky06l, Your approach work great! It gets rid of the pesky notices, and it will make it easier to do master reports about all systems. BTW, so I didn't have to change each model, I put the line var $useDbConfig = CLIENTDB; in app_model.php and that seems to work. Thanks, Russell On Mar 14, 11:00 am, francky06l [EMAIL PROTECTED] wrote: you can use the same database.php. In this one you could define different database ie : 'client1', 'client2' etc config ..In your index.php you could define a value set to the spotted DB (ie : define('CLIENTDB', 'client1'); and at the end in your models you could set : var $useDbConfig = CLIENTDB; that will point your models to the desired DB. Hope this helps On Mar 14, 6:12 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hello all, I was hired to develop an application that is now going to be sold as a service. So customers pay a fee and we install an instance of the application with their branding on our server. I am figuring out how to install and manage the instances. I plan is to share the cake and app folder among all the installations, but create a unique webroot and config folder for each client. The config folder is necessary so I can use a client-specific database.php and define client-specific constants in the bootstrap.php. I was able to get a test working on my development box, but I had to force my will upon cake a bit, and I want to know what you fellow developers thought of my approach. Is there a better way? WHAT I DID: For this example, I am creating an instance for a client called foo 1. Create folder foo 2. Copied webroot of original app to foo folder 3. Copied config of original app to foo folder 4. In foo/webroot/index.php: - i. changed ROOT to point to original app directory - ii. added the line: define('CONFIGS', dirname(dirname(__FILE__)).DS.'config'.DS); - iii. added the line: define('APP_PATH', dirname(dirname(__FILE__)).DS); --~--~-~--~~~---~--~~ 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: obAuth with Cake 1.2.x
I recall I similar problem that I fixed by adding var $uses = array('User', 'LoginAttempts') to app_controller.php. That might be the kludge you need. On Mar 14, 10:52 am, rtconner [EMAIL PROTECTED] wrote: Has anyone used obAuth with Cake 1.2.x? I am getting an error that I'm having trouble fixing. Undefined property: obAuthComponent::$User [CORE\app\controllers \components\ob_auth.php, line 46] It seems that the componant cannot locate a the Model User within the UserController. I have tried loadModel, but that does not seem to fix it for me. Any ideas? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---