cakephp-2.0

How to hide the physical path of the images

这一生的挚爱 提交于 2019-12-31 04:10:52
问题 In my application i display the image of user by giving the physical path of the directories like http://www.example.com/user_images/abcdefghijk.jpg But i dont want to expose this physical path to the external users to access the direct files. I want to implement the image retrieval as per the gravtar type image display. How we can do that? 回答1: In PHP you can use GD library to read the image. So the only way you need to create a image.php file & use the following code, <?php $imagepath="your

How can i test an Add function on CakePHP2.0

℡╲_俬逩灬. 提交于 2019-12-31 02:33:05
问题 I have been told that we have to test also the functions created by Cake like add/delete... If i have a function like this one, how can i test it if it doesn't have any return, redirect or even a view? ( i use ajax to execute it) public function add() { if ($this->request->is('post')) { $this->Comment->create(); if ($this->Comment->save($this->request->data)) { $this->Session->setFlash(__('The comment has been saved')); } else { $this->Session->setFlash(__('The comment could not be saved.

CakePHP 2.0 Select form Multiple selected

房东的猫 提交于 2019-12-31 00:45:22
问题 I have have this dropdown menu where you can select multiple values. Now let's say I want to edit my info and make a dropdown menu with multiple selected values. Trying to figure out how it goes, but no results. Let's say I have: $selected = array(3, 4); $options = array(1,2,3,4); echo $this->Form->select('Attendees', $options,array('multiple' => true, 'selected' => $selected)); I've used this code, but nothing is selected. 回答1: Ok found a way, appearantly it needs to be like this: $selected

CakePHP TwigView Plugin Missing View Error

烂漫一生 提交于 2019-12-30 13:39:22
问题 I am using CakePHP 2.4.2 and this plugin by predominant. I want to use TwigView with CakePHP and found that the plugin above is compatible with CakePHP 2.0. Followed all the installation steps, however, getting the Missing View error while executing the script. My AppController.php <?php App::uses('Controller', 'Controller'); class AppController extends Controller { public $viewClass = 'TwigView.Twig'; } The view's extention is .tpl , however, even after adding the Plugin it is still looking

Multiple form with same model name on single page cakephp

时间秒杀一切 提交于 2019-12-29 07:48:08
问题 I have two form on a single page: login form and register form. When I submit the register form, it validates both: form fields that are in login and registeration. How can I handle it if both form have the same model (user model) Register form <?php echo $this->Form->create('User', array('url' => array('controller' => 'users', 'action' => 'add'))); ?> <?php echo $this->Form->input('username', array('label' => false, 'div' => false, 'class' => 'reg_input'));?> <?php echo $this->Form->input(

Multiple form with same model name on single page cakephp

别来无恙 提交于 2019-12-29 07:48:05
问题 I have two form on a single page: login form and register form. When I submit the register form, it validates both: form fields that are in login and registeration. How can I handle it if both form have the same model (user model) Register form <?php echo $this->Form->create('User', array('url' => array('controller' => 'users', 'action' => 'add'))); ?> <?php echo $this->Form->input('username', array('label' => false, 'div' => false, 'class' => 'reg_input'));?> <?php echo $this->Form->input(

How to select subdocuments with MongoDB

青春壹個敷衍的年華 提交于 2019-12-29 04:48:06
问题 I have a collection with a subdocument tags like : Collection News : title (string) tags: [tag1, tag2...] I want to select all the tags who start with a pattern, but returning only the matching tags. I already use a regex but it returns all the news containing the matching tag, here is the query : db.news.find( {"tags":/^proga/i}, ["tags"] ).sort( {"tags":1} ). limit( 0 ).skip( 0 ) My question is : How can I retrieve all the tags (only) who match the pattern ? (The final goal is to make an

Cakephp 2.0 mysql query

这一生的挚爱 提交于 2019-12-25 12:57:06
问题 I'm new in Cakephp 2.0, but I want to make a view of two tables. I have the following tables: hpsas with records: ciname, location, status ldaps with records: ciname, status In my Controller I have the following syntax: $this->Hpsa->query("SELECT `hpsas`.`ciname`, `hpsas`.`status`, `ldaps`.`ciname`, `ldaps`.`status` FROM `cmdb`.`hpsas`, `cmdb`.`ldaps` WHERE `hpsas`.`ciname` = `ldaps`.`ciname`;"); I got the following results as expected: 'hpsas' => array( (int) 0 => array( 'hpsas' => array(

CakePHP 2.X: compound (concatenate several db columns) virtualfield as displayfield

喜你入骨 提交于 2019-12-25 07:53:16
问题 I already answered my own question but I wouldn't mind accepting any other answer that is really better than my approach (do mention how it is better). Please contribute. I had a situation where in my User Model , I had first_name, middle_name, last_name as 3 separate fields and only first_name being validated against empty/NULL , i.e., the other 2 can be empty/NULL/whitespace(didn't want to annoy the users with unreasonable validations, I personally know people who don't have/use their last

Use a Custom CakeResponse Class in CakePHP 2.1+

有些话、适合烂在心里 提交于 2019-12-25 04:08:19
问题 I am trying to use a Custom CakeResponse class however none of my current work nor current searches have led me to a solution towards actually using one. So let's call my custom CakeResponse class AppResponse : AppResponse is in Lib/Network <?php App::uses('CakeResponse', 'Network'); class AppResponse extends CakeResponse { } Based on this blog post http://mark-story.com/posts/view/cakeresponse-in-cakephp-2-0 it appears that one should be able to use this code to override the CakeResponse and