Re: File Uploading
¿Did you put the attribute enctype=multipart/form-data in the form? --~--~-~--~~~---~--~~ 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 For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Add property last = true to every validation rule
?php class AppModel extends Model { function beforeValidate() { foreach ($this-validate as $field) { foreach ($field as $rule) { $rule[last] = true; It seems that your error comes from a misunderstanding of the foreach constructor in PHP. The foreach iteration creates a _copy_ of each element of the array (the value returned by the each function) when iterates, hence the code block inside the foreach works with the copy of the array element instead of the actual array value. Try using references, as is explained in the PHP Manual foreach ($this-validate as $field) { foreach ($field as $rule) { } } And study the documentation: http://www.php.net/foreach http://php.net/manual/en/function.each.php --~--~-~--~~~---~--~~ 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: Wamp cakePHP allright except bake
Enable the mysqlcli (Command Line Interface) module in PHP It doesn't use to be enable by default. The PHP's mysql module for command line isn't the same mysql module used in CGI/Apache Module. See the php.ini file and php documentation for detail (usually you just have to uncomment a single line in the php.ini file --~--~-~--~~~---~--~~ 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: CSV file as DataSource
Use the ConnectionManager::getInstance() method to get the DB Manager instance, and set manually the database. $conn = ConnectionManager::getInstance() $conn-config['file'] = 'your_csv_file'; --~--~-~--~~~---~--~~ 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: CSV file as DataSource
Actually, it is (assuming your db configuration variable is called default): $conn = ConnectionManager::getInstance() $conn-config-default['file'] = 'your_csv_file'; --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to save recursively with a hasOne relation
I have the following models: Users (id, name, ...) Preferences (id, user_id, ...) With the relationships User hasOne Preference and Preferences belongsTo User set in each model. I created a form with all fields for either users and preferences. $form-create('User',Array('action' = 'register')); $form-input('User.name'); /*...*/ $form-input('Preference.country'); $form-input('Preference.gui_skin'); /*...*/ $form-end('Create User'); In the model, I have function register () { $this-User-recursive = 1; $this-save($this-data); } Altought, in the above save call, the data is saved only in the User model, Is there a way for perform the save recusive, namely, that the User::save create recursively the asociated Profile too? --~--~-~--~~~---~--~~ 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: What is the proper way of adding script to the layout?
- css - I want to include some css files only when I use Elements or helpers they are used by. Is it any way to do this in cakephp? Or have I include all css files into all pages? I prefer to include all css scripts in the head. It has tow advantages: - The includes are made in one place in my layout, so it's easier to add or remove stylesheets (just add or remove the css include in a single file) - The browsers use to cache all the files. Hence, if a user request a page that loads a lot of javascripts and css's, in the next request this includes will be cached and the request will be faster. - javascript - I have on-dom-ready js function in header and I want to add some script to it. I think I can do this by some kind of element filled from view but maybe there is a better way? If the scripts are complex, put all scripts in a js file and include it in the template. If your scripts are little bocks of code, user the $javascript- codeBlock() method for including your javascript where it is necesary. --~--~-~--~~~---~--~~ 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: Question on the best way to proceed and stay true to MVC/CakePHP philosophy
Set the name attribute into the CommandParser class (If your are using PHP 4 the name attribute is mandatory as it is in models and controllers). class CommandParserComponent extends Object { var $name = CommandParser; //the rest of the code. } --~--~-~--~~~---~--~~ 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: startpage with different layout
Just set the layout in the first line of your view ?php $this-layout=foo ? and after this line all your presentation code. --~--~-~--~~~---~--~~ 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: Question on the best way to proceed and stay true to MVC/CakePHP philosophy
if(function_exist( $this-{$command}()) ){ For testing the existence of cass methods, you should use method_exists instead. if (method_exists(get_class($this),$command) { //blah blah } With this fix i think that this idea would work too, --~--~-~--~~~---~--~~ 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 Handle Special Fields on $this-query() statements - Forking from MySQL Having Clausule
Use Set classs for manipulating your find's results, particularly the Set::combine method maybe helpful for you.. http://book.cakephp.org/view/662/combine --~--~-~--~~~---~--~~ 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: Troubles doing a complex find
AND logical operator is asociative, hence: 'OR' = Array ( 'AND' = Array ( /*put all conditions here*/) ) is equivalent, and here you don't rewrite the Array index. --~--~-~--~~~---~--~~ 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: Question on the best way to proceed and stay true to MVC/CakePHP philosophy
I think first that all you have to separate the parsing of the text and the execution of the command itself via components, namely: 1) Create a CommandParser component that has function to parse a command. 2) Create a CommandExecutive component that has a method for implement each of the commands. I suggest you to handle the user input in a unique action in the controlle. For example, create a send action where all the user text is sent: class ChatController extends AppController { var $components = Array('CommandParser','CommandExecutive'); /*handles all text send by user*/ function send($text) { /*analize wherter the input is a command or is plain text*/ if (CommandParser::isCommand($text)) { //is a command redirect for command execution //use the parser component to get the command and the parameter of the command $command = CommandParser::getCommand($text); $parameter = CommandParser::getParameter($te $this-redirect(/chat/command/$command/ $parameter); } else { //is normal text, show $this-redirect(/chat/add/$text) } } //here is the rest of actions function add ($text) { //perform logic of add text } function command ($command, $parameter) { //perform logic of command } } For executing the command you can avoid the big switching statement by using an array of callbacks indexed with the command names. All callbacks are methods defined in the ActionExecutive component itself. For example: //this function may be in the controller function proccessCommand($text,$parameter) { $command_list = Array ( 'help' = displayHelp, 'quit' = quitUser, /* ... */ ); /*verify if it is a valid command*/ if (empty($command_list[$text])) { return INVALID_COMMAND; /*this maybe a constant*/ } $callback = $command_list[$text]; /*execute the command that is a method in a command executive component*/ $result = CommandExecutive::$callback($parameter); return $result; } --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Access $data content in afterSave callback
I have the following question: I'm saving in the controller with the method: $this-Model-save($this-data); But I don't set $this-Model-data explicitly. How can I access to the data array in the afterSave callback? Can I use $this-data if that array wasn't set explicitly with $this-Model- data = $this-data in the controller? I need the data in the afterSave because I have to handle a file upload associated to the model. --~--~-~--~~~---~--~~ 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: Dynamical display contation on default layout.ctp
Use an element. 1) In your UsersController you have a function that returns the count of live users: class UsersController extends AppModel { function getCountLiveUsers() { //perform the calculation return $n; } } 2) Create /view/elements/number_of_live_users.ctp whith this /*File number_of_live_users.ctp */ $n = $this-requestAction('/users/getCountLiveUsers'); echo $n; /*EOF*/ 3) and finally, in your layout default.ctp or whatever view, you can use your element. html head ... /head body There are ?php echo $this- element('number_of_live_users') ? /body /html --~--~-~--~~~---~--~~ 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: MySQL Having Clausule
If you have query with complex conditions, I suggest you to use the query() method directly $users = $this-User-query('YOUR SQL QUERY') --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Error when including prototype and scriptaculous in layout template
I have a layout template that includes the prototype and scriptaculous scripts that are placed in webroot/js directory. The template looks like: !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd html xmlns=http://www.w3.org/1999/xhtml; head ?php echo $html-charset(); ? title ?php __('TITLE - '); ? ?php echo $title_for_layout ? /title ?php echo $html-meta('icon'); echo $html-css('gmg_frontend'); echo $javascript-link('swfobject'); //include prototype scriptaculous and lightbox scripts echo $javascript-link('prototype'); echo $javascript-link('scriptaculous'); echo $javascript-link('lightbox'); //personal scripts echo $html-css('lightbox'); echo $javascript-link('gmg'); echo $javascript-link('menubar'); ? /head ... (More stuff)... The page seems to load correctly, altough the Firefox's error console issues the following errors: Error: syntax error Source File: http://MY_DOMAIN/gmg/js/sound.js Línea: 1 Código fuente: !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd The code is a missing_controller page generate by cake in the scriptaculous loading, because the JS controller is missing. (This is the globlal object in scriptaculous that loads some scripts like sound, dragdrop and others) What is the solution for this trouble? --~--~-~--~~~---~--~~ 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: Documentation - Cakes bad side
The only complain that I found in the API documentation, is that there are not clear explanations about the parameters that a method expects (usually as an array) or class attributes are not explained too. Altought there is the source code; in many cases the source code itself is the best documentation. The cookbook I think is very terse and concise. It has some lacks of content, but you can realize that the cookbook has a beta state too, and obviously, it will be improved on time. --~--~-~--~~~---~--~~ 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: Add user_id from session to db when adding a product
Just assign the values to the data array $this-data['Product']['user_id'] = $user_id Or put user_id as a hidden field in the form. --~--~-~--~~~---~--~~ 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: Does calling model methods from elements break MVC pattern?
..the comment PERFORM BUSINESS LOGIC should immediately let you think that something is not 100% MVC ..you are performing LOGIC inside a MODEL, and not just model data handling. So, where I have to do the business logic? For example, I have a Product Object, and the product has some taxes that depends on the product itself (Its category, price, origin country, etc). Following the encapsulation principle of the object oriented programming, I think that the object to have to know how to calculate the product tax is the product itself. So I add a method Product::calculateTax(); into the class Product. Tax calculation is part of the business rules and tax value is inherent for each product, hence, I guess that the responsibility of tax calculation lays in the Product class. Why this could violate the MVC pattern? Or is the product controller who has to know how to calculate the product's tax? --~--~-~--~~~---~--~~ 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: Simple Question
When you post a form, the selected value of a select list is in the data array as any other form field. Hello all, how do I get the selected value from a select drop down box. Basically I want to redirect based on the returned value however I can not figure out how to get the selected value? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Does calling model methods from elements break MVC pattern?
It is a question about MVC pattern in cakephp. I have a calculated value that I want to display in many views, so I decided to create an element. The business logic has to be performed in the model, i.e: models/product.php class Product extends AppModel { //... all attributes and methods function performSomeProductCalculation () { //perform business logic return $result; } } There are two options to create an element that renders the result returned by the above method: - Option 1: Call the model method directly from element: views/elements/foo.ctp ?php App::import('Model','Product'); $p = New Product(); ? div class=result The result is ?php echo $p-performSomeProductCalculation() ? /div - Option 2: Create a controller method for rendering the result, and call that method in the element via requestAction controllers/products_controller.php class ProductsController extends AppController { //... all attributes and method function my_result() { return $this-Product-performSomeProductCalculation(); } } views/elements/foo.ctp ?php $r = $this-requestAction('/products/my_result'); ? div class=result The result is ?php echo $r; ? /div Wich options is the correct one in order to respect 100% the MVC pattern? ? ? --~--~-~--~~~---~--~~ 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: Database design for local information specific site
I suggest you to: - Create a single table Cities (id,name). For example IdName 1 New York 2 Madrid 3 Roma - Create a single table called Properties (id,city_id, property, value) and place in that table All the properties for each city. For instance: Id City_Id Property Value 11 greeting HELLO 22 greeting HOLA 33 greeting CIAO 41 contact[EMAIL PROTECTED] 52 contact[EMAIL PROTECTED] 63contact[EMAIL PROTECTED] - Add a session value with city_Id, once the user has enter in the site, and use that id to retreive all the properties from the current city. I think that with the above schema you don't need to do too much joins for retreive your localized properties, just need to know the city_id --~--~-~--~~~---~--~~ 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: Does calling model methods from elements break MVC pattern?
Ok, that means that I would consider to pass parameters to my elements (parameters calculated inside the controller) to avoid a requestAction call, doesn't it? --~--~-~--~~~---~--~~ 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: javascipt onclick in $html-image
Double quotes should work too: 'on_click' = open_win($id); On 30 sep, 10:37, bartez [EMAIL PROTECTED] wrote: Panic over answer is: 'onclick'='open_win('. $id .')' cheers a --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to allow all non-administrative route with Auth
I'm using Auth component to manage an admin panel. I use admin route for all function in admin panel. In order to allow all other actions without login, I add them in beforeFilter method. For instance: function beforeFilter() { parent::beforeFilter(); //Controller general initialization $this-Auth-allow('index'); $this-Auth-allow('price_list'); ... } But this is error prone when the controller has a lot of actions. Is there a single instruction with Auth component for allowing all actions with non-administrative route? --~--~-~--~~~---~--~~ 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 update a model with save method?
Thanks for all your answers. I found my error: I've overridden the exists method in my model for other uses. So, it seems that save method invokes the exists method to decide wheter call an INSERT or an UPDATE. I thought erroneuosly that save method only checked that the id attribute was set. On 23 sep, 11:08, teknoid [EMAIL PROTECTED] wrote: Is your primary key field really named 'id' ... not 'ID' or something along those lines? That being said $this-Manufacturer-id = $id should work regardless of the primary key column name, since the $id property here simply refers to the key column and has nothing to do with the actual name. The actual name is stored in the $primaryKey property of the model. On Sep 23, 1:28 am, ORCC [EMAIL PROTECTED] wrote: Thank you for answer. On 23 sep, 00:42, teknoid [EMAIL PROTECTED] wrote: $this-Manufacturer-id = $id; you can also save() the data without doing a set() first, i.e. $this- Manufacturer-save($this-data); This doesn't work either in my model-controller given in the previous posts. I can't figure where is the mistake, but I've have tested the following: - Set $this-Manufacturer-id = $id - Set $this-data['Manufacturer']['id'] = $id and invoke $this- Manufacturer-save($this-data) With both alternatives, the mysql error of duplicate key appears and the query performed is an INSERT one. Regards. --~--~-~--~~~---~--~~ 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: Wouldn't it be great if cake adds a straight PHP equivalent on it's manual pages e.g redirection
You can issue a header or any php function into the View, but it is not correct from the point of view of the MVC pattern, because it seems that you are putting application logic into the view. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to update a model with save method?
In the blog tutorial, they use the save method both to save or update an existing record. I tried to take that idea for my application and had some trouble: My model is the following, with all default table names (i.e id is the primary key) class Manufacturer extends AppModel { var $name = Manufacturer; var $validate = Array (/*validation stuff*/); //some other methods } And the controller is as follows class ManufacturersController extends AppController { var $name = Manufacturers; var $helpers = array('Html', 'Form','Javascript'); var $components = array('Session'); function edit($id = 0) { if ($id) { $this-Manufacturer-set($this-data); $this-Manufacturer-set('id',$id); /*try to update the record*/ $this-Manufacturer-save(); } } } In the edit function I set the id attribute for the Manufacturer model as stated in the documentation; with this, the save method should update rather than create a new records. Altough, the application issues the following error message (here key 1 is the primary key, and 12 is a value of an existing id in the database table): Warning (512): SQL Error: 1062: Duplicate entry '12' for key 1 $sql= INSERT INTO `manufacturers` (`titulo`,`descripcion_es`,`descripcion_uk`,`descripcion_it`,`id`) VALUES ('F222','xxx,'xxx','',12) Wich attribute I have to set in order of the save method generate a UPDATE query instead of an INSERT one? Thanks in advice. --~--~-~--~~~---~--~~ 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 update a model with save method?
Thank you for answer. On 23 sep, 00:42, teknoid [EMAIL PROTECTED] wrote: $this-Manufacturer-id = $id; you can also save() the data without doing a set() first, i.e. $this- Manufacturer-save($this-data); This doesn't work either in my model-controller given in the previous posts. I can't figure where is the mistake, but I've have tested the following: - Set $this-Manufacturer-id = $id - Set $this-data['Manufacturer']['id'] = $id and invoke $this- Manufacturer-save($this-data) With both alternatives, the mysql error of duplicate key appears and the query performed is an INSERT one. Regards. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to count associated records in a model?
I have a Manufacturer model having many Products. In order to return the number of Products of a Manufacturer I wrote the following method in Manufacturer: function countProducts() { App::import('Model','Product'); $condition = Array('manufacturer_id' = $this-id) return $this-Product-find('count',Array('conditions' = $condition)); } I would like to know if there is some way of getting the count of associated records without importing the associated model, but performing a recursive count. --~--~-~--~~~---~--~~ 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: using Configure::read in a model definition file
It is a php syntax issue. When you declare a class attribute, its value must be constant, i.e class Foo { var $foo = Array('equalTo' = 'xx', 'name' = yy); //correct, since all array's elements are constant var $bar = Array('equalTo' = Conf::read('Secret')); //Error, since the value its not constant } The solution is to set the attribute in the class constructor class Foo { var $bar = Array(); //declare the attribute function __construct() { $this-bar['equalTo'] = Conf::read('Secret'); } } --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Generate List with SQL calculated Fields
Usually I create lists for using with $form-select(), vía find('list') method. For instance, in the controller method $l = $this-ProductCategory-find('list'); Another way to create the list is by using a plain query: $l = $this-ProductCategory-query('SELECT `id`, `name` FROM product_categories ORDER by `name` ASC'); The problem is that select is not correctly rendered when I need a SQL calculated field. My trouble is the following: The table product_categories has a field called sex with type VARCHAR(1) and whose values are 'M' or 'F'. I need that in my select, the list items apear of the following manner: Pants(WOMEN) Shirts (WOMEN) Pants (MEN) Shirts (MEN) ... I try to create the list with the following query: $query = SELECT `id`, CONCAT(`name`,IF(`sex`= 'M','(MEN)','(WOMEN)')) AS `description` from `product_categories` ORDER BY `name` ASC, `sex` ASC;; $l = ProductCategory-query($query); But the calculated field appears wrapped into an array and the select list wouldn't create correctly. How to make a raw query in order to add SQL calculated fields? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---