I have two custom components that reference an external database. In component1 I set the parameters necessary to connect to that external DB.
Is there I way that I can use the parameter set in component1 within component2?
my code within my model in component2:
$app = JFactory::getApplication();
$params = $app->getParams('com_component1');
advises me of a fatal error:
Fatal error: Call to undefined method JApplicationAdministrator::getParams() in /var/www....
Should I just stop being lazy and redefine the same parameters in component2, or is there a reasonable solution?
Try using the following code.
$params = JComponentHelper::getParams('com_component1');
$test = $params->get('param_name');
To get parameters, you need to use JComponentHelper, not JFactory.
Related
In Codeigniter 3 is possible to get current active class and method with this code:
$active_controller = $this->router->fetch_class();
$active_function = $this->router->fetch_method();
Are there such functions in Codeigniter 4?
In CodeIgniter 4
$router = service('router');
$controller = $router->controllerName();
$router = service('router');
$method = $router->methodName();
Its worth saying those classes were never officially part of CI3 (https://codeigniter.com/user_guide/installation/upgrade_300.html?highlight=fetch_class). Bearing in mind CI4 is a lot more flexible and that routes are defined more variably I would look at the routing side of things and extract it from there (https://codeigniter4.github.io/userguide/incoming/incomingrequest.html#the-request-url).
You can use PHP constant or functions that provide you the same:
Get Current Function name:
__FUNCTION__
Get Current Class name:
__CLASS__
OR
get_class()
Codeigniter 4: All the above is working well otherwise use the same code that #mathan answered:
$router = service('router');
echo $router->controllerName();
Fatal error: Call to Undefined method CI_Session::get_userdata()
in/application/xamp/htdocs/application/models/articles_model.phI
I face a this error; how do I resolve this?
Its not correct method to get session data in code igniter.
To assign vale to session use
$this->session->set_userdata('name',$value);
To fetch value of session use
echo $this->session->userdata('name');
To pass an array
$temp = array('name'=>'John Doe','login'=>1);
$this->session->set_userdata('details',$temp);
To get array session data
print_r($this->session->userdata('details'));
$details = $this->session->userdata('details');
echo $details['name'];
Fatal error: Call to Undefined method CI_Session::get_userdata()
get_userdata() change into userdata()
Because it's the userdata() built-in session function in Codeigniter.
You can't change this
I am using rtconner/laravel-tagging package to get tags functionality to my app.
I can count attached tags by $o->tags->count()
I can loop the tags by a foreach: #foreach($o->tags as $t).
print attached tags by
the problem
Now I want to get a collection of random 10 Quotation with no tags attached.
While I can print a random 10 pieces with a given attribute:
$object = Quotation::where('deepness', null)->get()->random(10);
(Note: I have a random scope defined in the model, irrelevant for my issue)
... but this code, cloned from another model doesn't work:
$object = Quotation::whereHas('tags','>',0)->get()->random(10);
It produces this error message:
FatalThrowableError in Builder.php line 880:
Type error: Argument 2 passed to Illuminate\Database\Eloquent\Builder::whereHas() must be an instance of Closure, string given
I have also tried to execute this query
$object = Quotation::has('tags')->get()->random(10);
but I got this:
```
BadMethodCallException in Builder.php line 2431:
Call to undefined method Illuminate\Database\Query\Builder::tags()
```
Note 2: In the source model (the one I cloned from) the relation was counting a hasMany relation.
to do
Please help me to create the collection of Quotations with no tags assigned
Had the same problem and solved it this way:
$objects = Quotation::all();
$objects = $objects->filter(
function ($object, $key) {
return $object->tags->count() > 0;
}
)->random(10);
Hope issues still relevant :)
I'm building a custom component and I just want to get a value from the global config in my controller. I can't find any information about how to do this.
Something like...
$config = JFactory::getConfig();
$this->_db = $config->get('db');
The documentation on how to do it is slightly outdated:
http://docs.joomla.org/JFactory/getConfig
But if you check the code they actually drop the ampersand function:
https://github.com/joomla/joomla-cms/blob/staging/components/com_users/models/registration.php
$config = JFactory::getConfig();
$fromname = $config->get('fromname');
Also if you are trying to connect to the database you really can just use the DB object from JFactory.
$db = JFactory::getDbo();
Learn more about properly connecting to the database here:
http://docs.joomla.org/Accessing_the_database_using_JDatabase
Since Joomla 3.2:
JFactory::getApplication()->get($varname, $default);
See the reference
I have added this:
echo $this->getLayout()->createBlock('core/template')->setTemplate('sales/order/history.phtml')->toHtml();
to mypage.phtml, but it is giving
Fatal error: Call to a member function getSize() on a non-object in C:\xampp\htdocs\puckerimages_cvs\app\design\frontend\default\pucker\template\sales\order\history.phtml on line 41
Can anybody tell me how to call core module controller in custom pages
I dont know exactly what you were tried to do..Controller is nothing but your url segment.
If you want get controller from Url use the following code,
Mage::app()->getRequest()->getControllerName();
Mage::app()->getRequest()->getActionName();
Mage::app()->getRequest()->getRouteName();
Mage::app()->getRequest()->getModuleName();
If you want get collection of data from your Module use the following code,
Mage::getModel('groupname/classname');
or
Mage::getSingleton('groupname/classname');
Example
$collection = Mage::getModel('module/model_name')->getCollection()
->addAttributeToSort('order', 'ASC')
->addAttributeToSort('last_name', 'ASC')
->addAttributeToSort('first_name', 'ASC')
;
try this
instead of "core/template" use "sales/order_history"
<?php echo $this->getLayout()->createBlock('sales/order_history')->setTemplate('sales/order/history.phtml')->toHtml();?>
hope this help you