Is there a way to get the current object and method with CodeIgniter? - codeigniter

I'm looking for a function that would tell me the current object and method by way of the URI. Normally, I would use $this->uri->uri_string(), however, I do not want to pass any "dynamic" segments. For example, a URI of 'products/shoes/123', would be 'products/view_product'.
I want to be able to do this so I can create a config file containing page titles... since I use a model to output my page header. It is called from MY_Controller.php in the construct. For example: $this->template->overall_header($title = "View Product")...
but in the construct, it would be:
$this->template->overall_header($title = $this->config->item($object_method_string));
Anybody have any solutions? Thanks for your time.

for current method
$method= $this->router->fetch_method();
I hope you are talking about this

To expand on Nishant's answer you can access the attributes from the router class.
So for current object;
$this->router->class
And for current method;
$this->router->method

Related

Xamarin.Forms Shell: Passing objects from one vm to another

I see how to pass data in the form of strings from one object to another
What I want to do, however, is pass an object from one vm to another -- is this possible? I can think of these ideas:
Stream the object as json and pass that as a param.
Use an id to look up and create the object
in the receiving vm
Pass the object itself (ideal)
Will any of these work (well, #2 almost certainly will)? If 1 or 3 will work, can you possibly supply (detailed?) instructions on how to do so?
Thanks!!
jesse liberty
Add an parameter in your page constructor like:
public class MyPage : ContentPage
{
public MyPage(Object sth)
{..... }}
Then pass the object with
Navigation.PushAsync(new MyPage(sth));
Put the following at the top of the page that will be receiving the data
[QueryProperty(nameof(CodesToAdd), nameof(CodesToAdd))]
Create a corresponding property (in this case CodesToAdd)
In the setter for that property getg the string value passed to you
_codesToAdd = Uri.UnescapeDataString(value ?? string.Empty);
To send the data (in this case the codes to add) put this in the calling program:
await Shell.Current.GoToAsync($"{nameof(AddWidgetPage)}?CodesToAdd={codesToAddAsString}");
The first part in the parens identifies the page you want to navigate to. The part after the ? is the parameter. Make sure your param name (CodesToAdd) matches the one in your receiving page.

Smarty getting page content

I need to edit a page on prestashop, I've found that code
<ul id="idTab2" class="bullet">{$agencies->content}</ul>
And where should i search for that $agencies variable ?
I have found the text which is being displayed into that place in CMS.
However I'd that variable need to be define somewhere, am I right ? Anyone knows where should i search for that ? I'm new to prestashop.
Why am i asking for this ? I need to add another page for example
<ul id="idTab2" class="bullet">{$test->content}</ul>
- but I can't just simply add another page called test.
The {$agencies} variable is being set in a object derived from either the Controller or Module classes but to be honest it looks like you're working with code that has been customised (via a class override or a module) making it impossible to provide a definitive answer to your question without knowing more detail.
If you can locate the term 'agencies' in a file located under \controllers, \modules or \override in your installation, then you will be closer to finding your answer. It will be contained in a function call similar to:
$this->context->smarty->assign('agencies' , [some-variable]);
Note that the parameters to the function may also be passed as an array for multiple assignments.

Magento Override Existing Source Model

I want to add one more option in Mage_CatalogInventory_Model_Source_Backorders.How do I override this source model?
Is overriding similar to Entity model override?
Correct. The xpath is global/models/cataloginventory/rewrite/source_backorders. Depending on your sorting needs/preference, simply array_merge(), array_unshift(), or array_splice() your option where it needs to go in the overridden toOptionArray() method.
just try to put same folder in your local folder like this
magentodemo\app\code\local\Mage\CatalogInventory\Model\Source\Backorders.php and now write the code you want to add in Backorders.php and then check it out.

Extend a Varien Form Element for a Custom Module

Improving on this question:
Is it good practice to add own file in lib/Varien/Data/Form/Element folder
The accepted answer shows how to extend a Varien form element, but this will not work if you want to package it into a custom module.
What would be the proper method of extending the Varien form element in a module? A simple XML setting I'm hoping?
Update:
Thanks Vinai for the response. Although that does work, I was hoping to extend the form element somehow. My extension is using the base File form element to allow administrators to upload files to categories. So, I'm not directly adding the form elements to the fieldset myself.
I suppose it's possible to to check for the file input on my category block on the backend: Mage_Adminhtml_Block_Catalog_Category_Tab_Attributes , and then change the form element if it is 'file' to 'mycompany_file' -- but this seems like a workaround.
Is there an easier way? Thanks again Vinai.
On the Varien_Data_Form instance you can specify custom element types like this:
$fieldset->addType('custom', 'Your_Module_Model_Form_Element_Custom');
Then, add your element with
$fieldset->addField('the_name', 'custom', $optionsArray);
If you are using a form without fieldsets you can do the same on the Varien_Data_Forminstance, too.
EDIT: Expand answer because of new additional details in the question.
In the class Mage_Adminhtml_Block_Widget_Form::_setFieldset() there is the following code:
$rendererClass = $attribute->getFrontend()->getInputRendererClass();
if (!empty($rendererClass)) {
$fieldType = $inputType . '_' . $attribute->getAttributeCode();
$fieldset->addType($fieldType, $rendererClass);
}
Because of this the attribute frontend_input_renderer on the attributes can be used to specify custom element classes.
This property can be found in the table catalog_eav_attribute, and luckily enough it isn't set for any of the category image attributes.
Given this, there are several ways to apply customizaton.
One option is to simply set the element class in the table using an upgrade script.
Another would be using an observer for the eav_entity_attribute_load_after event and setting the input renderer on the fly if the entity_type_id and the input type matches.
So it is a little more involved then just regular class rewrites in Magento, but it is quite possible.
You don't necessarily need to have a file in the lib/Varien/ directory in order to extend it. If you needed to add an element to that collection, you should be able to extend one of the Elements in your app/code/local module. The answer to the question you referenced seems to also indicate this is the case. I would create your custom field, extending its highest-level function set (i.e., lib/Varien/Data/Form/Element/File.php).
If you want to override the Mage_Adminhtml_Block_Catalog_Category_Tab_Attributes block, then you should extend that block in your module and then reference the new one. You may wish to extend the block using an event observer rather than an XML rewrite, for compatibility purposes.

get magento module config data in Observer

I created a module with an observer for the sales module with event hook ‘sales_order_shipment_save_after’ ,
My module has the following files
Company/Modulename/etc/config.xml
Company/Modulename/etc/system.xml
Company/Modulename/Model/Observer.php
there are four fields in the modules admin configuration fields
I want to get those saved data in the Observer class.
using $this->getConfigData(’password’); gives a
Call to undefined method
error
Any suggestions?
Magento uses a static method on the global Mage application object to get configuration values
$config = Mage::getStoreConfig('section_name/group/field'); //value
$config = Mage::getStoreConfig('section_name/group'); //array
An amendment to Alan's completely correct answer.
Along with path as first parameter, getStoreConfig also accepts storeid as second parameter(optional).
Well, this is useful when you want to retrieve store-wise values.
Alan has mentioned this point in his own tutorial. I guess, he has not mentioned here just because OP has not mentioned this requirement in his question.
Please refer this
In a shipment module I can use $this->getConfigData for fields in system.xml, but in another kind of modules sometimes not, e.g. extends Mage_Core_Model_Abstract, than I must use getStoreConfig. So the answer is you don't have to use always getStoreConfig. But I don't know why ...
Answer: getConfigData is just defined in a shipment class and uses getStoreConfig too. A little confusing that some functions are extra defined and unneeded in fact ...

Resources