TYPO3 add and implement action for news extension - php

In my Configuration\TCA\Overrides\tx_news_domain_model.php I add option to select field like this:
$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['switchableControllerActions']['newItems']['News->gallery'] = 'Gallery view';
In my ext_localconf.php
$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['classes']['Controller/NewsController'][] = 'news_extender';
In my extension
namespace Vendor\NewsExtender\Controller\NewsController;
class NewsController extends \GeorgRinger\News\Controller\NewsContoller {
public function galleryAction()
{
...
}
}
I get an error: An action "galleryAction" does not exist in controller "GeorgRinger\News\Controller\NewsController" So my guess is no override of actual NewsController happens.
My question is if it is possible to add new action to the controller the way I do (['Controller/NewsController'][])? If not, can I achieve this other way? If so provide an example.

The first code must go into a ext_localconf file. Please upload full code to eg github.com to take a look as in general it looks good

I don't know what exactly i did to fix it, but as i did my research i found out that my path to controller was wrong, after changing it i spend few more hours clearing cache from BE and reinstalling extension with no result. After adding line function listAction() {} to my NewsController i finally got an error
Fatal error: Cannot redeclare GeorgRinger\News\Controller\NewsController::listAction() in D:\live_system\typo3\typo3_src\typo3temp\Cache\Code\news\tx_news_controller_newscontroller.php on line 618. After clearing Typo3temp/Cache manually again and removing listActionfrom my controller all works just fine.

Related

Error when loading library even library loaded

I'm now updating my company's old CI2 Website to CI3. Model, Controller and View from the CI2 seem to work fine after a little bit changes but my app keep showing "Fatal error: Class 'CI_Func' not found in pathtoapp\system\core\Common.php on line 196" when load library, the "Func.php" with "F" is capitalization, it's location is in "pathtoapp\application\libraries" and just echo "Hello world" for testing purpose. The text "Hello world" showing up but the app still showing the error. I've tried many other libraries but it just showing the same kind of error like "Fatal error: Class 'CI_Someotherlibrary'...". My system is running using IIS, PHP 5.5 and MySQL.
Here is my Func.php and my controller
defined('BASEPATH') OR exit('No direct script access allowed');
class Func {
function __construct()
{
echo 'Hello world';
}
}
class Home extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->library('form_validation');
$this->load->helper(array('url', 'form', 'download', 'text', 'views'));
$this->load->library('pagination');
$this->load->Model("Menus");
$this->load->Model("2019/News","News");
$this->load->library('Func');
}}
I don't know why it keep adding "CI_" before my library name. I'm still new with CI and new to stackoverflow too. I've already search over internet and try almost everything but still no luck. Any advice will be appreciated. Thanks in advance.
PS: Sorry for my bad English.
update infomation from #Bira quest
- When i change the name of class to CI_Func or $this->load->library('func');, the new error coming up: "An Error Was Encountered Unable to load the requested class: Func"
Update 1:
Here is two threads that nearly like my issue but can't solve my problem
Thread 1
Thread 2
Update 2:
- I figured it out that when i'm not using $this->load->view in my Views, the error disappear. May be the cause is $this->load->view trigger something that make loader class went wrong. I just don't know what wrong with it because i'm using $this->load->view to load some part of my website layout and it worked fine with CI2. Someone help me, please.
Update 3:
- I've solved it. In my view, i create new instance of the controller using like $home = new home(); so may be it load the library again and cause the error. Thank you all for your helps.
I've solved it. In my view, i create new instance of the controller using like $home = new home(); so may be it load the library again and cause the error. It's hard to trace the error. Thank you all for your helps.

Laravel cannot find a Controller Method (does not exist)

I'm trying to implement a new method in a BoController called "deleteBooking", the method is defined:
public function deleteBooking($id){
$booking = Reservation::find($id);
if($booking && $booking->delete()){
try {
$email = Mail::to($booking->user_email)->send(new Cancel($booking));
} catch(\Exception $e){
Log::error($e->getMessage());
}
return redirect('admin/manager/home')->with('message','Réservation annulée!');
}
return redirect('admin/manager/home')->with('message','Réservation non annulée!');
}
But laravel at the endpoint says:
(1/1) BadMethodCallException
Method [deleteBooking] does not exist.
Other methods from the same class are linked to endpoints too, and work well.
Do you have any ideas please? Thank you.
I got it fixed, I've found another file called BoController, in another folder somehow and it was conflicting with the App\Http\Controllers one.
Thank you.
It's most likely that you have declared that function for some other request type other than the one you're trying to make. For example you put Route::post('some-method', 'BoController#deleteBooking'); but you need to put either Route::get(...) or Route::put(...) or Route::delete(...).
If it isn't that problem, then you probably misspelled it.
I have faced similar issue. Then I have figured out a issue pointed in composer install log, with following instance of log line:
Class App\Http\Controllers\BlogController located in ./app/Http/Controllers/BlogControllerOld.php does not comply with psr-4 autoloading standard. Skipping.
Based on that I have found that one of the file renamed with Old suffix was creating conflict with the main file. So here I have to chhoseone of the following solutions:
To delete the file created for backup.
Or just rename the class in duplicated file to BlogControllerOld.
So its a good idea to check for issues with composer install
It will highlight the conflicts that can be fixed using one of the method above.
Once fixed using specified methods above issue composer install to apply the fix and regenerate autoloader.

codeigniter+HMVC cross module call controller->method

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>";

Joomla: Call helper function from within a model?

I'm starting off with both php and Joomla development, and finding it difficult working within Joomla to do some fairly simple stuff. Went through the Joomla MVC example and Lynda (and have built a few simple views so far).
I have a helper file/class/function that outputs all the userids that exist in the "completed" table so I can display a link for either a new record based on that user or edit an existing user's record.
I've already used a different function in this helper file successfully in a different part of the component ( Joomla: Write and call a helper function in a component ).
When I do the same thing in the model, I'm getting this: "Fatal error: Call to protected method JModel::_createFileName() from context 'JView' in C:\wamp\www\ilplocal\libraries\joomla\application\component\view.php on line 773". When I try it in the view, works fine - but I need the output in the model.
Code:
lookups.php
abstract class LookupHelper {
public function other_functions($vars){
...
}
public function completions_exist() {
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->SELECT(' #__completed.completed_userid as UserID');
$query->FROM (' #__completed');
$query->GROUPBY (' #__completed.completed_userid ');
$db->setQuery($query);
$result = $db->loadResultArray(0);
return $result;
}
}
In the model:
$completions_exist = Jview::loadHelper('lookups');
$completions_exist = LookupHelper::completions_exist();
This line is throwing the error: $completions_exist = Jview::loadHelper('lookups');
I've found some really vague references to something called JLoader::register to pull in helper functions but can't find any good documentation on that in Joomla except for everyone saying to just use that. SO I tried using it like so:
JLoader::register('LookupHelper', dirname( JPATH_COMPONENT_ADMINISTRATOR).DS.'helpers'.DS.'lookups.php');
$completions_exist = LookupHelper::completions_exist();
which throws this error: "Fatal error: Class 'LookupHelper' not found in C:\wamp\path\to\model\not\to\lookups.php. Tried manipulating the JLoader::register(everything here) and it doesn't effect the path of the error message.
Thoughts? Why does it work in a view and not in the model? How do I use the helper functions within a model?
Thanks!
#####EDIT
Thanks to #cppl looks like it's a path issue with the second bit of code. Also I read that the .DS. notation will be phased out in future versions - so the code that's working is:
JLoader::register('LookupHelper', JPATH_COMPONENT_ADMINISTRATOR.'/helpers/lookups.php');
$completions_exist = LookupHelper::completions_exist();
Lets break this down:
In Joomla! your components helper file should be in `/mycomponent/helpers/lookup.php'
JLoader:: is the Joomla! way to do it, but you could just as easily use PHP's require_once eg. require_once JPATH_COMPONENT_ADMINISTRATOR.'/helpers/myfunctions.php';
Is your path right? - you're providing dirname(JPATH_COMPONENT_ADMINISTRATOR).DS.'helpers'.DS.'lookups.php' but you've wrapped the path to your component in dirname which will the parent element of the path only. So JLoader is looking in /administrator/helpers/lookups.php.
JPATH_COMPONENT_ADMINISTRATOR is initialised as part of Joomla!'s renderComponent() call in it's JComponentHelper class if you apply dirname to it when it's not setup you will get back a dot (ie. current directory) so in the model you could would be passing ./helpers/lookups.php to the JLoader call.
You can call helper within model by following method:
JLoader::import('helpers.events', JPATH_COMPONENT);
this will include the file helpers/events.php from the component directory.
$_helper = new EventsHelper();
echo $_helper->getAnyInsideMethod();exit;

CodeIgniter: Can't Get My New Controller/View To Show

I am learning how to use codeIgniter as my php framework. I am reading through the documentation and watching the intro video and just generally following along with the first tutorial, but it's not working for me.
I have created a controller called "test.php" and a view called "test_view". The controller for this class is exactly like "welcome.php" and the view file just has some static html. However, when I go to index.php/test I get a 404 error.
I have also tried manipulating the original welcome files so that instead of calling a view it just echos "testing", yet I still see the original welcome message! I've tried clearing my browsing cash and refreshing, but to no avail.
Any suggestions? Thanks.
Edit: Here's the code for controllers/test.php
<?php
class Test extends Controller {
//Just trying to get it to echo test
public function index()
{
echo "test";
//$this->load->view('test_view');
}
}
?>
Try looking at this page in the documentation - this might solve your problem.
This basically means you should try typing index.php?/test/ instead (notice the question-mark).
First of all, check the above link. Might be useful.
If not, then...
Try changing the default controller in the config file ('routes.php') to something else (probably, to 'test'), then try loading index.php. Just to test whether the whole system works (or not).
Check whether mod_rewrite is loaded (in your server .conf-file, if you're using Apache).
Try using the latest build of the framework. AFAIK, the name of the controller class for now is "CI_Controller".
Finally, try removing the word 'public' before the declaration of the function. AFAIR, CI enable you to make private functions in controllers just by using prefix (which is set in the config file) at the beginning of the name of the function (thus making all the other functions public).
But most certainly the problem is with the mod_rewrite. If not, try debugging with die('Page found'); instead of echo - this will allow you to track possible redirects on the page.

Categories