FAQ Database Discussion Community


mysql_real_escape_string is not working in cakephp

cakephp,cakephp-2.0,cakephp-1.3,cakephp-2.3,mysql-real-escape-string
mysql_real_escape_string is not working in cakephp . I am getting error like below . mysql_real_escape_string(): Access denied for user 'root'@'localhost' (using password: NO) [APP/Controller/add.php, line 123] database connection: <?php class DATABASE_CONFIG { public $default = array( 'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => 'localhost', 'login' => 'xyz', 'password' =>...

Issues Trying to Run CakePHP2 Tests on Console

shell,testing,console,cakephp-2.0
In my development environment, I load CakePHP via Composer to the Vendor directory. The site runs fine as well as the tests in the browser. In the console, I am able to generate MVC, test cases, fixtures, etc. What I am unable to do it run my tests on the...

How to auto import all Stripe classes into CakePHP

php,cakephp,cakephp-2.0,stripe-payments
How do I import all necessary classes from Stripe PHP SDK (2.1.0) into CakePHP (2.6.1)? I have added a submodule for the Stripe and cloned it into app/Vendor/Stripe My code looks like this: <?php App::uses('Stripe', 'Vendor/Stripe/lib'); // Secret API Key for Stripe \Stripe\Stripe::setApiKey('sk_test_xxxxxxxxxxxxxxxxxxx'); class BillingController extends AppController { // My...

CakePHP unable to delete associations by cascade or beforeDelete()

php,cakephp,cakephp-2.0
I'm on CakePHP 2.6 I want to delete several dependent models... Users hasMany ConversationsUser (join model) ConversationsUser belongsTo User belongsTo Conversation Conversation hasMany ConversationsUser All relationships are dependent => TRUE When I delete a User, I want all ConversationsUser to be deleted, as well as all Conversations. Currently, only the...

How to view a cakephp plugin page

php,cakephp,plugins,cakephp-2.0
I'm making a plugin called "test", as an example. Is it possible to create "pages" for this plugin and display them? In my plugin folder I've got a folder called View, and inside that another folder called Pages, which contains a file: "demo5.ctp" +test view Pages demo5.ctp +webroot I'm assuming...

How to install CakePHP plugins from Composer into app/Plugin

php,cakephp,plugins,cakephp-2.0,composer-php
I'm trying to install this plugin: https://github.com/ichikaway/cakephp-mongodb/ into my CakePHP project using Composer. And everything was smooth, but it installed into [project root]/Plugin (directory created by Composer I guess) instead of [project root]/app/Plugin. Obviously, in that case, it's impossible to load it by using: <?php //app/Config/bootstrap.php CakePlugin::load('Mongodb'); If I manually...

how to send an email to a user in cakephp 2.x

cakephp-2.0
I will greatly appreciate with all my heart if an expert would help me on how to send an email to a user. am building a registration system. after a user successfully applies for registration, the admin must approve and at the click of the approve button, an email is...

How to access cakephp model's validate from custom view template

cakephp,cakephp-2.0
I have created a 'form' template to bake custom theme views (Cake 2.6.0). I am trying to access field properties from the Model's $validate array. However, accessing $model->validate shows an empty array. My model has several fields with rules defined in it's $validate property. Is the $validate property not accessible...

Multiple redirect in cakephp

php,cakephp,redirect,cakephp-2.0,cakephp-2.3
I want redirect to two pages one is view part another one is index part . Example : I am going to add new user. After i click submit button . The page has direct to index page in new tab and one more redirect is view part . Currently...

cakephp call a controller function in view file

php,cakephp-2.0
My method is public function topmenu($parentsid=null){ $this->layout =false; $category_tree = $this->Categorymaster->find('all',array('order'=>'Categorymaster.lft ASC','conditions'=>array('Categorymaster.parent_id'=>$parentsid))); echo '<ul class="sub-menu" role="menu">'; foreach($category_tree as $parentval){ echo '<li>'.$parentval['Categorymaster']['name'].'</li>'; $id = $parentval['Categorymaster']['id']; $haschild = $this->Categorymaster->children($id, true); if...

Saving Multiple record related to the same Model in Cakephp

cakephp,save,cakephp-2.0
I have a rating system the user should input his data in the input table for each year(All the years are listed) then he save all the input data at once, if the data is exist previously then the system should display the data in the input field so the...

how to call controllers from the cakephp default layout?

php,cakephp,cakephp-2.0
I have a controller called UsersController, is there a way I can output some values from this controller to the cakephp default layout? Here is what I have tried, the default.ctp: <?php foreach ($users as $user): ?> <ul class="nav navbar-nav navbar-right"> <?php if (!$this->Session->read('Auth.User.id')) : ?> <li> <?php echo $this->Html->link('Login',array('controller'...

One counterCache incrementing, one not - despite identical code for both

php,cakephp,cakephp-2.0
I am developing a basic forum system and have used three counter caches in it. Two are for categories (Containers of threads), which have a reply_count and a thread_count, and the last is for the post itself which has a reply_count. A thread is made from multiple ForumPosts, where one...

Use a Custom Status Code with CakePHP 2.x

php,cakephp,cakephp-2.0,http-status-codes
I need to use a custom status code for a response in CakePHP 2.x, for instance 422. However the CakeResponse class only allows those status codes that are already setup in the CakeResponse class. Is there a way for me to use my custom status code with CakePHP? Note if...

jpgraph Warning (2): file_exists() [function.file-exists]: open_basedir restriction in effect

cakephp,cakephp-2.0,jpgraph,open-basedir
I'm having a trouble on making the jpgraph's image work on the web. When I run it in localhost the jpgraphs works but when I uploaded it there is an error message: Warning (2): file_exists() [function.file-exists]: open_basedir restriction in effect. File(/usr/share/fonts/truetype/arialbd.ttf) is not within the allowed path(s): (/home/:/usr/lib/php:/tmp) [APP/Vendor/jpgraph/jpgraph-3.5.0b1/src/jpgraph_ttf.inc.php, line...

Including common code across layouts in cakephp

php,cakephp-2.0
I have a block of code that contains page configuration like shown below. I'd like to use this across my view layouts in CakePHP. I could use the PHP include function but I want to stay in line with CakePHP convention. So I tried putting this code in an element,...

CakePHP memcached configuration in core.php or bootstrap.php

cakephp,caching,memcached,cakephp-2.0
I am trying to figure out where to setup my memcached configuration in CakePHP 2. Both core.php and bootstrap.php have sections to set up any cache such as memcached, but I still haven't figured out which file to use. Also the CakePHP documentation is not so clear about this in...

cakephp saving data from different tables

cakephp,cakephp-2.0
I'm having a problem on saving the data inputted in the package and image table because I want to save both's data at the same time. I have a table for Package and Image. The Image table consist of (id, package_id, and image). Package hasmany Image and Image belongs to...

CakePHP - Pagination total count differs from actual count when using DISTINCT

php,pagination,cakephp-2.0
I have a find method that uses a DISTINCT clause to get results from my Model. The Controller code looks like below $options = array( 'limit' => 10, 'fields' => array( 'DISTINCT id', 'title', ), 'contain' => array( 'Dealer' => array('id'), ), 'paramType' => 'querystring' ); $this->Paginator->settings = $options; $cars...

CakePHP: habtm with join table having an extra field

php,mysql,cakephp,join,cakephp-2.0
I am generating model tables with cake bake utility, and I am facing a strange situation. I have these tables: product(id_product) guest(id_guest) product_guest(product, guest, amount) where product_guest table keep trace of what product a guest bought, and the amount of product bought. Now, with HABTM relationship on cake bake, I...

how to keep my product ID in cakephp 2.0

cakephp,cakephp-2.0
i have two table Location and Car , what I want is: when I click on the picture of the car (View / Cars / view.ctp) redirected to the location add form (View / Locations / add.ctp) while keeping the ID of the car I've previously chosen ...

Where to create common functionalities with view in cakephp?

cakephp,cakephp-2.0,components
I am new in cakephp. I have a module with name contact us in 1 of my project. This module need to show on almost all pages of the website. So my question is, for this common module can we create component or there is some other way to complete...

Why used App::uses('Controller', 'Controller') before all controllers

cakephp,cakephp-2.0,cakephp-2.1,cakephp-2.3
Sorry to Ask but I can't understand why following line written before every controller. App::uses('Controller', 'Controller'); If we write following code with extends controller that means all the property and function of Controller class we can access in AppController. class AppController extends Controller{...} So, My question is If I do...

How to implement pagination with search in CakePHP

cakephp,pagination,cakephp-2.0
My pagination is working, even the search is also working. But the problem that I'm having is when i click on next page link in the pagination links. The search is not working for the next page of the pagination. Also I need to know how I send other parameters...

Cakephp lose session when close browser and apache load balancer

apache,session,cakephp,cakephp-2.0
my site have config load balancer from https to http and in my cource code /app/Config/core.php Configure::write('Session', array( 'defaults' => 'cake', 'timeout' => 4320, 'checkAgent' => false, 'cookieTimeout'=>0, 'ini' => array( 'session.cookie_secure' => false, 'session.referer_check' =>false ) )); it's mean that session is store in /app/tmp/. and timeout 3days. but...

Inserting new row instead of Updating

cakephp,cakephp-2.0,cakephp-1.3,cakephp-2.3
I am trying to update a profile in the database without passing the profile id as a paramater and instead of updating I am adding new row. I tried to use the getLastInsertId() but it did not work. public function editProfile(){ if (isset($this->data)){ $Client = $this->Client->find('first', array( 'fields' => array('email','username','first_name','surname','country','phone_prefix','phone'),...

How to store multiple params on Session

php,session,cakephp,cakephp-2.0
I'm using like this: if(!empty($this->request->data['cd_pedido'])){ $this->set('filtroBusca',array('cd_pedido'=>$this->request->data['cd_pedido'])); }else if(!empty($sessaoCdPedido)){ $this->set('filtroBusca',array('cd_pedido'=>$sessaoCdPedido)); } if(!empty($this->request->data['cd_seq_pedido'])){ $this->set('filtroBusca',array('cd_seq_pedido'=>$this->request->data['cd_seq_pedido'])); }else if(!empty($sessaoCdSeqPedido)){...

How to return array for a recursive function using PHP?

php,arrays,recursion,cakephp-2.0
I have a Multi-dimensional array like this: <pre>Array ( [0] => Array ( [id] => 52a83521-0914-4264-8fd9-07d9c601692a [role_id] => 2 [children] => Array ( [0] => Array ( [id] => 54c1f5e4-b52c-4e17-b1bf-1f4616091b4e [role_id] => 8 [children] => Array ( [0] => Array ( [id] => 54c20aba-201c-40ce-b3df-22d516091b4e [role_id] => 9 ) [1] =>...

CakePHP SQL Error when trying to use loadModel

mysql,cakephp-2.0
I have two controllers (Feeds & Items), on the Items add view, I want some information from the Feeds table visible to the user. So in the Items Controller I'm trying to access the Feed model, everything I have come across recommends to use loadModel but when I try to...

SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias

cakephp,cakephp-2.0,cakephp-1.3,cakephp-2.1,cakephp-2.3
class Store extends AppModel { var $useTable = 'store'; var $belongsTo = array( 'Employee' => array( 'className' => 'Employee', 'foreignKey' => 'employee_store' ) ); } Controller public function index(){ $options=array( 'joins' => array( array( 'table' => 'Employee', 'alias' => 'Employee', 'foreignKey' => true, 'conditions'=> array('Employee.employee_store = Store.store_name') ) )); $coupons...

How to Join one table to another table by zipcode?

mysql,cakephp-2.0,model-associations
I have two table I want to join Ad.zipcode with Zipcode.zip please check below details - Table : ads +----+----------+---------+----------+ | id | user_id | zipcode | photo | +----+----------+---------+----------+ | 1 | 1 | 751010 | img1.jpg | | 2 | 2 | 123456 | img2.jpg | | 3...

CakePHP: Multiple Model in Controller Action:add

database,cakephp,cakephp-2.0
I just started with CakePHP recently. The framework make things easy, but today I just find myself a new question. If a Project model has an image, it would be accessible somewhere like $this->data['Project']['image']. Since there's only 1 image to 1 project, it can be a field in the Project...

Is CakePhp adding timestamp to my javascript files requested by ajax?

cakephp-2.0
I am using Pjax to fetch pages on my cakePhp website. I am getting an error due to the javascript being fetch again because it see's it as a new file due the .js?_=timestamp being added to it. main.min.js?_=1425763395728 If a page is being requested by ajax does cakePhp add...

Declaration of Upload::beforeSave() should be compatible with Model::beforeSave($options = Array) [APP/Model/Upload.php, line 5]

cakephp,model,cakephp-2.0
I am being shown the following error on top of my page when using beforeSave method in my Upload model. Strict (2048): Declaration of Upload::beforeSave() should be compatible with Model::beforeSave($options = Array) [APP/Model/Upload.php, line 5] Could someone point out what I'm doing wrong? Here is my model: <?php App::uses('AppModel', 'Model');...

Cakephp Model constants in controller

php,cakephp,model,cakephp-2.0
I am working in a CakePHP project. I am getting the error: Class 'Book' not found, when trying to access a model constant from a controller. In my model I declared a const named 'TYPE' class Book extends AppModel { const TYPE = 0; } In the controller I loaded...

HABTM CakePHP no results for related model

cakephp,cakephp-2.0,has-and-belongs-to-many
I have problem with HABTM models. When I try to fetch any related model f.e. like this: $this->Tagi->find('first'); I dont get any results for associated model. Result looks like this: array( 'Tagi' => array( 'id' => '1', 'nazwa' => 'sth' ), 'Instytucje' => array() ) I am sure that there...

CakePHP Howto allow value change from A to B but not vice versa (B to A)

php,forms,cakephp,cakephp-2.0
I've created a form using the Form Helper and one of the fields is a select for values (for example) A and B. When you add a record, both options A and B are available. You may also edit the record later, however: I want to allow to switch from...

Cakephp custom folder structure for admin

php,cakephp,routing,namespaces,cakephp-2.0
Since my app is getting bigger i would like to separate admin prefix actions and views from normal actions and views. The new folder for admin is Controller/admin/UsersController.php. I would like to change my cakephp controllers and views folder structure to match the prefix I'm using. Example for admin prefix:...

CakePHP configuring HybidAuth google provider

cakephp,cakephp-2.0,cakephp-2.3,google-authentication,hybridauth
I am using HybridAuth. I have already configured vkontaknte and facebook providers. Now I need additional one - google. Below the part of my config hybridAuth: 'Google' => array ( "enabled" => true, "keys" => array ( "id" => "my_id", "secret" => "my_secret_key" ), "scope" => "https://www.googleapis.com/auth/userinfo.profile ". // optional...

Write JSON to DOC file in PHP

php,json,cakephp-2.0
I have a situation where a webserver posts a JSON array which includes some parameters as well as a document data within it. I get the data, content-type and filename. I convert this JSON into an associative array so that I can work with it. An example of the converted...

Cakephp link to view a page in sub folder

cakephp,cakephp-2.0,cakephp-2.3
I wish to display a normal page in a sub-dir of the Pages folder, however cakephp keeps removing the "/" forwardslash and replacing it with "%2F".Ive tried to add the escape=>false flag but it doesnt seem to work. What am i doing wrong? my code; echo $this->Html->link('Tiny MCE plugin',array( 'controller'=>'pages',...

Containable behavior only working when local

php,cakephp,cakephp-2.0,cakephp-2.5
I'm having a very strange issue. I'm working with XAMPP on my local computer, and everything works perfect. But when I upload it to my server, suddenly ContainableBehavior stops recognizing associations. Cake's version: 2.5.6 Here's XAMPP's phpinfo(): http://pastebin.com/DeZWMh42 And here's my server's phpinfo(): http://pastebin.com/rtZ0kTAM Both locations have the exact same...

Magic of Find query

mongodb,cakephp,cakephp-2.0
I have user controller and I written following find query with condtion $userData = $this->User->find('first', array('conditions'=>array('id'=>null))); If I written find query with id=null condition then also it return first record from database. I expected no any record because condition is false, But it written first record. My Question is why...

Sidebar list with cakephp

ajax,pagination,cakephp-2.0
I want to make a sidebar list so when the user click on the item all the information that related to this item is viewed in a specific area in the same page , and its the same for all items,what is the best way to do that ( AJAX...

Cake PHP Use Conditions and Order By in Paginate

pagination,cakephp-2.0
I'm trying to use Conditions and Order By in cake PHP paginate function of the Paginator helper This is my code which I'm using $this->set('equipment', $this->Paginator->paginate('Equipment',array('conditions' => array('Equipment.equipment_type_id' => 19), 'order' => array('Equipment.problem_count', 'Equipment.barcode DESC')))); But it gives me this error Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'conditions'...

AngularJS filter is not working in object

javascript,arrays,angularjs,filter,cakephp-2.0
My AngularJS filter is not working with an Object. View: <input type="text" ng-model="searchKeyUser.$" placeholder="Pesquisar Chaves" class="form-control"><br> <ul class="list-group"> <li class="list-group-item clicavel chaves" ng-repeat="chave in keyUsers | filter:searchKeyUser" ng-class="{ active:Grupo.isActiveKey(chave.Chave.id)}" ng-click="Grupo.mostrar()"> {{chave.Chave.chave}}{{chave.show}} </li> </ul> I tried to use searchKeyUser.$, searchKeyUser.Chave.$, searchKeyUser.Chave.chave, and nothing...

how to write distinct and count query in cakephp using find

cakephp,cakephp-2.0
How to write below query in cakephp using find . $this->tmp_sale->query("select DISTINCT COUNT( tax ) as 'tax_amount' , SUM( quantity ) as 'quantity1',tax,tax_amount1 from tmp_sale where employee='$emp' and no ='$no' and store='$store_name' group by tax"); ...

CakePHP : How to Create OptGroup Drop down list from DataBase?

php,database,cakephp-2.0
i am new to CakePHP, and developing a new project. i just want to know that, how to show optgroup dropdown list that is fetched from database. i want to fetch array like this below $arr = array( 'optgroup' => array( '1','2','3'), 'optgroup2' => array( '1','2','3') ); ...

Display value in View layer (Cakephp)

cakephp,view,cakephp-2.0
How can I display Organisation value in view, I tried this , but it does not work Code in Model : function getOrganisationName($organisation_id){ return $orgaName = $this->find('list',array('conditions' => array('Organisation.id' => $organisation_id), //array of conditions 'fields' => array('Organisation.name'))); } Code in Controller : $orgName = $this->Organisation->getOrganisationName($organisation_id); $this->set(compact('indicators', 'organisations', 'rejections', 'projects', 'organisation_id','orgName'));...

How to insert audio/mp3 in Cakephp?

php,cakephp-2.0,html5-audio
<?php echo $this->Html->media('musica.mp3'); ?> I'm trying this in the view.ctp (USING CAKEPHP 2.5....)...

cakephp: how to display foreign key table field

cakephp-2.0
basically, database table: Products: id, name Comments: productId,comment Model: product.php class Product extends AppModel { public $hasMany = array('Comment'=>array('foreignkey'=>'productId')); } comment.php class Comment extends AppModel { public $belongsTo = array('Product'); } In product index.ctp, how can I display one product comment? What I need to write in ProductsController.php and index.ctp?...

Twitter OAuth - Invalid or expired access token

php,cakephp-2.0,twitter-oauth
I am trying to share post using twitteroauth with latest version. Below is my code. require APP."Vendor/twitteroauth-master/autoload.php"; // twitter v0.5.1 SDK if(isset($_REQUEST['oauth_verifier'])) { $request_token = []; $request_token['oauth_token'] = $this->Session->read('twtr_oauth_token'); $request_token['oauth_token_secret'] = $this->Session->read('twtr_oauth_token_secret'); /* If denied, bail. */ if (isset($_REQUEST['denied'])) { exit('Permission was denied. Please start over.'); } /* If the...

How validate a personal identification number in cakephp

validation,cakephp-2.0
I need to validate a field in my form, this field belongs to the personal identification number of my country, this number has 10 digits Example: card = 1710034065 2 1 2 1 2 1 2 1 2 (coefficient) 1 7 1 0 0 3 4 0 6 (personal identification...

Can i convert whole cakephp website to web services?

cakephp-2.0
Hey I m working on project in cakephp. There will also be apps for Android as well as iPhone. How can i convert my web code to web services.

how to display max and min number from database in cakephp

cakephp,cakephp-2.0,cakephp-1.3,cakephp-2.1,cakephp-2.3
how to display max and min number in cakephp controller part . $rs = $this->Item->find('all' , array ('fields' => array('Max(Item.no) as no'))); I want max number of Item table . I need to add some rand number to that and save it in new row ....

how loadModel and modified field in another controller Cakephp 2

php,cakephp,cakephp-2.0,cakephp-2.3
I have two tables, cars and locations; I want loadModel Car in LocationsController and I want, when I add location, for it to automatically status column in Cars table registers unavailable into locationsController: public function add($car_id) { if ($this->request->is('post')) { $this->Location->create(); if ($this->Location->save($this->request->data)) { $this->Session->setFlash(__('The location has been saved.')); return...

error in joining table in cakephp

cakephp,cakephp-2.0,cakephp-1.3,cakephp-2.1,cakephp-2.3
Controller public function index(){ $this->Store->unbindModel( array('belongsTo' => array('Employee')), true ); $options=array( 'joins' => array( array( 'table' => 'Employee', 'alias' => 'Employee', 'foreignKey' => true, 'conditions'=> array('Employee.employee_store = Store.store_name') ) )); $coupons = $this->Store->find('all', $options); } Model class Store extends AppModel { var $useTable = 'store'; } Sql : SELECT `Store`.`id`,...

CakePHP how to modify validation from shell script

php,shell,validation,cakephp,cakephp-2.0
I'm using CakePHP v2.6 and I'm writing a shell script which needs to have slightly different validation rules then those in the $validates property of the model. I've read the section of the book about modifying validations on the fly, but all the examples are from within a model. And...