I have MySQL database for store data. Some field is type decimal. I don't know why zend_db always fill zero pad for decimal type field.
public function getListings() {
$select = $this->getDb()->select()
->from($this->_tableName, array('listing_sell_price', 'listing_sell_total_price'));
return $select->query()->fetchAll();
}
When I try to var_dump all data from model
$listings = RW_Model_Listing::getInstance()->getListings();
var_dump($listings);
There is zero padding
array(2) {
[0]=> array(2) { ["listing_sell_price"] => string(10) "0004750000", ["listing_sell_total_price"] => string(10) "0004750000"}
[1]=> array(2) { ["listing_sell_price"] => string(10) "0000008000", ["listing_sell_total_price"] => string(10) "0000008000"}
}
Any solution for removing zero pad ?
Best regard,
Brian
Okay it's my stupidity.
I forgot to uncheck ZeroFill in my Table Configuration LoL
Related
I have an extension, that works fine on TYPO3 6.2 and 7.4. I try to run ist on TYPO3 8.7.
The problem is, that the values of my database result object are null except uid and pid.
I use $this->subjectRepository->findAll(); and I tried to use individual queries. The result is the same.
$query = $this->createQuery();
$query->statement('SELECT * FROM tx_libconnect_domain_model_subject WHERE deleted = 0 AND hidden = 0');
$query->execute();
This is the dump of the query:
TYPO3\CMS\Extbase\Persistence\Generic\Queryprototypeobject
type => protected'Sub\Libconnect\Domain\Model\Subject' (35 chars)
objectManager => protectedTYPO3\CMS\Extbase\Object\ObjectManagersingletonobjectfiltered
dataMapper => protectedTYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMappersingletonobjectfiltered
persistenceManager => protectedTYPO3\CMS\Extbase\Persistence\Generic\PersistenceManagersingletonobjectfiltered
qomFactory => protectedTYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactorysingletonobjectfiltered
source => protectedTYPO3\CMS\Extbase\Persistence\Generic\Qom\Selectorprototypeobject
nodeTypeName => protected'Sub\Libconnect\Domain\Model\Subject' (35 chars)
selectorName => protected'tx_libconnect_domain_model_subject' (34 chars)
constraint => protectedNULL
statement => protectedTYPO3\CMS\Extbase\Persistence\Generic\Qom\Statementprototypeobject
statement => protected'SELECT * FROM tx_libconnect_domain_model_subject WHERE deleted = 0 AND hidde
n = 0' (81 chars)
boundVariables => protectedarray(empty)
orderings => protectedarray(empty)
limit => protectedNULL
offset => protectedNULL
querySettings => protectedTYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettingsprototypeobject
respectStoragePage => protectedTRUE
storagePageIds => protectedarray(1 item)
ignoreEnableFields => protectedFALSE
enableFieldsToBeIgnored => protectedarray(empty)
includeDeleted => protectedFALSE
respectSysLanguage => protectedFALSE
languageOverlayMode => protected'1' (1 chars)
languageMode => protected'content_fallback' (16 chars)
languageUid => protected0 (integer)
usePreparedStatement => protectedFALSE
useQueryCache => protectedTRUE
The dump of the result object on TYPO3 8.7:
object(Sub\Libconnect\Domain\Model\Subject)#886 (10) { ["title":protected]=> NULL ["dbisid":protected]=> NULL ["ezbnotation":protected]=> NULL ["uid":protected]=> int(2) ["_localizedUid":protected]=> int(2) ["_languageUid":protected]=> NULL ["_versionedUid":protected]=> int(2) ["pid":protected]=> int(1) ["_isClone":"TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject":private]=> bool(false) ["_cleanProperties":"TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject":private]=> array(5) { ["title"]=> NULL ["dbisid"]=> NULL ["ezbnotation"]=> NULL ["uid"]=> int(2) ["pid"]=> int(1) } }
On TYPO3 6.2:
object(Sub\Libconnect\Domain\Model\Subject)#1078 (10) { ["title":protected]=> string(29) "Allgemein / Fachübergreifend" ["dbisid":protected]=> string(2) "28" ["ezbnotation":protected]=> string(2) "AZ" ["uid":protected]=> int(2) ["_localizedUid":protected]=> int(2) ["_languageUid":protected]=> NULL ["_versionedUid":protected]=> int(2) ["pid":protected]=> int(1) ["_isClone":"TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject":private]=> bool(false) ["_cleanProperties":"TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject":private]=> array(5) { ["title"]=> string(29) "Allgemein / Fachübergreifend" ["dbisid"]=> string(2) "28" ["ezbnotation"]=> string(2) "AZ" ["uid"]=> int(2) ["pid"]=> int(1) } }
Do you have any idea? Thanks a lot.
Sounds like the TCA is not valid.
There were some changes in TCA in the last major updates, e.g.:
The required field "renderType" when using a select
You have to use the tablename as filename for the TCA definitions
You need to move the TCA file for each table into the folder Configuration/TCA
You can see the TCA reference here: https://docs.typo3.org/typo3cms/TCAReference/
I have TYPO3 7.6.18 and I am making ajaxDispatcher. I stay on final study. I trying to call $this->bootstrap->run( '', $this->configuration ); but it get an error. I can't know what this error is exactly. But I'm sure problem in this line.
My $this->configuration is:
array(8) {
["pluginName"] => string(7) "Piphoto"
["vendorName"] => string(5) "Istar"
["extensionName"] => string(7) "feFiles"
["controller"] => string(5) "Photo"
["action"] => string(4) "test"
["mvc"] => array(1) {
["requestHandlers"] => array(1) {
["TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler"] =>
string(48) "TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler"
}
}
["settings"] => array(2) {
["adminemail"] => string(15) "mvnaz#yandex.ru"
["pageShowPhotoId"] => string(2) "32"
}
["persistence"] => array(1) {
["storagePid"] => string(2) "31"
}
}
Action test is allowed in local_conf. The Vendor is set right, extension name, plugin and controller too.
Sorry)
["extensionName"]=>
string(7) "fefiles"
fefiles need Fefiles - uppercase!
Thank you all for help! )
In my model I have the following function
protected $_users ='users';
public function getbyid($user_id)
{
$select = $this->_db
->select()
->from($this->_users)
->where('users.user_id =?', $user_id);
$result = $this->_db->fetchRow($select)->toArray();
return $result;
}
When it is called it returns fatal error :
Call to a member function toArray() on a non-object
Can anyone point in the direction of what I am doing wrong.
Thanks.
output of Zend_Debug::dump($this->_db->fetchRow($select));
array(11) {
["user_id"] => string(1) "1"
["role"] => string(13) "administrator"
["email"] => string(18) "bjh497#hotmail.com"
["password"] => string(40) "62bb49da919f0d349ed2cbbec559d7ed649dd238"
["created"] => string(19) "2013-05-09 07:34:00"
["modified"] => NULL
["status"] => string(6) "active"
["salt"] => string(40) "ce8d96d579d389e783f95b3772785783ea1a9854"
["lastlogin"] => NULL
["first_name"] => string(3) "Bob"
["last_name"] => string(5) "Smith"
}
Trying to use the result to populate a form in controller as follows
$userdetails = new Account_Model_User;
$userdetails->getbyid($user->user_id);
$userdetails = $userdetails;
$form = new Account_Form_Profile;
$form->populate($userdetails);
From the looks of that Zend_Debug::dump call, $this->_db->fetchRow($select) already returns and array, so if you call toArray() it will throw the error you mentioned.
It all depends on what you want your getbyid function to return, but I'd say to simply update your code to:
protected $_users ='users';
public function getbyid($user_id)
{
$select = $this->_db
->select()
->from($this->_users)
->where('users.user_id =?', $user_id);
$result = $this->_db->fetchRow($select);
return $result;
}
fetchRow() function return already an array so, you don't need to "cast it " to array.
and you can access it directly by something like
$result = $this->_db->fetchRow($select);
//so now you can access or assign values to a variable
$user_id=$result['user_id'];
Hope it my help.
I have a problem using forms in Symfony 2 with mongoDB documents.
I'm trying to have a form that will represent my first document (Post) with a relation oneToMany to Tags (reference)
The relation is declared like this :
/**
* #Assert\Collection
* #MongoDB\ReferenceMany(targetDocument="Acme\ManagerBundle\Document\Tags")
*/
protected $tags;
A tag has an Id and a Name.
I have tried a lot of things to make it work
$form = $this->createFormBuilder($tag)->add('tags', 'choice', array('choices' => $tags, 'multiple' => true, 'expanded' => true, 'empty_value' => true, ))
The form show the choices but once its submited the form is not valid and keep showing thhis error :
"The fields "0", "1", "2" were not expected"
I've also tried this : symfony2 form choice and mongodb
But the use of it is kinda confusing
UPDATE
This is what i get after the post is submited :
object(Doctrine\Common\Collections\ArrayCollection)#795 (1) {
["_elements":"Doctrine\Common\Collections\ArrayCollection":private]=>
array(2) {
[0]=>
object(Acme\ManagerBundle\Document\Tags)#723 (2) {
["id":protected]=>
string(24) "4f7a0eb1ecd111b99c3d2f25"
["name":protected]=>
string(6) "Fruits"
}
[1]=>
object(Acme\ManagerBundle\Document\Tags)#720 (2) {
["id":protected]=>
string(24) "4f7a0ec7ecd111b99c3d2f26"
["name":protected]=>
string(10) "Vegetables"
}
}
}
So now i understand why i have "The fields "0", "1", "2" were not expected" but i dont understand why Symfony doesn't process it.
I've been looking a the possible bundles but nothing
I have no idea how to have a nice form that will hydrate my object and the related objects,
does anyone has a solution for this issue or other idea to solve this?
Thanks a bunch !
Without seeing the data involved I can only make a best guess here.
It feels like your line of code should look something like.
$tags = $post->getTags();
$fixedTags = array();
foreach ($tags as $tag) {
$fixedTags[$tag->getId()] = $tag->getName();
}
$form = $this->createFormBuilder($post)
->add(
'tags',
'choice',
array(
'choices' => $fixedTags,
'multiple' => true,
'expanded' => true,
'empty_value' => true
)
);
Now I think whats happening is you are getting your $tags data in a form like this.
array(0 => (Object)Tag, 1 => (Object)Tag, 2 => (Object)Tag)
Where as what you really want is probably like this.
array('topic1' => 'Topic 1', 'topic2' => 'Topic 2', 'topic3' => 'Topic 3')
If you this isn't the case, reply with some data output and I'm sure we'll be able to help some more.
A choice field won't save by default (although you could manually do it on form submission). You need to look into the document type which is admittedly not documented well but it's essentially the same type as entity here.
I didn't see this was from 3 years ago! Well, it's here in case others find this page I guess.
If you have a complex SQL query involving many joins (for example returning Articles with their associated many to many Tags) is there anything in Zend Framework that will produce the lovely CakePHP style database results:
Array
(
[0] => Array
(
[ModelName] => Array
(
[id] => 83
[field1] => value1
[field2] => value2
[field3] => value3
)
[AssociatedModelName] => Array
(
[id] => 1
[field1] => value1
[field2] => value2
[field3] => value3
)
)
)
I don't mind if it's an object rather than an array, I just wondered if by using Zend_Db_Table to build a SELECT JOIN query I could save some leg work and get some nicely formatted results.
Here is the kind of code I'm using to build the query:
$select = $db->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
$select->from('tableName','fieldName')
->join('joinTable', 'joinTable.keyId = tableName.keyId',array())
->where('tableName.userId = ?', $userId);
$resultSet = $db->fetchAll($select);
Nothing as pretty as what you're used to just the data I asked for.
The normal Result would be a rowset object, however the ->toArray() is available for most *Zend_DbTable_Abstract* methods.
The $result->toArray() truncated and dumped using Zend_debug::dump():
Lead Tracks array(7) {
[0] => array(9) {
["trackid"] => string(2) "24"
["weekendid"] => string(1) "8"
["shiftid"] => string(1) "1"
["bidlocationid"] => string(1) "1"
["qty"] => string(1) "2"
["lead"] => string(1) "1"
["bidloc"] => string(14) "out of service"
["deptcode"] => string(3) "491"
["stationid"] => string(1) "1"
}
The query:
where = $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART)
->setIntegrityCheck(FALSE);
$where->where('track.bidlocationid = ?', $bidlocationId)
->where('lead = ?', $lead)
->join('bidlocation', 'bidlocation.bidlocationid = track.bidlocationid')
->where('bidlocation.stationid = ?', $stationId)
->order('shiftid ASC')
->order('weekendid ASC');
$result = $this->fetchAll($where);
sorry, just utility :)