Re: Looking for Help with Cakephp basics .. aka looking for a mentor
awesome answer reuben +69 -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
CakePHP Newbie Questions
Hi, I have recently started to learn CakePHP after just being used to coding from scratch. I have installed a couple of plugins but the issue I have is linking them together, for example if I have a login script then how on earth do I just show the login page for example? Does every Controller need to have a mysql assigned to it? I have been through the blog tutorial but so far it just feels really restrictive compared to just coding from scratch but what really appeals is the plugins / helpers but I am just struggling with basic things like echoing the username they are logged in with when logged in etc. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
Re: Cakephp without Save() function?
When doing an insert, you need to call Model->create() first. And if you are calculating a value, assign is back to the request, so it can be saved on the Model. $data1 = (string) $this->request->data['Calculate']['var1']; $data2 = (string) $this->request->data['Calculate']['var2']; $result = $data1 + $data2; $this->request->data['Calculate']['result'] = $result; $this->request->data['Calculate']['otherField'] = 2; $this->Calculate->create(); if ($this->Calculate->save($this->request->data)){ echo 'Successful add'; } On Thursday, 12 December 2013 16:18:56 UTC+10, YOONG SINJIE wrote: > > May I know , got other way to store the SQL statement, except the Save() > function ? I want to do some simple calculation, i want to store the result > at database. Anyone having any idea about it ? > > public function add() { if ($this->request->is('post')) { > > /// complete calculation > > $data1 = (string) $this->request->data['Calculate']['var1']; > $data2 = (string) $this->request->data['Calculate']['var2']; > > echo $data1; > echo ''; > echo $data2; > > $result = $data1 + $data2; > > echo ''; > echo $result; > > SQL Statement > mysql_query("INSERT INTO calculate > VALUES('$data1','$data2','$result','2')") or die(mysql_error()); >// if($this->Calculate->save($this->request->data)){ > >// echo'succuful add'; > > >// } > } > > } > > > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
Re: Yet Another Validation Question
Have you confirmed that the validation function is actually getting called, via CakeLog::debug() or error_log(print_r($data, true)); If your validation function only returns false, and it never gets called, mostly likely, validation is not getting called at all. If the data is data['Community']['start']['year'], then you're probably using the FormHelper date functions, which tend to split a date into it's components, and return the results as an array. However, you may wish to confirm with error_log(print_r($data, true)); or similar, the structure of the field at validation time. You may want to check for $value = $this-> data[$this->alias][$field]['year']; when determining the value of the year. Regards Reuben Helms On Wednesday, 18 December 2013 16:22:45 UTC+10, advantage+ wrote: > > I cannot validate my year select. > > > > When posted it appears as : > > data[Comunity][start][year]... > > 2009 > > > > Validation rule: > > 'start' => array( > >'required' => true, > >'allowEmpty' => false, > >'rule' => array('checkYearValues', 'start'), > >'message' => 'Please enter a year between 1950 and 2013 when you > started.', > >'last' => true), > > > > checkYearVales: > >/ > >* FORM VALIDATION SELECT YEAR VALUES > >* *** > >* @access public > >* @return bool > >* > >* > >* > >/ > >public function checkYearValues($data, $field){ > > > > $value = $this->data[$this->alias][$field]; > > > > $baseYear = date('Y') - 2013 + 10; > > $years = array_combine(range( date('Y'), date('Y') - > $baseYear), range( date('Y'), date('Y') - $baseYear)); > > > > //return in_array($value, $years); > > return false > > > >} > > > > But it always passes validation > > > > Any ideas why start[year] gets added to the input? > > > > Thanks all > > > > *Dave Maharaj* > > *Freelance Designer | Developer* > [image: Description: header_logo] > www.movepixels.com | d...@movepixels.com | 709.800.0852 > > > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
Re: Looking for Help with Cakephp basics .. aka looking for a mentor
There's this list, the irc channel and sometimes, stackoverflow, but your mileage may vary on how much effort you put into solving the problem yourself vs how much help you may receive. For example, you may experience a bit of radio silence when asking questions that are covered in the documentation at http://book.cakephp.org/2.0/en/ For example, uploading a file is partially covered by http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-create, by specifying that your form is going to be for a file, and then adding an input field that has the type of file. When the form is submitted, the $this->request->data will have a file descriptor, as described here: http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::file Saving data to multiple models is covered by Model::saveAssociated : http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveassociated-array-data-null-array-options-array. Though you may need to add some special processing in the controller to read the file upload descriptor into a database field on the model, in the appropriate format (some databases require special encoding before storing binary files). With regards to the year issue, take note of the sample code at http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::year. Notice the input name is data[User][purchased][year]. This means that the FormHelper displays the year component of a whole date field, so when you inspect $this->request->data('User.purchased'), it is likely to be an array. Personally, I'm not much of a fan of the way the FormHelper does date processing, so you may be better off just doing a FormHelper::select, and specify the year entries you are interested in. I thought the document is pretty nice for showing how to implement plugins ( http://book.cakephp.org/2.0/en/plugins.html), helpers ( http://book.cakephp.org/2.0/en/views/helpers.html#creating-helpers) and components ( http://book.cakephp.org/2.0/en/controllers/components.html#creating-a-component). CakePHP also has plenty of implemented helpers and components in it's core to look at for initial guidelines and best practice. For plugins, you may have to dig a little deeper, but they're really just mini apps wrapped up for use with other applications. You just need to stick to the naming convention. Personally, I'm looking forward to CakePHP 3.0 for plugins, when namespaces will be implemented properly, and we won't have to be as concerned with namespace / class name clashes. The last one sounds like an actual application problem, rather an issue with CakePHP. With that one line description, there are a lot of parts to deal with. Start with the model. Maybe add a Tree Behaviour to help represent the tree, and find neighbours and children. Set up a controller, and find the entries, using the model. Perform a set in the controller, to set the data for use in a view. Write the view to processing and display the data. Perhaps you have a Javascript component in mind that will display the data in the tree. Perhaps it takes json for the structure. Perhaps it can load via Ajax, so then you would read up on the JsonView class, and the $this->set('_serialize', ...) method of serializing data in a view variable, plus looking at the RequestHandlerComponent for accepting ajax and json requests. The other hidden gem with CakePHP is the test suite. The test suite tests all the core functionality in CakePHP, so you can see how the FormHelper::select should be used to populate a dropdown list. I'd also recommend following the Blog Tutorial. Then expand on it a bit to add an EntryType to the Post model, and see what scaffolding adds to the add and edit controller actions and views. This will show you how to populate a drop down (hint: in the controller: $entityTypes = $this->EntityType->find('list'); $this->set(compact('entityTypes')); and in the form, $this->Form->input('entityType');) It's been a very long time since I looked at the Zend Framework, so I'd recommend you take a look, and see if you can get the job done there, and see if there the same level of help there, as you expect to find here. Last time I looked at it, the class names were more noise than useful, and there was a lot of cruft that made the framework seem bloated. Maybe it has slimmed down since then, and the learning curve for doing things the Zend way isn't as steep as it used to be. Then once you've solve the problem in Zend, come back and take another look at CakePHP, and solve the same problem, purely as a self education exercise. I'm thinking you might be pleasantly surprised. I subscribe to the posts on this list, and get a daily digest. Depending on the question, and how much effort has been put in, I'll help out when I can, as a civic duty, to give a little back to the framework that has made development in PHP so much easier ov
Re: GeoIp Help
That's not how to do an 'and' in CakePHP conditions. Conditions in CakePHP will use 'and' by default, for items in the same array, unless explicitly keyed by an 'or'. This will get you closer to your goal, though you might want to check the greater than / less than operations for equality, and IPs that are at the beginning or end of the range. 'conditions' => array( 'startIpNum <=' => $address, 'endIpNum >=' => $address), 'limit' => 1, Regards Reuben Helms On Wednesday, 18 December 2013 05:22:22 UTC+10, advantage+ wrote: > > Was hoping someone can point out where I am going wrong here. > > > > Just testing so code is rather sloppy. > > > > Related to GeoIP City / Country Location. (data is in my database, not a > web call) > > > > $address = $this->my_ip2long($_SERVER['REMOTE_ADDR']); > > > > Calls this: > > private function my_ip2long($ip){ > > > > $nums = explode('.', $ip); > > $ret = 0; > > for ($i=0; $i<4; $i++){ > > $ret += intval($nums[$i]) * pow(256, 3-$i); > > } > > return $ret; > > } > > > > So $address = (int) 2393010516 > > > > So far so good. > > > > $current_address = ClassRegistry::init('IpCountry')->__findUserCountry(); > > Produces: > > array( > > 'IpCountry' => array( > > 'id' => '38959', > > 'ip_from' => '2391343104', > > 'ip_to' => '2394947583', > > 'country2' => 'CA', > > 'country3' => 'CAN', > > 'country' => 'CANADA' > > > > Which is correct I am in Canada. > > > > So I put that function inside __FindUserCountry(); all good so far. > > > > Then > > $location = ClassRegistry::init('GeoCityBlock')->find('first', array( > > 'conditions' => array( > > 'and' => > array( > > > > array( > > > > 'startIpNum <' => $address, > > > > 'endIpNum >' => $address))), > > 'limit' => > 1, > > 'contain' => > array( > > > 'GeoCityLocation'))); > > > > And presto time travel :0 I am now in Seoul Korea. > > > > array( > > 'GeoCityBlock' => array( > > 'startIpNum' => '23068672', > > 'endIpNum' => '24117247', > > 'locId' => '22883' > > ), > > 'GeoCityLocation' => array( > > (int) 0 => array( > > 'locId' => > '22883', > > 'country' => > 'KR', > > 'region' => '11', > > 'city' => > 'Seoul', > > 'postalCode' => > '', > > 'latitude' => > '37.5985', > > 'longitude' => > '126.9783', > > 'metroCode' => > '', > > 'areaCode' => '' > > ) > > ) > > > > > > Anyone have any assistance they could provide would be great. > > > > Thanks, > > > > Dave > > > > > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
Re: Display Errors
Look first to the underlying HTML. Does that show each field in a consistent order. i,e label, field, error message. If so, and most likely if the fields are being displayed in the default fashion, then there might be some CSS that is rearranging the error message to be before the field for the Academic merit field. However, if the underlying HTML has label, error message, field for the Academic merit field, then you need to look for the code that is outputting that field. Either it's like that because the application/view makes it like that, or perhaps that's how CakePHP places error messages for select fields. I'm at home, and don't have access to the code base to check, but that is where I would look first. Regards Reuben Helms On Wednesday, 18 December 2013 08:23:48 UTC+10, advantage+ wrote: > > I have attached an image for the first time so maybe it will help. > > > > I just noticed the select errors are above the select yet the rest of the > errors appear below where they should be. Well I really do not care above > or below…., but they must line up for the sake of appearance. > > This just looks like crap all jagged. > > > > Any ideas how / why / fix this? > > > > Thanks all, > > Dave > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.