Error when loading library even library loaded - php

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.

Related

TYPO3 add and implement action for news extension

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.

Ion auth Codeigniter Login throwing errors after logging in

This is my first project using both Codeigniter and Ion Auth and I've finished this tutorial: http://www.rappasoft.com/tutorials/view/5#.U1bJLeZdWpo
But now that I've reached the end, I have an error that is appearing when all of my code looks identical to the tutorial. The error is:
Message: Creating default object from empty value
Filename: core/MY_Controller.php
Line Number: 13
But the odd thing is that the code from the MY_Controller file is copied right from the tutorial. Here's the code I have:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller {
public function __construct() {
parent::__construct();
if (!$this->ion_auth->is_admin()) {
redirect('auth/login');
} else {
//Store user in $data
$data->user_info = $this->ion_auth->user()->row();
//Load $the_user in all views
$this->load->vars($data);
}
}
}
?>
The correct view loads underneath the error but obviously I'd like to know what's wrong. Since this is my first turn time working with ion-auth and I'm relatively new to code igniter as well, I was wondering if anyone knew how to go about debugging an error like this. Teach a man to fish, feed him for a lifetime! I'd really appreciate not just solutions but methods so I can learn and do this on my own.
Are you working on PHP 5.4+ ?
In that case, you must declare $data before using it:
Change:
$data->user_info = $this->ion_auth->user()->row();
to
$data = new stdClass();
$data->user_info = $this->ion_auth->user()->row();
and try again. Hpe it helps!
I think I might have figured it out. I think the issue might be that the default login information (the ones provided by ion auth) do not have any additional information in the database. This means that when the $data variable goes to set the additional account information, it doesn't find anything. It's not a strong enough error to crash the page but it is warning me that there is no other account information available even though it is supposed to be looking for more info.
So how to fix this? Create a user for testing purposes with a full compliment of account information and see if that solves the problem. The only problem is that I don't know how to add new users using ion auth and my views aren't sophisticated enough yet to make that process easy.
I've looked at the create_user() method in the auth.php file but when you press submit after filling out the form, it kicks you back to the same page with all the info. I have a feeling an edit needs to be done here although I don't quite know what to change. I've been looking on the ion auth documentation but it seems a bit... sparse. I think I'm on the right track although I'd really like to hear if someone else has a better explanation or solution. As of now, I haven't actually fixed it yet. Just deduction.

Call to undefined method ActiveRecord\Config::initialise() composer

Hey everyone I'm following a tutorial on Composer, I've installed ActiveRecord and I'm trying to create a database model. Whenever I load the page though I get this error: Call to undefined method ActiveRecord\Config::initialise()
Here's my setup file in index.php
require_once "vendor/php-activerecord/php-activerecord/ActiveRecord.php";
ActiveRecord\Config::initialise(function($cfg) {
//setting up a model (which is the representation of a table)
$cfg->set_model_directory('models');
$cfg->set_connections(array(
'development' => 'mysql://root:tutsplus#localhost/blog'
));
});
$posts = Post::all();
print_r($posts);
?>
And here's where I declare Post
class Post extends ActiveRecord\Model{}
I really cannot find the reason this isn't working, I actually did this instead to see if manually creating a new Post instance would fix the initialisation problem but it didn't, it had exactly the same error:
$post_class = new Post;
$posts = $post_class->all();
print_r($posts);
I'm really stumped on this one, I've usually managed to find something that fixes my problem on here but this is just nope. There is literally no difference to the tutorial code that I can see and I've checked it loads of times. Any help would be greatly appreciated.
(edit: the duplicate php-activerecord folders at the top isn't a code problem, the folder is actually duplicated and I haven't got round to moving the contents yet)
Point one: When using Composer, you are supposed to only include "vendor/autoload.php", and nothing else. Composer does the rest of autoloading for you.
Point two: It is called initialize with a Z, not S. You might simply have misspelled that method name.

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.

Is this Codeigniter code correct?

I've just started looking at PHP Frameworks after spending loads of wasted time doing everything from scratch. I thought I would give Codeigniter a go after a friend recommended it to me.
I worked through the first tutorial and there were no issues but I'm getting stuck with the second one.
At first my code was identical to the tutorial:
<?php
class Blog extends CI_Controller{
function Blog()
{
parent::CI_Controller();
$this->load->scaffolding('entries');
}
public function index(){
$data['title'] = "My Blog Title";
$data['heading'] = "An intresting title";
$data['todo'] = array('create media player','design site','finish project');
$this->load->view('blog_view',$data);
}
}
?>
But I got an internal server error. After looking at the user guide it shows a different way for using the constructor.
I changed the code to the document spec.
<?php
class Blog extends CI_Controller{
public function __construct() {
parent::__construct();
$this->load->scaffolding('entries');
}
public function index(){
$data['title'] = "My Blog Title";
$data['heading'] = "An intresting title";
$data['todo'] = array('create media player','design site','finish project');
$this->load->view('blog_view',$data);
}
}
?>
But I still get an internal error. I don't know if my code is wrong or I misconfigured something else. Some advice would be good, thanks.
Edit:
To clarify - I only get an internal error when I add the constructor to the class.
This will most likely because you're trying to load scaffolding in the latest version of CodeIgniter.
Scaffolding has been depreciated since version 1.6. It was removed in 2.0, and the latest version is now 2.0.2
In terms of which of your provided snippets to use, the latter form of declaring a constructor (__construct) is preferred over using the Class name (Blog). This method is also consistent with the Core Classes of CodeIgniter since 2.0.
As an aside, I've got no idea why CodeIgniter are including such out-of-date samples in their tutorials. EllisLab's seem to have lost total interest in the CI project recently, which is a shame :(
Internal error means there's mis-server configuration.
Usually .htaccess file or apache settings. Try this:
Enable rewrite module in apache.
Make sure .htaccess file is configured correctly. It should look like this: https://gist.github.com/ce2914e79193896590bc
This also removes index.php, which you should look into.

Categories