Magento - create a helper class - magento

I'm having trouble figuring out how to create a helper class with a function in it that's available to *.phtml files.
Can someone describe step by step how I can make the function prtHelloWorld() available to all my *.phtml files?

it's rather simple and you have to call your helper from template like this:
Mage::helper('yourmodule/yourclassfile')->prtHelloWorld();
Default helper class is Data and this defaults to Yourmodule/Helper/Data.php
Mage::helper('yourmodule')->prtHelloWorld();

To add to Anton S's, if you want to be able to access the helper's function using $this->prtHelloWorld() in the phtml instead, add it to your Block like this:
public function prtHelloWorld() {
return Mage::helper(whatever)->prtHelloWorld();
}

Related

Trying to understand the view method and general method calling in laravel

I am a new to laravel and trying to understand where the view method comes from and what mechanism allows it to be shown in the web.php folder in laravel.
For example :
Route::get('/', function () { return view('welcome'); })
I guess the view function is defined in some class. Bu which class is it and where is that class made reference to in order to access its method?
Thanks a lot if you can help me understanding this!
In most IDEs you can hold CTRL and left-click the function to view it's definition. view() is not defined in a class. It comes from a file called helpers.php.
This file is included at the beginning, so its functions can be used afterwards.
PHP is not only object oriented. Procedural and object oriented programming can be mixed together.
What I do usually in these cases is to search in the whole project (and remember to include vendor directory in your search) for: "function YOUR_FUNCTION_NAME" because somewhere in PHP there must be that function declared, whether is in a class or in a simple .php file.
view() method is a helper method inside src/Illuminate/Foundation/helpers.php. All the methods that declare here will be available everywhere inside Laravel application. You can check view() method here

What is the difference of using URL::asset() and asset()?

I'm learning Laravel and want to understand it better. What is the difference of using URL::asset() and asset()?
Also what are the parts in front of the :: called?
Both of the functions are, the same. asset() is simply a helper function. Specifically, helpers are more appropriate for views. It's a preference thing.
The part before the :: is the class you are calling.
Generate a URL for an asset:
asset('img/photo.jpg');
Does the same as
URL::asset('img/photo.jpg');
Here you can read more about it: Laravel helpers
Actually asset() is a helper function which calls asset() method from the URL class, you can find that helper file (helpers.php) inside vendor/laravel/framework/src/Illuminate/Support folder and the function looks something like this (Version-4.2):
function asset($path, $secure = null)
{
return app('url')->asset($path, $secure);
}
There are other helper functions available in this file and those functions are very useful to use as shortcut ((less typing)) but behind the scene, when you call any helper function Laravel will call the original method from the class. You may also check the online documentation about helper functions.

How do I extend default joomla class / function?

I want to extend the submit file function in Joomla in an extension I'm making to custom handle files, how do I do that? Can I get some code samples please.
I've been told to extend them in the Model, but whenever I try to extend anything I get an error, even if I have an empty function that just says "..extends xxxx{}.
see below url and read :-
http://docs.joomla.org/How_Joomla_pieces_work_together
Or
class <name>Controller extends JController
{
}

Magento - Review helper

I'm trying to instantiate the review helper class but failing..
I need to access getReviewsSummaryHtml() of class Mage_Review_Block_Product_View (app/code/code/Mage/Review/Block/Product/View.php).
I've tried this:
Mage::helper('review/product')->getReviewsSummaryHtml($_product, false, true);
But I receive Fatal error: Class 'Mage_Review_Helper_Product' not found.
What am I doing wrong?
(p.s. I can't use $this->getReviewsSummaryHtml as $this is out of scope.)
Thanks
The method getReviewsSummaryHtml() is defined in Mage_Review_Block_Product_View. You can instantiate it anywhere using Mage::app()->getLayout()->createBlock('review/product_view',$product);. In order for this to work, though, you'll need to also have a block instance named product_review_list.count, which is normally defined in review.xml, is of type core/template, and uses the review/product/view/count.phtml template.
You should simply do :
Mage::helper('review')
in order to get helper class which is named as Data.php
The function getReviewsSummaryHtml() resides in a block and you should only be able to call that function (ideally) from you template.
If you have moved that function to helper than you can call it like :
Mage::helper('review')->getReviewsSummaryHtml();
and you should do all these changes in your local.

How to access function from every controller in codeigniter

Hi friends hi have this function in one controller , how can i access it from every other controller ?pls help
public function click_add($ads_id){
//some statement here
redirect($ads_site['url']);
}
There are a few possibilities:
Define a helper
Create a parent controller class from which all other controllers in your application extend
Create a library
Use ModularExtensions to allow calling one controller inside another
It all depends on what exactly the function should do. If it shouldn't access the model, then you could go for the first three options. Otherwise I'd suggest the latter two.
One solution would be to create your own library.

Resources