Im trying to extend the functionality of the in built hooks by adding some hooks of my own. The documentation on this is pretty scarce so Im posting it here in hopes one of you has done something similar.
I have added a MY_Hooks.php file under the application/core folder as follows
class MY_Hooks extends CI_Hooks {
public function __construct()
{
parent::__construct();
echo "<pre>";
var_dump( $this->hooks );
echo "</pre>";
//this works fine when placed right here
$this->hooks["admin_start"] = function(){
echo "Boosting";
};
// this doesnt work when i simply include the file from the theme directory
if (file_exists(APPPATH.'themes/default/hooks.php'))
{
include(APPPATH.'themes/default/hooks.php');
}
}
}
if you take a look at the comments you can see i have 1 snippet of code which works just fine.
$this->hooks["admin_start"] = function(){
echo "Boosting";
};
and then in the next snippet, I am simply trying to include the same code from a themes directory that i have set up. Which doesnt work. So im scratching my head as to why.
if (file_exists(APPPATH.'themes/default/hooks.php'))
{
include(APPPATH.'themes/default/hooks.php');
}
so its the same code just inside of an include file. Please tell me what Im missing. Thanks in advance.
Related
I'm working on a new website. This website will be a one pager. All my files I already load in through PHP into the main folder. But now I want to edit them and update them through WYSIWYG.
The UPDATE and SELECT are already working. I tested it on a page who stood on its own. All the one-pager files are stored in a folder and within the folder is also the file which loads all the files into it. I call them through a href which ends up giving the file an # in the address bar. There lies the problem. I can't access the #file with the function I wrote because that only can access files without starting a #. Is it possible to access it through my function?
I give the code if the question is too unclear because it's a bit of mess to implement all the files I use for this purpose.
Short recap: Can't access #domain with a PHP function. Is it even possible to access it.
<?php
class Home extends Controller {
protected function frontpage() {
$viewmodel = new HomeModel();
$this->returnView($viewmodel->frontpage(), true);
}
}
?>
this is the returnView from Controller:
protected function returnView($viewmodel, $fullview){
$view = 'views/'. get_class($this). '/' . $this->action. '.php';
if($fullview){
require('views/main.php');
} else {
require($view);
}
}
I'm new with overflow so I couldn't get the function into right place but with protected function frontpage I should access the file frontpage.php. Well it does do that but that's not the right directory because it's only visible throug a href which means the function should have been: protected function #frontpage which isn't possible.
This is actually not possible, as the anchor (#) isn't sent to the server and is handled by the browser itself.
The only possibility is to include some JavaScript magic to your project.
I have created a module which was downloaded from SocialEngine and uploaded there without making any changes to the source code.
The controller code:
// Controllers/IndexController.php
class Likecounter_IndexController extends Core_Controller_Action_Standard
{
public function indexAction()
{
$this->view->someVar = 'someVal';
}
}
The view code:
// views/scripts/index/index.tpl
Index for skeleton module: Likecounter
someVar : <?php echo $this->someVar; ?>
And the Bootstrap.php code:
// Root of Likecounter(module name) directory
class Likecounter_Bootstrap extends Engine_Application_Bootstrap_Abstract
{
}
BUT NOTHING OUTPUT :(
What's your guess? Why it doesn't print out anything?
Thanks
It will work on the link with /likecounter or whatever you set in manifest.php under routes.
Does your module include necessary files/folders such as /application/modules/Likecounter/settings/manifest.php? If so, can you check if your module is enabled in your package manager (it can be found on yoursite.com/install/manage)?
Next, you may place something like echo "it works"; die(); right in indexAction() of your controller. Then when you visit yoursite.com/likecounter it should show you blank white page with "it works" text.
If not, you should check the end part of the log file which is in /temporary/log/main.log. Hope this helps.
********* Updated question **************
So I have tried to implement my own AttrDef to HTMLPurifier but it doesn't "take", and I can't debug using die() either.
Here's what I have:
I created Transform.php in the HTMLPurifier/AttrDef/CSS/ directory. The only contents so far is this (I'm only trying to hook it in for now, I will add validating logics once I see that it is in the loop and thus can test it):
<?php
/**
* Validates Transform as defined by CSS.
*/
class HTMLPurifier_AttrDef_CSS_Transform extends HTMLPurifier_AttrDef
{
//basing this off of the color definition so the var is $color for now, may change it to $transform later
public function validate($color, $config, $context) {
return $color;
}
}
I added my file to library/HTMLPurifier.includes.php like this:
require 'HTMLPurifier/AttrDef/CSS/Transform.php';
and to the library/HTMLPurifier.safe-includes.php
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/Transform.php';
(not sure about the difference between these two include files above but all AttrDef files seemed to be in both so I added my file to both as well).
Then I try to make use of this new definition by adding this to library/HTMLPurifier/CSSDefinition.php:
// transform
$this->info['transform'] = new HTMLPurifier_AttrDef_CSS_Transform();
It is as if all of my additions were never made, and I can't debug it by putting a die() in my own file either, nothing happens.
So any advice on where I went wrong or how I can debug this is very much appreciated.
*********** addition *******
I also tried a simple bypass by applying the Color-AttrDef to any transform property, in the CSSDefinition.php:
$this->info['transform'] = new HTMLPurifier_AttrDef_CSS_Color();
And I hacked the original Color definition like this:
//TODO: testing ways to bypass
if (strpos($color, 'rotate(') !== false) {
return $color;
}
Not working. Please advice on what I am missing.
You'll need to define your own AttrDef which knows how to parse and validate such definitions. Color should serve as a decent model, since the rgb syntax is similar to matrix.
I am pulling all my hair off... Have been searching every thread, would appreciate if someone can point me to a working example.
Accroding to the doc: https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc
I can call another module->controller using
modules::run('module/controller/method', $params);
modules::load('module/controller/method', $params);
or
$this->load->module('module/controller');
$this->controller->method();
Problem: the "method()" is never called. only constructor of the controller is called every time.
The objective is to build self-contained MVCs as module and use by other controllers.
But no matter what I do, it only calls the constructor, method is not called.
I started using HMVC a few weeks ago, did I miss something in the doc or it is not used this way?
Here is the setup:
modules
|--ztest1
| |--controller/c1.php
|--ztest2
|--controller/c2.php
class C1 extends MX_Controller {
function __construct() {
parent::__construct();
}
function index () {
Modules::run('ztest2/c2/testc2/');
//Modules::load('ztest2/c2/testc2/');
//$this->load->module('ztest2/c2/testc2/');
//$this->c2->testc2();
}
}
class C2 extends MX_Controller {
function __construct() {
parent::__construct();
echo __FILE__." // ".__CLASS__."/".__FUNCTION__.PHP_EOL;
}
function testc2(){
echo __FILE__." // ".__CLASS__."/".__FUNCTION__.PHP_EOL;
}
}
output:
/app/modules/ztest2/controllers/c2.php // C2/__construct
additional note: no error or warning with the script. It just quietly calls the constructor.
Thanks for MC's tip, I finally figured out the cause. HMVC doc indeed lacks some examples for beginner.
For anyone who may find this thread in the future, correct usage here:
to call module01/controller01/method00:
//method 1 CORRECT:
$ctlObj = modules::load('module01/controller01/');
$ctlObj->method00();
//or you could use chaining:
modules::load('module01/controller01/')->method00();
//method 1 WRONG:
modules::load('module01/controller01/method00'); //this will only load contructor
---
//method 2 CORRECT:
modules::run('module01/controller01/method00'); //no trailing slash!
//method 2 WRONG:
modules::run('module01/controller01/method00/');
---
//method 3 CORRECT:
$this->load->module('module01/controller01');
$this->controller01->method00();
I don't understand why method 3 failed when I first try... maybe because I restarted HTTPD?
This HMVC works well for me. I'm working on a project using this HMVC now.
Just edit third_party/MX/Modules.php as shown in this link below and tell me the response.
https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/pull-request/5/return-error-messages-instead-of-logging/diff
I ran into the same issue. Make sure you check capitalization of your directories and and controllers. It's not case sensitive for differing between the module and controller name.
//In my case the below did not work
$this->load->module('dashboard/Dashboard');
$this->Dashboard->method();
//but
$this->load->module('dashboard');
$this->Dashboard->method();
//worked
After some attempts to achieve call a controller that is not located within any module.
Modules::run('../Controller/method');
I am new at CI as well, and I thought I was having the same issue. Script seemed not to be running. (no html output).
//This did NOT work (did not produce output)
modules::run('module_name/method_name',$data);
// but this DID work??? didn't know why
modules::run('module_name/method_name',$data);
exit();
// turns out you need the echo for output
echo modules::run('templates/login_template',$data);
This may be obvious to many of you- but I wasted two hours searching for an answer.
so According to the documentation they says copy the controller in default controller folder and move to modules controller.
So now how do I run the controller that has been moved to modules when I run its running from the default controller file if removed does not work so how to make it run the controller inside module as a default controller to run.
So Do I need to mention the modules name too in the route
/*echo Modules::run("controller name of a module which you want to call/and its.. function name");*/
echo Modules::run("Second/callit");
or
$this->load->module('Second');
$this->second->callit();
But.. the controller name shold be different .. from one module to another module..
**(parameter passing)**
echo "<hr>";
//echo Modules::run("controller name of a module which you want to call/and its.. function name");
$data="peter";
echo Modules::run("Second/callit",$data);
echo "<hr>";
$this->load->module('Second');
$this->second->callit($data);
echo "<hr>";
I have an on-going CI v2.0.2 app that was coded by other developers.
I started off by creating a trial controller: `controllers/trial/trial.php'. The code in this controller is:
<h1>controller</h1>
<?php
class Trial extends CI_Controller {
function index() {
echo "this works";
$this->load->view("trial/trial_view");
}
}
And the view is in views/trial/trial_view.php. The view has a simple <p>this is the view</p> line.
Now when I visit the URL - http://localhost/ci/index.php/trial/trial all I get is the <h1> tag from the controller. If I remove that tag, nothing is seen, not even the echo statement.
The code base I was given is an exact replica of the app that is being used right now. I've doubly checked to make sure the folder structure is correct too.
What should be going on here? Any config options I should look at?
Update--------
I moved trial.php into the controllers folder, and trial_view.php into the views folder. Made the appropriate changes in the code too. But the result is still the same - only the h1 tag from the controller is displayed when I visit http://localhost/ci/index.php/trial
your action is called index, while you're trying to access controller's trial action, which does not exist.
change it to,
function index() {
echo "this works";
$this->load->view("trial/trial_view");
}
try putting trial.php outside trial folder inside controller folder, and get back what happens
try changing
function index() {
echo "this works";
$this->load->view("trial/trial_view");
}
to
public function index() {
echo "this works";
$this->load->view("trial/trial_view");
}
BTW try turning on error reporting and see if error is thrown
EDIT
BTW i tested with your code with same setting. It is working in my machine
First off all, stop using the index method to do anything. If your class is called Trial, you need to do this with the index method:
public function index()
{
$this->trial();
}
Then do everything under a method called trial.