cakephp-2.1

CakePHP 2.1 Avg function for query

拜拜、爱过 提交于 2019-12-11 10:28:11
问题 I am using cakephp 2.1 and I wanna get average of movie ratings for perticular movie. Where 'Movie' is a model and it contains 'Language' and 'CriticReview' as models. The array structure is as follows. array( (int) 0 => array( 'Movie' => array( 'id' => '4', 'name' => 'Maattrraan', 'cover_image' => '/movies/4d0d1c41d956a2cb2ab93603d1fdf70c.jpg', 'release' => '2012-10-12', 'runtime' => '', 'budget' => '65 crore', 'box_office' => '', 'language_id' => '2', 'industry_id' => '3' ), 'Language' =>

Define global variable for Models and Controllers at CakePHP 2.2

坚强是说给别人听的谎言 提交于 2019-12-11 09:43:37
问题 Currently i am using something like this: //at bootstrap.php file Configure::write('from', 'mymail@mydomain.com') //at controllers or models files $var = Configure::read('from') The thing is, i would like to manage that variable through the database to be able to modify it in a simpler way. I was thinking about doing it with AppModel but then it would only be accessible for Models and not controllers. What should I do in this case? Thanks. 回答1: You can create a separate model / plugin which

How to add 2 callback to the Jshelper in Cakephp 2.x

纵饮孤独 提交于 2019-12-11 06:54:37
问题 I want to add 2 callback to Js->submit, My first return true or false. Continuing with that I want to put action. I mean If it is true then it continue to action else halt at that moment. What I have tried yet but its not taking 2 callback. Plaese help. echo $this->Js->submit("Apply", array( 'id' => 'submitForm', 'div' => false, 'class' => 'general_button', 'style' => array('float:none;', 'margin: 10px;'), 'url' => array( 'controller' => 'categories', 'action' => 'index', 'field' => $search

how to get books from one category excluding other category (through cross table)

江枫思渺然 提交于 2019-12-11 06:23:07
问题 For now I am using following code to get books from certain category: $options['conditions']['Category.id'] = $category_id; $options['joins'] = array( array( 'table' => 'books_categories', 'alias' => 'BookCategory', 'type' => 'inner', 'conditions' => array('Book.id = BookCategory.id_book'), ), array( 'table' => 'categories', 'alias' => 'Category', 'type' => 'inner', 'conditions' => array('BookCategory.kat = Category.id'), ), ); $this->Book->find('all',$options); This just finds all books from

Cakephp not loading css and js files

耗尽温柔 提交于 2019-12-11 05:42:51
问题 I seriously can't understand what is going on here. I just uploaded my web app from localhost to new domain-name on Windows IIS Server. When I try to access the web app, CSS files and images are not loaded and I get the following error: " CssController could not be found." I don't understand why it is doing this. Although I've written code like this in my default.ctp: echo $this->html->css('generic'); CSS files are placed in: app\webroot\css I have searched on Google and have tried everything

Using CakePHP's MediaView with MP4 videos on an iPad

主宰稳场 提交于 2019-12-11 04:18:46
问题 I am trying to display MP4 videos through Cake's MediaView class. I have it working fine in Chrome & Firefox, the problem is when trying to view the video on an iPad. All I get is the play icon with a line through the middle of it. The video is able to be viewed if you access the URL of the video directly, however I need this layer in between as videos are restricted on who is able to view them. I Google'd the problem and found that the iPad uses RangeRequests (Not fully sure on how all that

AND / OR conditions cakephp FIND for has many association

跟風遠走 提交于 2019-12-11 04:16:15
问题 I have a model Post that has many association with the model Comment. Post has a primary key post_id which is Comment s foreign key. Both of these have a visible column. I have a working query on Post.visible options, and I need to add the AND to find all Posts that have one of Post.visible values. For these posts I need all Comments that have a Comment.visible value = 1. My code: $conditions = array( "OR" => array( "Post.visible" => array( 1, 2, 3, 4 ), ), "AND" => array ( "Comment.visible"

CakePHP test behaviour with mapped method

天大地大妈咪最大 提交于 2019-12-11 03:22:28
问题 Whilst creating an OwnableBehavior I decided to use the $mapMethods property that is available. It is to map any method called isOwnedByXXX() to isOwnedBy() (The link for the documentation on this is here) Here is my OwnableBehavior code: class OwnableBehavior extends Model Behavior { public $mapMethods = array('/isOwnedBy(\w+)/' => 'isOwnedBy'); public function isOwnedBy(Model $model, $type, $id, Model $userModel, $userId) { // Method is currently empty } } Here is the TestCase code: class

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(

HABTM with self requires 2x the rows in join table?

旧时模样 提交于 2019-12-11 01:17:52
问题 I'm trying to build a CMS with Nodes as the main model. Each Node belongsTo a NodeType , and every Node can be related to any/every other Node . So - thought this called for HABTM: //Node model public $hasAndBelongsToMany = array( 'AssociatedNode' => array( 'className' => 'Node', 'foreignKey' => 'node_id', 'associationForeignKey' => 'associated_node_id', 'joinTable' => 'node_associations' ) ); The problem is, it seems like the only way it works is if I have TWO rows for each association.