CodeIgniter 3 / Basic Hook Loading Problems - php

Hey I'm sure I miss something obvious, but can't figure out what it is :
I can't get a simple hook working with my quasi blank installation of CI 3 ...
I've put the simplest of the code possible with a Hook called MyTest and it works fine :
application/config/hooks.php
$hook['post_controller_constructor'][] = array(
'class' => 'MyTest',
'function' => 'TestMe',
'filename' => 'MyTest.php',
'filepath' => 'hooks',
'params' => ''
);
application/hooks/MyTest.php
class MyTest{
function TestMe()
{
die("die by the hook TEST");
}
}
->this outputs "die by the hook TEST", which is what is expected.
But almost the same with a Hook called URI_Actions doesn't work at all :
application/config/hooks.php
$hook['post_controller_constructor'][] = array(
'class' => 'URI_Actions',
'function' => 'index',
'filename' => 'URI_Actions.php',
'filepath' => 'hooks',
'params' => ''
);
application/hooks/URI_Actions.php
class URI_Actions{
function index()
{
die("die by the hook URI Actions");
}
}
-> this doesn't output anything ... I'm sure I'm missing something enormous, any idea ?
Epilogue
Of course the problem was elsewhere : binary FTP transfert was the issue, once the files uploaded normally the same codes worked perfectly. Thanks to trajchevska which made me realize the code was not the problem !

Does it not display anything or it displays "die by the hook TEST" only? The thing is that you have them both defined one after the other and they're both doing dump and die. So when the Test hook displays the result, the program dies and doesn't get to the URI_Actions hook.
Try using a simple var_dump instead of die, you should get the expected result. I tested both locally and they work fine.

Related

DRUPAL-7: hook declaration missing

Goodmorning everyone,
I'm new in Drupal.
I hope don't ask a stupid question.
I'm working with Drupal 7 and I need to edit a custom module for my company developed by another developer.
This is a piece of code where I use "theme" function.
This code is under "sites/all/modules/gestione_attivita_attivita/gestione_attivita_attivita.module"
function gestione_attivita_attivita_block_search_attivita($tipo_ricerca) {
$block['subject'] = "";
$ricerca = gestione_attivita_ricerca_fetchAll($tipo_ricerca);
$block['content'] = theme('ricerca_attivita', array(
'items' => $ricerca,
'tipo_ricerca' => $tipo_ricerca
));
return $block;
}
I know that should exist "ricerca_attivita" hook declared somehere in my files.
I'v been looking for something like "['ricerca_attivita'] = array(" or similar words or sub-words in all my files of my site folder but it doesn't exist.
The only thing I know is that under :"sites/all/themes/customModuleOfmyCompany/templates" there are several tpl files and in particular one called "ricerca_attivita.tpl.php" that work and receives data from theme function but I don't know how this is possible.
I don't know who tell to theme call to go on another folder on another path and use "ricerca_attivita.tpl.php" and not foo.tpl.php for example.
Is there anyone that can help me?
Another thing:
Going under includes/theme.inc and debugginng it I have this printing hook info:
array (
'template' => 'ricerca_attivita',
'path' => 'sites/all/themes/customtheme/templates',
'type' => 'theme_engine',
'theme path' => 'sites/all/themes/customtheme',
'preprocess functions' =>
array (
0 => 'template_preprocess',
1 => 'contextual_preprocess',
),
'process functions' =>
array (
0 => 'template_process',
1 => 'ctools_process',
2 => 'rdf_process',
),
)
but I don't know who is that declare it
I think you should use the developer module for themers https://www.drupal.org/project/devel_themer
And about theming function, did you search for this function inside the themes folder?
Hope that helps.

Drupal 7 Messages only show after class registry clear

Need to show some messages from hook_block_view.
so in the function setting a message like:
drupal_set_message('Block should have loaded');
Does not work.
If I clear class registry, it works once, then every other time it does not show.
It looks like drupal is redirecting or something before the page is rendered. Using drupal_exit(); by the end of this function does show everything is correct so far, but does not make it to the final output.
Edit:
It works if I throw in drupal_flush_all_caches But then goes super slow obviously. Seems to be some sort of caching problem.
Turn off full caching for the block under hook_block_info() by setting 'cache' to: DRUPAL_NO_CACHE
function hook_block_info() {
$blocks = array();
$blocks['abc'] = array(
'info' => t('test block'),
'visibility' => 0,
'status' => TRUE,
'region' => 'none',
'weight' => 99,
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
Then try to write
drupal_set_message('Block should have loaded');
within hook_block_view and check now...
it may be help for you.

Extending page table with field using itemsProcFunc in TYPO3 6.2

I'm trying to extend the 'page' properties form by extending the page db table and TCA array from within an extension. This works, except that my custom function won't be called. If I replace my own itemsProcFunc line with a TYPO3 core function itemsProcFunc line it works, but with my own function it never works (I just get an empty result/selectlist, even when I simply return a dummy array: "return array('title','1');"....
Here's my code in my extension's ext_tables.php:
<?php
$TCA['pages']['columns'] += array(
'targetelement' => array(
'exclude' => 0,
'label' => 'Target element (first select a target page!)',
'config' => array (
'type' => 'select',
'items' => Array (
Array('',0),
),
'size' => 1,
'minitems' => 1,
'maxitems' => 1,
//'itemsProcFunc' => 'TYPO3\CMS\Backend\View\BackendLayoutView->addBackendLayoutItems',
'itemsProcFunc' => 'Vendor\Myextension\Controller\Hooks\CustomTargetElementSelector->getContentElements',
),
)
);
t3lib_extMgm::addToAllTCAtypes('pages', 'targetelement,', '2', 'after:nav_title');
t3lib_extMgm::addToAllTCAtypes('pages', 'targetelement', '1,5,4,199,254', 'after:title');
P.s. I replace Vendor\Myextension for my own namespace of course.
I don't know where to put my function file exactly, I assume in extension\Classes\Controllers\Hooks\CustomTargetElementSelector.php.
My ultimate goal is to display a list of content elements of the selected shortcut page UID..
P.s.2 my CustomTargetElementSelect.php file looks like this (contents just return a single item, dummy list result:
<?php
namespace Vendor\Myextension\Controller;
class CustomTargetElementsSelector extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
public function getContentElements(array &$params,$pObj){
return array('title','uid');
}
}
First of all, an itemsProcFunc should be a simple class; I never tested if an Extbase controller context is available in an itemsProcFunc.
Your hook should (this is just a recommendation) reside in
yourext/Classes/Hook/CustomTargetElementSelector.php
Namespace:
namespace Vendor\Yourext\Hook;
class CustomTargetElementSelector {
[method inside]
}
After flushing the system cache, if the hook still has no function, set a die() statement within the function to find out if the function is called at all. Currently it cannot work because the location of your class (Controllers/Hooks) and the namespace (Controller) don't fit.
For the sake of full 6.2/7 compatibility, replace
t3lib_extMgm::
by
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::

Yii don't understand how to log a message

I followed this tutorial but still I go to the webpage refresh, then go to the file and still I can't find the log message I sent
I wrote the following line in a controller:
Yii::log("Index Checkout",CLogger::LEVEL_ERROR);
And My configurations:
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
array(
'logFile'=>'trace.log',
'class' => 'CFileLogRoute',
'levels' => 'error,info, warning',
),
// uncomment the following to show log messages on web pages
/*
array(
'class'=>'CWebLogRoute',
),
*/
),
Right way to write to log is:
Yii::log($message, $level, $category);
But point is that $category should not be empty.
Example above works becouse message is written in category then category is not empty, but it writes empty message. It writes category so it looks like message.. but it isn't.
I was in a similar trouble with YII logger. Strange but I was kind of messing with parameter order.
This works for me:
<?php
Yii::log('', CLogger::LEVEL_ERROR, 'Message Here...');

Fatal Error when loading Catalog-settings in backend

On a fresh 1.5.0.1 Magento install when choosing Catalog from the settings->settings menu I get the following error:
Fatal error: Undefined class constant 'RANGE_CALCULATION_AUTO' in
/my-install-dir/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Price/Step.php on line 33
Checked Step.php and it does not look damaged and contains the following:
class Mage_Adminhtml_Model_System_Config_Source_Price_Step
{
public function toOptionArray()
{
return array(
array(
'value' => Mage_Catalog_Model_Layer_Filter_Price::RANGE_CALCULATION_AUTO,
'label' => Mage::helper('adminhtml')->__('Automatic')
),
array(
'value' => Mage_Catalog_Model_Layer_Filter_Price::RANGE_CALCULATION_MANUAL,
'label' => Mage::helper('adminhtml')->__('Manual')
),
);
}
}`
Anyone know this error or how to fix it?
PHP is complaining that it can't find the constant on RANGE_CALCULATION_AUTO defined on the class Mage_Catalog_Model_Layer_Filter_Price
Based on your comments above, it sounds like you already checked the file at
app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php
to ensure is had the correct constant defined.
const RANGE_CALCULATION_AUTO = 'auto';
Based on that, my guess would be there's a different Price.php being loaded for this class. This can happen if
Someone's placed a different version in community or local
Someone's monkied with the include path beyond Magento's normal monkey business
Check for files at
app/community/core/Mage/Catalog/Model/Layer/Filter/Price.php
app/local/core/Mage/Catalog/Model/Layer/Filter/Price.php
If that doesn't work, add some temporary debugging code to
app/code/core/Mage/Adminhtml/Model/System/Config/Source/Price/Step.php
that uses reflection to figure out what file PHP is loading the class from
class Mage_Adminhtml_Model_System_Config_Source_Price_Step
{
public function toOptionArray()
{
//NEW LINES HERE
$r = new ReflectionClass('Mage_Catalog_Model_Layer_Filter_Price');
var_dump($r->getFileName());
//echo $r->getFileName(); // if too long for var_dump
exit("Bailing at line ".__LINE__." in ".__FILE__);
//END NEW LINES
return array(
array(
'value' => Mage_Catalog_Model_Layer_Filter_Price::RANGE_CALCULATION_AUTO,
'label' => Mage::helper('adminhtml')->__('Automatic')
),
array(
'value' => Mage_Catalog_Model_Layer_Filter_Price::RANGE_CALCULATION_MANUAL,
'label' => Mage::helper('adminhtml')->__('Manual')
),
);
}
}`
This will dump out a file path that points to the exact place PHP is loading the class from, which should get you where you need to go.

Categories