Create for each hook function a file in WHMCS modules - php

In WHMCS can i use a folder for hooks inside of hooks.php in modules/addons/ like in includes/hooks?. I test it but it don't work. and i tried to find solution by creating a folder named hooks and inside this folder i create files that contain functions: Exemple :
In modules/addons/myModule/hooks/function1.php :
function function1($vars){
// .....
}
In modules/addons/myModule/hooks.php :
if (!defined("WHMCS"))
die("This file cannot be accessed directly");
foreach (glob("hooks/*.php") as $filename)
{
include($filename);
}
add_hook("ClientAreaHeadOutput", 1, "function1.php");
My solution don't work. There is any best solution for that? Thanks.

To get an addon detected put your addon folder inside modules/addons/ e.g modules/addons/mymodule and then inside your module folder have a php file with the same name modules/addons/mymodule/mymodule.php. Your functions go into this file.
You will then go to Setup > Addon Modules interface and activate it.

Related

Joomla: Is it possible to display a view of a component without iframe and plugin?

Is it possible to display a view of a component without iframe and plugin?
(That is to say, if possible with a few lines of PHP and maybe SQL queries?)
EDIT:
To be more clear: I'd like to do it directly in the PHP-Template!
(Would be fine to do it in an article as well, as I have written a
PHP-function showArticle(mixed $ident))
(I'm using Joomla 3.5)
I'd like to do something like
<jdoc:include type="component" view="example" name="position-x" />
or
<?php
show_component('component-name', 'view-name');
?>
you can use this component http://extensions.joomla.org/extension/components-anywhere
Install the plugin and enable it.
Then you can call the component this way {component url/of/the/component}
{component index.php?component=com_example&form=1}
Try to use non-sef urls in the url but sef url will still work.
There is another way to achieve this by calling the model into your controller file this way
JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_example/models', 'ExampleModel');
What this does is it searches the model class starting with ExampleModel in the folder specified. here you can eneter just a path string or array of the directories as the first parameter. Next you have to call the method inside the views file this way
$exmodel = JModelLegacy::getInstance('Something', 'ExampleModel', array('ignore_request' => true));
So here you create an instance of the class object which can be used to get the items from the model this way
$items = $exmodel->getitem();
$this->assignRef('items', $items);
next you can copy the default.php file in the tmpl folder of that component and place it anywhere you like inside your layout file. Basically instead of copying the entire component you are calling the model and getting the data which you can use in your layouts.

Include files inside modules folder in Prestashop

I have created a subfolder inside my store in Prestashop inside the /classes/ subdirectory with the name service (e.g /classes/service/).
I'm trying to include the php file of a module that I have created myself to access to its methods with the following line of code inside a class that I have created inside /classes/service/ :
include(dirname(__FILE__).'/../../modules/mymodulename/mymodulename.php')';
class A {
.
.
.
public function callmodule(){
$obj = new MyModuleName();
$obj->someMethod();
}
}
I use it in the include the /../../ to go two directories up, one to get out to the service folder and another one to get out to the root folder of the store, but the problem is that the above line is not returning anything when I call it, only gave me a blank page without errors or warning and if I delete it's works fine, but I need to access to this file.
There is a better way to access to the file without errors ?
PD : When I mean call the class A it's because I put a rule inside my .htaccess to redirect a specific call to some class like a dispatcher where the A class its called.

How to load view from alternative directory in Laravel 4

In my Laravel 4 application's root directory, I have a folder themes. Inside the themes folder, I have default and azure.
How can I access view from this themes/default folder in a specific route.
Route::get('{slug}', function($slug) {
// make view from themes/default here
});
My directory structure:
-app
--themes
---default
---azure
I need to load views from localhost/laravel/app/themes/default folder. Please explain this.
This is entirely possible with Laravel 4. What you're after is actually the view environment.
You can register namespace hints or just extra locations that the finder will cascade too. Take a look here
You'd add a location like so:
View::addLocation('/path/to/your/views');
It might be easier if you namespace them though, just in case you have conflicting file names as your path is appended to the array so it will only cascade so far until it finds an appropriate match. Namespaced views are loaded with the double colon syntax.
View::addNamespace('theme', '/path/to/themes/views');
return View::make('theme::view.name');
You can also give addNamespace an array of view paths instead of a single path.
Here I am not accessing my project from public folder. Instead of this I am accessing from project root itself.
I have seen a forum discussion about Using alternative path for views here. But I am little confused about this.The discussed solution was,
You'd add a location like,
View::addLocation('/path/to/your/views');
Then add namespace for theme,
View::addNamespace('theme', '/path/to/themes/views');
Then render it,
return View::make('theme::view.name');
What will be the value for /path/to/ ?
Can I use the same project in different operating system without changing the path?
Yes, we can do this using the following,
Put the following in app/start/global.php
View::addLocation(app('path').'/themes/default');
View::addNamespace('theme', app('path').'/themes/default');
Then call view like the default way,
return View::make('page');
This will render page.php or page.blade.php file from project_directory/app/themes/defualt folder.
I've developed a theme package for laravel 5 with features like:
Views & Asset seperation in theme folders
Theme inheritence: Extend any theme and create Theme hierarcies
Try it here: igaster/laravel-theme
\View::addLocation($directory); works fine but the new right way to do it is using loadViewsFrom($path, $namespace) (available on any service provider).

Symfony layout in another folder

Is it possibile to put layout files in the modules/templates (or something else) directory instead of the general app/templates?
I've tried to put the path in view.yml but it doesn't work.
Just found a workaround so I can keep layout.php inside the module/templates folder:
public function preExecute()
{
$template = $this->getContext()->getConfiguration()->getTemplateDir('MODULE', 'layout.php');
$this->setLayout($template . '/layout');
}

showing a module anywhere in website of codeigniter

I am pretty new to codeigniter and working on an audio cart website.
I implemented a audio playlist in my project and I created a different module called playlist. Created routes and everything working fine for the page playlist. I used HMVC codeigniter and hence i have different folders for each module.
My playlist is basically a list of songs and user can select and play any song.
Modules-
---Playlist
--Controllers
--playlist.php (my front controller)
--Models
--playlistmodel.php (model)
--Views
index.php (view for showing playlist)
Now according to new specifications, This playlist can be placed anywhere in the website. It should be working. I am not able to figure out how is this feasible ? should I need to create helpers ?
Please help .
Live Url : http://webcartz.stagetesting.com/playlist
Thanks
see this url:--
How to load a module outside modules folder on HMVC with CodeIgniter?
Well you can do this too
<?php echo Modules::run('../bar/bar/index'); ?>
Perhaps you should create a library then
When we use the term "Libraries" we are normally referring to the
classes that are located in the libraries directory and described in
the Class Reference of this user guide. In this case, however, we will
instead describe how you can create your own libraries within your
application/libraries directory in order to maintain separation
between your local resources and the global framework resources.
As an added bonus, CodeIgniter permits your libraries to extend native
classes if you simply need to add some functionality to an existing
library. Or you can even replace native libraries just by placing
identically named versions in your application/libraries folder.
http://codeigniter.com/user_guide/general/creating_libraries.html
something like this
class Playlistlib {
public function __construct($params)
{
$CI =& get_instance(); // so you'd use $CI instead of $this to ref to CI object
// Do something with $params
}
public function get_playlist($params)
{
// Do something with $params
}
}
$params = array('id' => 15, 'limit' => 5);
$this->load->library('Playlistlib', $params);

Categories