Joomla 2.5 Load custom field in components layout fatal error - joomla

Im trying to load custom field in my backend component default view (default.php):
JFormHelper::addFieldPath(JPATH_COMPONENT . '/models/fields');
$productType = JFormHelper::loadFieldType('ProductType',false);
$productTypeOptions = $productType->getOptions();
But I get a fatal error:
Fatal error: Call to a member function children() on a non-object in xxx\libraries\joomla\form\fields\list.php on line 89
When I load this custom field into the form, everything works perfectly.
Any ideas?

Make sure you are adding the correct path to the fields

In your $productType->getOptions() function,
Try removing:
$options = array_merge(parent::getOptions(), $options);

Well, I tried to expand my fellow above idea but it seemed an inappropiate edit, I put it here then:
This worked for me. In your getOptions, if you have something like the getOptions found here (http://docs.joomla.org/How_to_add_custom_filters_to_component_admin), you´ll have this line:
$options = array_merge(parent::getOptions(), $options);
This is the one that makes the error. Why? Well, I´m not sure. If you see the related file, you´ll find this:
foreach ($this->element->children() as $option)
So the problem is that you are calling children() on the model parent that it seems is not initialized. Why the array_merge is needed? Is discussed here (http://forum.joomla.org/viewtopic.php?f=626&t=782877)
My explanation is more like a dirty blind patch, but hope it helps to move forward.

Related

How to rectify class not found in psy shell in laravel tinker?

I am very new to the laravel tinker part, I have one model based on that model I am trying to update some column value but it's throwing an error please help me to resolve the issue.
User::update(["status"=>"active"])->where ('id',1);
Error I am getting is
PHP FATAL error: class 'User' not found in psy shell code on line1
Try User::update(["status"=>"active"])->where ('id',1)->first();
or better still:
$user = User::find(1);
$user->update(["status"=>"active"]);
Where 'plans' comes from must be a mistake in your User model. Did you add private $with(['plans']); or something similar in the model? Maybe you should post your User.php model in the question.

Scope left Join Sub doesn't work - Laravel

I'm new to Laravel I'm making a clone of Twitter. I'm making a scope to get all the likes from the DB, but I get an error from Tinker
I know some basic SQL Queries, but this one is quite complicated, so I've got no idea what to do now.
Tweet model
public function scopeWithLikes(Builder $query)
{
$query->leftJoinSub(
'select tweet_id, sum(liked) likes, sum(!liked) dislikes from likes group by tweet_id',
'likes',
'likes.tweet_id',
'tweet.id'
);
}
Tinker command
App\Tweet::withLikes()->first();
Tinker error
TypeError: Argument 1 passed to App/Tweet::scopeWithLikes() must be an
instance of Illuminate/Database/Query/Builder, instance of
Illuminate/Database/Eloquent/Builder given, called in
C:/wamp64/www/laravel/tweety/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php
on line 1164
I hope I explained it well, but if you need more information please ask me.
Thanks for your answer!
i think that you are using the wrong class for your scope, scope use
Illuminate/Database/Query/Builder
as a parameter while you pass
Illuminate/Database/Eloquent/Builder
in your Twit model file, on the top ...
remove:
use Illuminate/Database/Eloquent/Builder;
and paste:
use Illuminate/Database/Query/Builder;
Did this solve the problem? Because I run into exactly the same issue.
When I change Eloquent to Query, the error message is still the same.
Also the source that is given on Git uses use
Illuminate\Database\Eloquent\Builder;
Hubert

How can I render a twig template in a custom controller in Silex?

I'm playing with Silex microframework to build a very simple app.
The Silex documentation briefly illustrates how to keep your code organised using controller as class and I've also found this useful article talking about the same practice:
https://igor.io/2012/11/09/scaling-silex.html
but still can't solve my problem
The issue:
in my app.php I'm using
$app->get('/{artist}', 'MyNamespace\\MyController::getAlbum');
This is working. MyController is a class correctly loaded through composer using psr-4.
At the moment the return method of getAlbum($artist) is return $player;
What I'd like to do instead, is returning a twig view from getAlbum, something like:
return $app['twig']->render('player.twig', $player);
To do so, what I've tried to do in my custom class/controller is:
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
[...]
public function getAlbum(Request $request, Application $app, $artist)
but this is generating the following error when I try to access the routed pages:
ReflectionException in ControllerResolver.php line 43:
Class MyNamespace\Request does not exist
Whic made me think that there's a namespace conflict between myNamespace and the Silex namespaces?!
What am I doing wrong?
Is this the right way to make $app visible in my custom controller in order to use return $app['twig']... ?
Thank you in advance!
EDIT
After several other tries still didn't get to the point (replies still welcome!) but I've found a workaround solution that could be useful to anyone will incur in a similar issue. Directly in my app.php I added this
$app->get('/{artist}', function (Silex\Application $app, $artist) use ($app)
{
$object = new MyNamespace\MyController();
$player = $object->getAlbum($artist);
return $app['twig']->render('player.twig',
array(
//passing my custom method return to twig
'player' => $player,));
});
then in my player.twig I added:
{{player | raw}}
And this basically means that I still need an anonymous function to get use of my custom method which is a working solution I'm not really happy with because:
I'm using 2 functions for 1 purpose.
The return value of getAlbum is dependent from the use of "raw" in twig.
SOLVED
The workflow described works fine. It was a distraction error: I've placed the namespace of my custom class after use Symfony\Component\HttpFoundation\Request;
namespace declaration in PHP needs always to be at the top of the file, Silex wasn't able to injects $app and $request for this reason.

Magento Fatal error: Call to a member function addLink()

Whenever I try to do something in a popup window, live export or preview a transactioanl email I get an error:
Fatal error: Call to a member function addLink() on a non-object in
/home/jsrdirec/public_html/app/code/core/Mage/Adminhtml/Block/Widget.php
on line 65
Here is app/code/core/Mage/Adminhtml/Block/Widget.php:
protected function _addBreadcrumb($label, $title=null, $link=null)
{
$this->getLayout()->getBlock('breadcrumbs')->addLink($label, $title, $link);
}
Does anyone have any idea what could be causing this?
There can be so many reasons for this , check this question for more information. Mean while you can try this hack to fix your problem.
I had this same problem. I noticed it when I was trying to import products through the import interface. The kicker was that two days before the problem started, everything was working fine. My solution, as a temporary fix, was I edited the _addBreadCrumb function in app/code/core/Mage/Adminhtml/Block/Widget.php to be
protected function _addBreadcrumb($label, $title=null, $link=null)
{
if($this->getLayout()->getBlock('breadcrumbs')){
$this->getLayout()->getBlock('breadcrumbs')->addLink($label, $title, $link);
}
}
For me, I didn't care if there were breadcrumbs on the admin page, specifically when importing products or sending emails. So far, it hasn't caused a problem on the store site itself. Breadcrumbs are still generating as expected, I can still add to cart, checkout, etc.
PLEASE NOTE - This is changing a core class in a core class file, which is not the best/borderline bad if not bad. So I want to emphasize this is/should be a TEMPORARY fix only!!

Serialization not allowed in Magento?

When I turn on cache in Magento, I get the following exception:
Serialization of 'Mage_Core_Model_Layout_Element' is not allowed
Exception occurs in app/code/core/Mage/Page/Block/Template/Links.php, on line:
return parent::getCacheKeyInfo() + array(
'links' => base64_encode(serialize($links)),
'name' => $this->getNameInLayout()
)
I am using Magento Enterprise 1.10 and PHP 5.3.
Can anyone tell me what the problem is?
You shouldn't have an empty after_text or before_text tags in your layout file. If you don't need it, just delete the tag at all.
If it will not help, dump the $links variable before the 150th line in the app/code/core/Mage/Page/Block/Template/Links.php file, and you will see an array with arrays inside it. All of keys and values should be strings or integers, not objects. The key of array value which is an object will tell you which tag to delete from the layout file.
Awesome #vsushkov.
I used:
try{
serialize($links);
} catch(Exception $e){
Mage::log($links);
die;
}
to find out exact layout where we had those empty tags and after removing those empty tags, it fixed the issue and then removed above code :-)
Saw this issue on a clients site. None of the solutions above worked for me. After much googling of the error, it seems to be related to JM or JoomlArt themes/extensions.
The code is extremely poorly written. For example some of the things you will find in these themes include:
Declaring php classes inside templates,
Setting global variables inside templates,
Setting data into superglobals from templates,
Providing a translation file, yet not wrapping most text strings in template in the translate function
I found 1 response from their support staff essentially suggesting to turn off error reporting to fix the issue.
I found my problem in app/design/frontend/default/jm_adamite/template/catalog/navigation/tops.phtml
There was a line setting $this into $_SESSION. I commented it out and the error went away. Nothing else appeared broken. A grep for that variable being used anywhere else had 0 results. If you have one of these JM extensions installed or use one of their themes, I would suspect that first
Good luck
This problem happened to me when trying to serialize categories after calling the getCategoryUrl function after digging i found out that that set _urlModel object which cannot be serialized as it contains Mage_Core_Model_Layout_Element so before serializing the object check if it has that _urlModel property

Resources