cakephp

cakephp 2 redirect url with hashtag

一笑奈何 提交于 2020-01-14 12:32:53
问题 I'm trying to redirect an url containing a hashtag(#) with cakephp's redirect controller function. When I use this code it url encodes the hashtag $this->redirect(array('action' => 'index',$menuItem."#article_id_".$created_id)); output: http://something.com/link%23article_id_62 Is there a way that 回答1: You need to use the # key: $this->redirect([ // ... '#' => 'article_id_' . $created_id, ]); 来源: https://stackoverflow.com/questions/8615516/cakephp-2-redirect-url-with-hashtag

cakephp component $this->controller->modelClass

强颜欢笑 提交于 2020-01-14 10:37:08
问题 In Component I try to access Myprofile Model class SignMeupComponent extends Object public function register() { $this->__isLoggedIn(); if (!empty($this->controller->data)) { extract($this->settings); $model = $this->controller->modelClass; $this->controller->loadModel($model); $this->controller->{$model}->Myprofile->save($this->controller->data); $this->controller->data['Myprofile']['user_id'] = $this->controller->{$model}->id; $this->controller->{$model}->set($this->controller->data); if (

CakePHP: Fields not populating in Edit screen

情到浓时终转凉″ 提交于 2020-01-14 06:18:09
问题 Simple question from an absolute n00b. I'm trying to create an edit content screen based on the code given in the Blog Tutorial on the Cake site. Here's my edit function in the controller (it's named Contents): function edit( $id = null ) { $this->Content->id = $id; Debugger::dump( $this->Content->id ); if( empty( $this->data ) ) { $this->data = $this->Content->read(); Debugger::dump( $this->Content ); } else { if( $this->Content->save( $this->data ) ) { $this->Session->setFlash( 'Content has

Validation Messages Don't Show for Related Models in CakePHP

删除回忆录丶 提交于 2020-01-14 05:32:08
问题 I have a set of models that looks a bit like this Member Member_Addresses Agents AgentAddress I also have a form that tries to let you update all these different models in one form. I am bit new to this way of making forms in CakePHP, and I'm having trouble getting the validation error messages to show up in my form. My form looks something like this: <?php echo $this->Form->create('Member',array('type' => 'file'));?> <fieldset> <?php echo $this->Form->input('first_name'); echo $this->Form-

How to display results from a HABTM relationship in a view?

走远了吗. 提交于 2020-01-14 05:14:27
问题 I have a HABTM relationship between a books table and an authors table, joined with an authors_books table. However, I can't find a solution to display the fields firstname, lastname and fullname in my view. book-model: class Book extends AppModel { var $name = 'Book'; var $hasAndBelongsToMany = array( 'Author' => array( 'className' => 'Author', 'joinTable' => 'authors_books', 'foreignkey' => 'book_id', 'associatioanForeignKey' => 'author_id' ) ); author-model: class Author extends AppModel {

In cakePHP's find(), how do I include a constant?

孤街醉人 提交于 2020-01-14 04:43:11
问题 I'm looking to build a SQL query something like: "SELECT email.member_id, 1 FROM email ... " I'm using $this->Email->find('list', array( 'fields' => array('Email.member_id', '1'), ... CakePHP is generating: SELECT `Email`.`member_id`, `Email`.`1` FROM `emails` AS `Email` ... How do I specify that the 1 is a constant and not a database field? Why I want to do this I basically want to return an associative array with keys of member_id and values of 1. Would it be better to just get a straight

Cake PHP Checkboxes

强颜欢笑 提交于 2020-01-14 04:35:08
问题 I am new to CakePHP now I'm working on checkbox I used the following statement but it gives check box after the label and it prints the field also.My requirement is it does not print the field name and label should be displayed after the check box. please help me , Thanks in advance <?php echo $form->input('Model.name', array('multiple' => 'checkbox', 'options' => $options, 'selected' => $selected));?> 回答1: First, make sure your value is a boolean or tinyint . Otherwise, you will never get a

CakePHP needs to set session for particular folders

吃可爱长大的小学妹 提交于 2020-01-14 04:23:30
问题 I am using CakePHP framework . And below is my problem. www.mysite.com is the main site and I've created 5-6 different demos of my original site with different colors and fonts. So, if I am login in www.mysite.com/demo1 and then I open another demo www.mysite.com/demo2 , it shows I'm logged in already. Is there any way to set session folder wise? 回答1: In core.php, few lines before EOF, says: //Prefix each application on the same server with a different string, to avoid Memcache and APC

CakePHP 3: Exception handling / serialization in a RESTful API

不想你离开。 提交于 2020-01-14 02:59:22
问题 I'm building a JSON RESTful API with CakePHP3, but I'm not sure what is the best approach to handle errors and give the client information about the error. My approach so far is to throw a HttpException if (for example) saving an entity fails due to validation errors. In my controller I have the following: if (!$this->Categories->save($categoryEntity)) { throw new InternalErrorException('Saving failed'); } $this->set('status', 'Everything fine!'); $this->set('_serialize', true); If the saving

CakePHP 3: Exception handling / serialization in a RESTful API

半腔热情 提交于 2020-01-14 02:59:06
问题 I'm building a JSON RESTful API with CakePHP3, but I'm not sure what is the best approach to handle errors and give the client information about the error. My approach so far is to throw a HttpException if (for example) saving an entity fails due to validation errors. In my controller I have the following: if (!$this->Categories->save($categoryEntity)) { throw new InternalErrorException('Saving failed'); } $this->set('status', 'Everything fine!'); $this->set('_serialize', true); If the saving