I have an eloquent class with the protected set:
protected $fillable = array('user_id', 'key', 'value');
Yet if I do:
Foo::create(array('user_id'=>1, 'key'=> 1, 'value' => 'v'));
I get
Array
(
[query] => insert into `foo` (`updated_at`, `created_at`) values (?, ?)
[bindings] => Array
(
[0] => 2013-09-29 16:32:54
[1] => 2013-09-29 16:32:54
)
[time] => 0.42
)
On the other hand
Foo::insert(array('user_id'=>1, 'key'=> 1, 'value' => 'v'));
works flawlessly.
I ran into this issue. I was overriding the __construct method in my model object. After I removed my __construct method, everything seemed to go back to normal.
I can't say for sure this is what you are experiencing (and this answer is 6 months after your original question), but hopefully this will help someone else who comes across this same issue.
I have 2 database-tables which are connected as followed:
ProjectProduct hasMany Bde
Bde belongsTo ParentBde / Bde hasMany ChildBde
The first association is new and shall be added into the application now. Since then I used $this->Bde->find('threaded') to get an threaded array of these records.
Now I need/want to query the ProjectProduct-table and wanted to use the containable-behavior to get all associated Bdes.
Now I'm wondering: Is it possible (in a Cake way) to still get threaded results with a call of find on ProjectProduct?
I tried doing $this->ProjectProduct->find('threaded', array('contain' => 'Bde')) but this will try to get threaded results on ProjectProduct.
I'm expecting an array like this:
Array (
[ProjectProduct] => Array (
[id] => 17,
[Bde] => Array (
[0] => Array (
[id] => 1,
[project_product_id] => 17,
[children] => Array()
)
)
)
)
Since I couldn't find any information how this can be done in one call or the "Cakish" way, I've done it like this:
$project_products = $this->Project->ProjectProduct->find('all');
foreach ($project_products as $key => $project_product) {
$project_products[$key]['Bde'] = $this->Project->Bde->find('threaded', array('conditions' => array('Bde.project_product_id' => $project_product['ProjectProduct']['id'])));
}
If someone has a better way in doing this I really appreciate any other ideas!
I am using jQuery to pass data to the following URL in my cakephp 1.2 app:
$("#test").load("http://domain.com/controller/action/productID:2001642/questionID:2501322/value:C%2B%2B/questionType:3", function({
$("#test").fadeOut(3000);
});
In the controller when I
debug($this->params['named']);
it returns
Array
(
[productID] => 2001642
[questionID] => 2501322
[value] => C
[questionType] => 3
)
The URL part of $this displays
[url] => Array
(
[url] => deu/productanswers/updateoredit/productID:2001642/questionID:2501322/value:C /questionType:3
)
so that somewhere along the line the C++ or C%2B%2B is getting squished.
Does anyone have a solution or workaround please?
Cheers,
Taff
Although I would be very interested in a cakephp solution, I resorted to using $_SERVER['REQUEST_URI']
Definitely not a sexy solution
$tmp1 = explode('value:',$_SERVER['REQUEST_URI']);
$tmp2 = explode('/',$tmp1[1]);
$prod=$this->params['named']['productID'];
$ques=$this->params['named']['questionID'];
$value=urldecode($tmp2[0]);
Hope this helps someone in the future...
I am trying to get Propel to work in my Zend app, it seems that I can get the Propel library to load (from library/propel) but when called I get the exception: 'No connection information in your runtime configuration file for datasource [default]' (when I try to make a connection: 'Propel::getConnection'). My Db is not even named 'default'. I have this in my bootstrap.php from another SO question/answer:
require_once 'propel/Propel.php';
Propel::setConfiguration($this->getOptions('propel/MyPropel-conf.php'));
Propel::initialize();
// so we can get the connection from the registry easily
return Propel::getConnection();
I want the Propel configs (classmap conf as well) to be in the '/application/configs' (copies are there too right now), but I thought If I can get Propel to load from library/propel, then maybe moving my 'conf' files there, I may get them to load too. It seems that if I 'force' the config, by manually loading the params, or if I seem to get it in a temporary 'right' location (or use an absolute path), the exception I then get is this:
'Unable to open PDO connection [wrapped: SQLSTATE[28000] [1045] Access denied for user 'www-data'#'localhost'
As if Propel is not paying any attention to my configs.
My config looks like this; converted from the xml:
$conf = array (
'datasources' =>
array (
'unmActTestDB' =>
array (
'adapter' => 'mysql',
'connection' =>
array (
'dsn' => 'mysql://root:PASSWORD#localhost/unmActTestDB',
),
),
'default' => 'unmActTestDB',
),
'log' =>
array (
'ident' => 'propel-act',
'level' => '7',
),
'generator_version' => '1.5.6',
);
$conf['classmap'] = include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'classmap-unmActTestDB-conf.php');
return $conf;
If it helps, I still have the Zend PDO DB adapter loading in the application.ini file too, would that cause a clash?. Is there a standard way to get Propel to work with Zend? Or can anyone see what I'm doing wrong?
I have been to several posts here on SO, and a couple popular posts like this one The Adventures Of Merging Propel With Zend Framework and this one at Zend's dev zone Integrating Propel with the Zend Framework, among others including the Propel Docs. They have been helpful, but I am really struggling with this. Thanks in advance! My current Zend Directory structure looks like this (w/ the two propel confs also in the library/propel folder:
What I ended up doing is this:
I got a good grip on how to generate my models from a 'reverse' using Propel. It created (as before) a 'schema.xml' file for me to build my models with.
Also my 'runtime.xml' file was incorrect for my needs, after the build I was not connecting to the right database because of my omission of a few tags, overall it is quite simple though:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<log>
<ident>unmActTestDB</ident>
<level>7</level>
</log>
<propel>
<datasources default="unmActTestDB">
<datasource id="unmActTestDB">
<adapter>mysql</adapter>
<connection>
<dsn>mysql:host=localhost;dbname=unmActTestDB</dsn>
<user>zend</user>
<password>PASSWORD</password>
<database>unmActTestDB</database>
</connection>
</datasource>
</datasources>
</propel>
</config>
The 'dsn' tag has to be in the format above with the addition of the 'user', 'password', and the 'database' tags. This fixed my issue with the database connection errors. As quoted above (and here) the exception thrown was: 'No connection information in your runtime configuration file for datasource [default]'
As far as the loading of my models goes, I ended up putting them in my 'library' folder, I already have that folder autoloading in my app, plus it seemed like a good place form them.
here is an image of my 'updated' directory structure:
Note the addition of the 'unmActTestDB' folder in my directory, this is my ORM models.
Another thing to note is that I put my generated 'conf' files into my 'application/configs' folder. These are correct now, after the correction of the runtime.xml file and a 'rebuild'.
As a side note, I had to edit my 'schema.xml' file by hand (several times :) )...The original database used plural names for the tables, so I edited all the 'phpname' declarations (attributes actually, on the declaration tag) to be singular so I wouldn't access an object called 'Users'...instead I can now access a 'User' object. I kept the table names the same (tables are plural, and I won't have any issues importing the existing data, etc.) This was suggested by an answer to another one of my questions, see here How to get related object Propel ORM.
The other big edit I made was to add primary key declarations (again, attributes) for the many SQL views in the DB, also I added a 'readonly' and a 'noSQL' attributes to the declarations, this way I will have access (through the Propel models) to my views.
And, just to be thorough, and for those who are interested here is the addition to my 'bootstrap.php' file that does my 'Propel Init' for me...
protected function _initPropel()
{
$this->_logger->info('Bootstrap ' . __METHOD__);
require '../library/propel/Propel.php';
Propel::init(APPLICATION_PATH . '/configs/unmActTestDB-conf.php');
Propel::initialize();
return Propel::getConnection();
}
Another NOTE: the '$this->_logger->info('Bootstrap ' . METHOD);' calls my 'logging' method that just tells 'firePHP' that this method has loaded. The /configs/unmActTestDB-conf.php' calls the second 'conf' file that Propel generates... and here is the 'corrected' version of that file (the unmActTestDB.conf file that is), Note the changes in the 'connection' array.
<?php
// This file generated by Propel 1.5.6 convert-conf target
// from XML runtime conf file runtime-conf.xml
$conf = array (
'datasources' =>
array (
'unmActTestDB' =>
array (
'adapter' => 'mysql',
'connection' =>
array (
'dsn' => 'mysql:host=localhost;dbname=unmActTestDB',
'user' => 'zend',
'password' => 'PASSWORD',
'database' => 'unmActTestDB',
),
),
'default' => 'unmActTestDB',
),
'log' =>
array (
'ident' => 'unmActTestDB',
'level' => '7',
),
'generator_version' => '1.5.6',
);
$conf['classmap'] = include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'classmap-unmActTestDB-conf.php');
return $conf;
I am off and running now! This was a great way to go, otherwise I was looking and writing sooo many mapping classes for my app. Propel (currently) generates over 300 models for this application! Plus the base classes, it would take me forever...
Anyway, can anyone give me the error code definitions for when files are uploaded in cakePHP.
So my $this-data contains something like this,
Array
(
[file] => Array
(
[name] => cake.jpg
[type] => image/jpeg
[tmp_name] => /tmp/hp1083.tmp
[error] => 1
[size] => 24530
)
)
What does [error] = 1 indicate?
While you're at it can you list the break down of all the numbers, then maybe it'll be easier for others to find it the future
Thanks!
File upload has nothing to do with CakePHP.
$this->data contains what $_FILE contains, it is a HTTP/PHP specific array.
Documentation, $_FILE, and the error codes.