cakephp-2.0

CakePhp 2.0 sort on associated model using Pagination / Paginator

ぐ巨炮叔叔 提交于 2019-12-11 03:33:39
问题 I realize this question is literally all over StackOverflow, but none of the answers seem to work for me. My problem is dirt-simple. I just want to list Companies ordered by City name: class Company extends AppModel public $recursive = 2; public $belongsTo = array( 'City' => array( 'className' => 'City', 'foreignKey' => 'city_id' ) ); class City extends AppModel { public $useTable = 'cities'; public $belongsTo = 'Country'; public $hasMany = array( 'Company' => array( 'className' => 'Company',

cakephp 2.0 smtp email

青春壹個敷衍的年華 提交于 2019-12-11 03:32:48
问题 I am trying to send a email message using CakePhp 2.0. in my controller i use this code (i know it's fine, i took it from the cookbook) : App::uses('CakeEmail', 'Network/Email'); $email = new CakeEmail("myConfig"); $email->from(array('from@example.com' => 'From Example')); $email->to($to); $email->subject($msgtitle); $ok = $email->send($content); and in app/config/email.php i have this config : <?php class EmailConfig { public $myConfig = array( 'host' => 'mail.myServer.com', 'port' => 587,

CakePHP 2.0.4 - findBy magic methods with conditions

女生的网名这么多〃 提交于 2019-12-11 03:25:41
问题 I am trying to build a small cms to test CakePHP 2.x In my PagesController (for displaying single sites), I use this code: $page = $this->Page->findByNavtitle($name, array( 'conditions' => array( 'Page.visible' => '1', ), ) ); The result should only set when the record is marked as visible. But this codeblock throws an error. The API describes, that just one parameter is allowed in these findBy magic methods. How can I get the result with conditions? 回答1: You cannot add conditions to findBy

ACL - Where to configure custom userModel for authorize?

回眸只為那壹抹淺笑 提交于 2019-12-11 03:25:12
问题 I'm having Player instead of default User model for my Auth. I recently configured ACL for my app and while trying to do testing by return false in my isAuthorized($player) function, the following error occured: AclNode::node() - Couldn't find Aro node identified by Array ( [Aro0.model] => User [Aro0.foreign_key] => 1 ) Isn't the Aro0.model suppose to be Player ? I can't find where to change for Auth->authorize . Auth-authenticate works fine as I manage to login since there is a userModel

Htaccess and CakePHP 2 on windows IIS7

邮差的信 提交于 2019-12-11 03:07:39
问题 I was having problems trying to configure the mod rewrite over windows and II7: CakePHP 2.2.2 not working on Windows IIS7 but finally i could import the htaccess in order to create the web.config file for IIS7. The thing is: Now that file has been created in cakephp folder and i can access to the main page BUT it has not been created inside app/ or app/webroot in which you can find 2 more .htaccess files. Now, i can not access any other view than the main site, it shows a 404 page not found

CakePHP: hasMany association not recognized

半腔热情 提交于 2019-12-11 02:54:59
问题 Attempts belong to Users (Users have many Attempts). In User.php (model) public $hasMany = array ( 'Attempt' => array( 'className' => 'Attempt', 'order' => 'modified DESC' ), ); In Attempt.php (model) public $belongsTo = array ( 'Test' => array ('className' => 'Test', 'foreignKey'=>'test_id', 'order' => 'Test.created DESC'), 'User' => array ('className' => 'User', 'order' => 'User.created DESC') ); In a controller, I construct this query... $joins = array( array( 'table'=>'attempts', 'alias'=

CakeEmail how to determine failure before stack trace?

自闭症网瘾萝莉.ら 提交于 2019-12-11 02:37:39
问题 I am trying to catch when an email fails so that I can save the required data in my database and I can attempt to send at a later date. I thought the following should work as it does when using save() if ( $email->send() ) { //..success - works.. } else { //..fail - never gets here, stack trace } 回答1: obviously you are not in debug mode there. if you were, you would see that this actually throws an exception. and you are catching sth there, just not the exception thrown :) try this: try {

when opened with winrar, Zip file obtained through Cakephp MediaViews reports Unexpected end of archive

早过忘川 提交于 2019-12-11 02:27:37
问题 What i am trying to achieve: Force download a zip file that contains user opted pdf files. What i did in controller to achieve this: Generate pdf reports in folder APP.WEBROOT_DIR.DS."package_files" (i used MPDF library) *it generates correct readable pdf. I call here $this->render(); With Zip feature of php, Generate package.zip (which consists pdf files from above specified folder) *it generates correct zip file, when downloaded from server it opens as valid zip file in windows. Set the

How to import a class in a controller of CakePHP 2.0?

爷,独闯天下 提交于 2019-12-11 02:24:17
问题 I am using CakePHP. I created an external class which is not a model nor a controller. The structure of the class looks like this class UploadImage{ function sayHello(){ return "hahaha"; } } I saved the class in the App->Lib directory and named it as UploadImage.php I wanted to call the method sayHello() in my controller which is: class ContentsController extends AppController { public $helpers = array('Html', 'Form'); public function index() { $test = App::uses('UploadImage','Lib'); debug(

CakePHP - How to make routes with custom parameters?

不想你离开。 提交于 2019-12-11 01:18:59
问题 My Cake URL is like this: $token = '9KJHF8k104ZX43'; $url = array( 'controller' => 'users', 'action' => 'password_reset', 'prefix' => 'admin', 'admin' => true, $token ) I would like this to route to a prettier URL like: /admin/password-reset/9KJHF8k104ZX43 However, I would like the token at the end to be optional, so that in the event that someone doesn't provide a token it is still routed to: /admin/password-reset So that I can catch this case and redirect to another page or display a