[Solved] Using Cake PHP Sort to sort Array Keys

You cannot sort an simple array by his key in cake. You can only sort like this: (or you can use {n}.{n} ) $array = (e,h,u,w,r); $result = Set::sort($array, ‘{n}’, ‘asc’); pr($result); For key sorting use ksort php function, or create in cake a ksort function with same properties and use it ksort( $array ); … Read more

[Solved] CakePHP 3.0 and new project [duplicate]

I’ve been working a lot with Cakephp 2, and i’m currently learning Cakephp 3. What I can say so far is: cakephp 3 introduces a lot a interesting new functionnalities (i won’t detail here, you can find many resources on internet for that). cakephp 3 is really a major release: many things have changed. Even … Read more

[Solved] How to write REST web service in cakephp using Post ..? [closed]

you can sent json through Http post in cakephp <?php $data = array(‘Users’=>array(‘id’=>’1′,’username’=>’xyz’,’password’=>’pass’,’email’=>’[email protected]’,’age’=>’28’,’gender’=>’male’)); $url = “http://localhost/appname/Controllername/functionname”; $content = json_encode($data); $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, ‘data=”.$content); $json_response = curl_exec($curl); echo $json_response;?> 2 solved How to write REST web service in cakephp using Post ..? [closed]

[Solved] how to create form with a drop-down list that change the other option depend on selection [duplicate]

I’m trying to find a specific solution for cakePHP but I got bullied instead of getting a good answer. After a lot of searching I’ve found this great blog post which exactly solve my problem. http://blog.jandorsman.com/2011/01/using-ajax-and-cakephp-to-dynamically-populate-select-form-fields/ If you’re using a newer version of CakePHP. you need to use different functions JS helper instead $this->Js->get(‘#BookId’)->event( ‘change’, … Read more

[Solved] Output last 5 rows in database [CakePHP] [closed]

You have to use find() Other way is to use query() $alltext = $this->Text->find(‘all’, array(‘limit’ => 5,’order’=>array(‘id DESC’))); <?php foreach ($alltextext as $text): ?> // format as necessary <td><?php echo $text[‘Text’][‘id’]; ?></td> // add others here <?php endforeach; ?> 3 solved Output last 5 rows in database [CakePHP] [closed]

[Solved] Protect folders in CakePHP2

CakePHP does this automatically. If you try to access www.yoursite.com/css, it will try to access the “CssController”, which doesn’t exists, so it will throw an error – it won’t show your folder contents. The same goes for the rest. 2 solved Protect folders in CakePHP2

[Solved] CakePHP $this->redirect($this->Auth->redirectUrl()); Duplicates BaseURL in Redirect

The issue is with line 680 of lib/Cake/Controller/Component/AuthComponent.php return Router::url($redir); Changing it to the following (which was an update in 2.3.9) fixes it: return Router::url($redir + array(‘base’ => false)); As does changing it to this (which is an update in 2.4): return Router::normalize($redir, false); See commit message here: https://github.com/cakephp/cakephp/commit/8133f72 Obviously editing the CakePHP core files … Read more

[Solved] Unknown php syntax [closed]

It translates to this: <td> <?php if($contact[‘Contact’][‘sex’] == ‘m’): ?> Male <?php else: ?> Female <?php endif ?> </td> But there is really nothing wrong with the line that is actually in your file. 7 solved Unknown php syntax [closed]

[Solved] Array to string Error while uploading an Image

You study cakephp manual properly HOW form type can be File ?????? 🙂 Use this <?php echo $this->Form->create(‘User’,array(‘enctype’=>’multipart/form-data’)); echo $this->Form->input(‘profile_pic’, array(‘type’=>’file’)); echo $this->Form->end(‘submit’); ?> 5 solved Array to string Error while uploading an Image